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 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;
50 static nsINetUtil *net_util;
52 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
55 const nsIWineURIVtbl *lpWineURIVtbl;
61 NSContainer *container;
62 windowref_t *window_ref;
68 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
69 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
71 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsIWineURI**);
73 static const char *debugstr_nsacstr(const nsACString *nsstr)
77 nsACString_GetData(nsstr, &data);
78 return debugstr_a(data);
81 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
83 const WCHAR *ptr = nsuri;
85 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
87 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
88 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
90 if(*ptr || ret_empty) {
91 *ret = SysAllocString(ptr);
98 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
102 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
104 IOleCommandTarget *cmdtrg = NULL;
107 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
108 if(SUCCEEDED(hres)) {
109 VARIANT varUrl, varRes;
111 V_VT(&varUrl) = VT_BSTR;
112 V_BSTR(&varUrl) = SysAllocString(url);
113 V_VT(&varRes) = VT_BOOL;
115 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
117 IOleCommandTarget_Release(cmdtrg);
118 SysFreeString(V_BSTR(&varUrl));
120 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
121 TRACE("got VARIANT_FALSE, do not load\n");
129 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
131 HTMLDocumentObj *doc = container->doc;
136 nsIWineURI_GetWineURL(channel->uri, &uri);
138 ERR("GetWineURL returned NULL\n");
143 NSContainer *container_iter = container;
145 hlnf = HLNF_OPENINNEWWINDOW;
146 while(!container_iter->doc)
147 container_iter = container_iter->parent;
148 doc = container_iter->doc;
154 if(!hlnf && !exec_shldocvw_67(doc, uri))
157 hres = hlink_frame_navigate(&doc->basedoc, uri, channel->post_data_stream, hlnf);
161 static inline BOOL is_http_channel(nsChannel *This)
163 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTP;
166 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
168 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
170 nsChannel *This = NSCHANNEL_THIS(iface);
172 if(IsEqualGUID(&IID_nsISupports, riid)) {
173 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
174 *result = NSCHANNEL(This);
175 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
176 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
177 *result = NSCHANNEL(This);
178 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
179 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
180 *result = NSCHANNEL(This);
181 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
182 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
183 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
184 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
185 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
186 *result = NSUPCHANNEL(This);
187 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
188 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
189 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
191 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
196 nsIChannel_AddRef(NSCHANNEL(This));
200 return NS_NOINTERFACE;
203 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
205 nsChannel *This = NSCHANNEL_THIS(iface);
206 nsrefcnt ref = InterlockedIncrement(&This->ref);
208 TRACE("(%p) ref=%d\n", This, ref);
213 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
215 nsChannel *This = NSCHANNEL_THIS(iface);
216 LONG ref = InterlockedDecrement(&This->ref);
219 nsIWineURI_Release(This->uri);
221 nsIChannel_Release(This->channel);
223 nsISupports_Release(This->owner);
224 if(This->post_data_stream)
225 nsIInputStream_Release(This->post_data_stream);
227 nsILoadGroup_Release(This->load_group);
228 if(This->notif_callback)
229 nsIInterfaceRequestor_Release(This->notif_callback);
230 if(This->original_uri)
231 nsIURI_Release(This->original_uri);
232 heap_free(This->content_type);
233 heap_free(This->charset);
240 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
242 nsChannel *This = NSCHANNEL_THIS(iface);
244 TRACE("(%p)->(%p)\n", This, aName);
247 return nsIChannel_GetName(This->channel, aName);
249 return NS_ERROR_NOT_IMPLEMENTED;
252 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
254 nsChannel *This = NSCHANNEL_THIS(iface);
256 TRACE("(%p)->(%p)\n", This, _retval);
259 return nsIChannel_IsPending(This->channel, _retval);
261 FIXME("default action not implemented\n");
262 return NS_ERROR_NOT_IMPLEMENTED;
265 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
267 nsChannel *This = NSCHANNEL_THIS(iface);
269 TRACE("(%p)->(%p)\n", This, aStatus);
272 return nsIChannel_GetStatus(This->channel, aStatus);
274 TRACE("returning NS_OK\n");
275 return *aStatus = NS_OK;
278 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
280 nsChannel *This = NSCHANNEL_THIS(iface);
282 TRACE("(%p)->(%08x)\n", This, aStatus);
285 return nsIChannel_Cancel(This->channel, aStatus);
287 FIXME("default action not implemented\n");
288 return NS_ERROR_NOT_IMPLEMENTED;
291 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
293 nsChannel *This = NSCHANNEL_THIS(iface);
295 TRACE("(%p)\n", This);
298 return nsIChannel_Suspend(This->channel);
300 FIXME("default action not implemented\n");
301 return NS_ERROR_NOT_IMPLEMENTED;
304 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
306 nsChannel *This = NSCHANNEL_THIS(iface);
308 TRACE("(%p)\n", This);
311 return nsIChannel_Resume(This->channel);
313 FIXME("default action not implemented\n");
314 return NS_ERROR_NOT_IMPLEMENTED;
317 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
319 nsChannel *This = NSCHANNEL_THIS(iface);
321 TRACE("(%p)->(%p)\n", This, aLoadGroup);
324 nsILoadGroup_AddRef(This->load_group);
326 *aLoadGroup = This->load_group;
330 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
332 nsChannel *This = NSCHANNEL_THIS(iface);
334 TRACE("(%p)->(%p)\n", This, aLoadGroup);
337 nsILoadGroup_Release(This->load_group);
339 nsILoadGroup_AddRef(aLoadGroup);
341 This->load_group = aLoadGroup;
344 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
348 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
350 nsChannel *This = NSCHANNEL_THIS(iface);
352 TRACE("(%p)->(%p)\n", This, aLoadFlags);
354 *aLoadFlags = This->load_flags;
358 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
360 nsChannel *This = NSCHANNEL_THIS(iface);
362 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
364 This->load_flags = aLoadFlags;
367 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
371 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
373 nsChannel *This = NSCHANNEL_THIS(iface);
375 TRACE("(%p)->(%p)\n", This, aOriginalURI);
377 if(This->original_uri)
378 nsIURI_AddRef(This->original_uri);
380 *aOriginalURI = This->original_uri;
384 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
386 nsChannel *This = NSCHANNEL_THIS(iface);
388 TRACE("(%p)->(%p)\n", This, aOriginalURI);
390 if(This->original_uri)
391 nsIURI_Release(This->original_uri);
393 nsIURI_AddRef(aOriginalURI);
394 This->original_uri = aOriginalURI;
397 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
401 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
403 nsChannel *This = NSCHANNEL_THIS(iface);
405 TRACE("(%p)->(%p)\n", This, aURI);
407 nsIWineURI_AddRef(This->uri);
408 *aURI = (nsIURI*)This->uri;
413 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
415 nsChannel *This = NSCHANNEL_THIS(iface);
417 TRACE("(%p)->(%p)\n", This, aOwner);
420 return nsIChannel_GetOwner(This->channel, aOwner);
423 nsISupports_AddRef(This->owner);
424 *aOwner = This->owner;
429 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
431 nsChannel *This = NSCHANNEL_THIS(iface);
433 TRACE("(%p)->(%p)\n", This, aOwner);
436 return nsIChannel_SetOwner(This->channel, aOwner);
439 nsISupports_AddRef(aOwner);
441 nsISupports_Release(This->owner);
442 This->owner = aOwner;
447 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
448 nsIInterfaceRequestor **aNotificationCallbacks)
450 nsChannel *This = NSCHANNEL_THIS(iface);
452 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
454 if(This->notif_callback)
455 nsIInterfaceRequestor_AddRef(This->notif_callback);
456 *aNotificationCallbacks = This->notif_callback;
461 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
462 nsIInterfaceRequestor *aNotificationCallbacks)
464 nsChannel *This = NSCHANNEL_THIS(iface);
466 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
468 if(This->notif_callback)
469 nsIInterfaceRequestor_Release(This->notif_callback);
470 if(aNotificationCallbacks)
471 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
473 This->notif_callback = aNotificationCallbacks;
476 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
480 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
482 nsChannel *This = NSCHANNEL_THIS(iface);
484 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
487 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
489 FIXME("default action not implemented\n");
490 return NS_ERROR_NOT_IMPLEMENTED;
493 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
495 nsChannel *This = NSCHANNEL_THIS(iface);
497 TRACE("(%p)->(%p)\n", This, aContentType);
499 if(This->content_type) {
500 nsACString_SetData(aContentType, This->content_type);
505 return nsIChannel_GetContentType(This->channel, aContentType);
507 WARN("unknown type\n");
508 return NS_ERROR_FAILURE;
511 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
512 const nsACString *aContentType)
514 nsChannel *This = NSCHANNEL_THIS(iface);
515 const char *content_type;
517 TRACE("(%p)->(%p)\n", This, aContentType);
519 nsACString_GetData(aContentType, &content_type);
521 TRACE("content_type %s\n", content_type);
523 heap_free(This->content_type);
524 This->content_type = heap_strdupA(content_type);
527 return nsIChannel_SetContentType(This->channel, aContentType);
532 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
533 nsACString *aContentCharset)
535 nsChannel *This = NSCHANNEL_THIS(iface);
537 TRACE("(%p)->(%p)\n", This, aContentCharset);
540 nsACString_SetData(aContentCharset, This->charset);
545 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
547 nsACString_GetData(aContentCharset, &ch);
551 nsACString_SetData(aContentCharset, "");
555 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
556 const nsACString *aContentCharset)
558 nsChannel *This = NSCHANNEL_THIS(iface);
560 TRACE("(%p)->(%p)\n", This, aContentCharset);
563 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
565 FIXME("default action not implemented\n");
566 return NS_ERROR_NOT_IMPLEMENTED;
569 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
571 nsChannel *This = NSCHANNEL_THIS(iface);
573 TRACE("(%p)->(%p)\n", This, aContentLength);
576 return nsIChannel_GetContentLength(This->channel, aContentLength);
578 FIXME("default action not implemented\n");
579 return NS_ERROR_NOT_IMPLEMENTED;
582 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
584 nsChannel *This = NSCHANNEL_THIS(iface);
586 TRACE("(%p)->(%d)\n", This, aContentLength);
589 return nsIChannel_SetContentLength(This->channel, aContentLength);
591 FIXME("default action not implemented\n");
592 return NS_ERROR_NOT_IMPLEMENTED;
595 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
597 nsChannel *This = NSCHANNEL_THIS(iface);
599 TRACE("(%p)->(%p)\n", This, _retval);
602 return nsIChannel_Open(This->channel, _retval);
604 FIXME("default action not implemented\n");
605 return NS_ERROR_NOT_IMPLEMENTED;
608 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
610 nsIWineURI *wine_uri;
615 if(!channel->original_uri) {
616 ERR("original_uri == NULL\n");
620 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
621 if(NS_FAILED(nsres)) {
622 ERR("Could not get nsIWineURI: %08x\n", nsres);
626 nsIWineURI_GetWineURL(wine_uri, &wine_url);
627 nsIWineURI_Release(wine_uri);
629 TRACE("wine_url == NULL\n");
633 hres = CreateURLMoniker(NULL, wine_url, mon);
635 WARN("CreateURLMoniker failed: %08x\n", hres);
640 static HTMLWindow *get_window_from_load_group(nsChannel *This)
645 nsIWineURI *wine_uri;
649 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
650 if(NS_FAILED(nsres)) {
651 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
658 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
659 nsIRequest_Release(req);
660 if(NS_FAILED(nsres)) {
661 WARN("Could not get nsIChannel interface: %08x\n", nsres);
665 nsres = nsIChannel_GetURI(channel, &uri);
666 nsIChannel_Release(channel);
667 if(NS_FAILED(nsres)) {
668 ERR("GetURI failed: %08x\n", nsres);
672 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
674 if(NS_FAILED(nsres)) {
675 TRACE("Could not get nsIWineURI: %08x\n", nsres);
679 nsIWineURI_GetWindow(wine_uri, &window);
680 nsIWineURI_Release(wine_uri);
685 static HTMLWindow *get_channel_window(nsChannel *This)
687 nsIRequestObserver *req_observer;
688 nsIWebProgress *web_progress;
689 nsIDOMWindow *nswindow;
693 if(!This->load_group) {
694 ERR("NULL load_group\n");
698 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
699 if(NS_FAILED(nsres) || !req_observer) {
700 ERR("GetGroupObserver failed: %08x\n", nsres);
704 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
705 nsIRequestObserver_Release(req_observer);
706 if(NS_FAILED(nsres)) {
707 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
711 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
712 nsIWebProgress_Release(web_progress);
713 if(NS_FAILED(nsres) || !nswindow) {
714 ERR("GetDOMWindow failed: %08x\n", nsres);
718 window = nswindow_to_window(nswindow);
719 nsIDOMWindow_Release(nswindow);
722 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
724 FIXME("NULL window for %p\n", nswindow);
730 HTMLDocumentNode *doc;
731 nsChannelBSC *bscallback;
732 } start_binding_task_t;
734 static void start_binding_proc(task_t *_task)
736 start_binding_task_t *task = (start_binding_task_t*)_task;
738 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
744 nsChannelBSC *bscallback;
745 } start_doc_binding_task_t;
747 static void start_doc_binding_proc(task_t *_task)
749 start_doc_binding_task_t *task = (start_doc_binding_task_t*)_task;
751 start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
752 IUnknown_Release((IUnknown*)task->bscallback);
755 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
756 nsISupports *context)
758 nsChannelBSC *bscallback;
759 IMoniker *mon = NULL;
762 hres = create_mon_for_nschannel(This, &mon);
764 return NS_ERROR_UNEXPECTED;
767 set_current_mon(window, mon);
769 bscallback = create_channelbsc(mon);
770 IMoniker_Release(mon);
772 channelbsc_set_channel(bscallback, This, listener, context);
775 start_doc_binding_task_t *task;
777 set_window_bscallback(window, bscallback);
779 task = heap_alloc(sizeof(start_doc_binding_task_t));
780 task->window = window;
781 task->bscallback = bscallback;
782 push_task(&task->header, start_doc_binding_proc, window->task_magic);
784 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
786 task->doc = window->doc;
787 task->bscallback = bscallback;
788 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
794 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
795 nsISupports *aContext)
797 nsChannel *This = NSCHANNEL_THIS(iface);
798 HTMLWindow *window = NULL;
801 nsresult nsres = NS_OK;
803 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
805 if(TRACE_ON(mshtml)) {
808 nsIWineURI_GetWineURL(This->uri, &url);
809 TRACE("opening %s\n", debugstr_w(url));
812 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
814 window = get_channel_window(This);
816 nsIWineURI_SetWindow(This->uri, window);
818 NSContainer *nscontainer;
820 nsIWineURI_GetNSContainer(This->uri, &nscontainer);
824 /* nscontainer->doc should be NULL which means navigation to a new window */
826 FIXME("nscontainer->doc = %p\n", nscontainer->doc);
828 b = before_async_open(This, nscontainer);
829 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
831 FIXME("Navigation not cancelled\n");
832 return NS_ERROR_UNEXPECTED;
838 nsIWineURI_GetWindow(This->uri, &window);
840 if(!window && This->load_group) {
841 window = get_window_from_load_group(This);
843 nsIWineURI_SetWindow(This->uri, window);
848 ERR("window = NULL\n");
850 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
851 : NS_ERROR_UNEXPECTED;
854 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI) && window == window->doc_obj->basedoc.window) {
855 if(window->doc_obj->nscontainer->bscallback) {
856 NSContainer *nscontainer = window->doc_obj->nscontainer;
858 channelbsc_set_channel(nscontainer->bscallback, This, aListener, aContext);
860 if(nscontainer->doc->mime) {
861 heap_free(This->content_type);
862 This->content_type = heap_strdupWtoA(nscontainer->doc->mime);
867 open = before_async_open(This, window->doc_obj->nscontainer);
870 nsres = NS_ERROR_UNEXPECTED;
876 nsres = async_open(This, window, is_doc_uri, aListener, aContext);
879 IHTMLWindow2_Release(HTMLWINDOW2(window));
883 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
885 nsChannel *This = NSCHANNEL_THIS(iface);
887 FIXME("(%p)->(%p)\n", This, aRequestMethod);
889 return NS_ERROR_NOT_IMPLEMENTED;
892 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
893 const nsACString *aRequestMethod)
895 nsChannel *This = NSCHANNEL_THIS(iface);
897 FIXME("(%p)->(%p)\n", This, aRequestMethod);
899 return NS_ERROR_NOT_IMPLEMENTED;
902 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
904 nsChannel *This = NSCHANNEL_THIS(iface);
906 FIXME("(%p)->(%p)\n", This, aReferrer);
908 return NS_ERROR_NOT_IMPLEMENTED;
911 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
913 nsChannel *This = NSCHANNEL_THIS(iface);
915 FIXME("(%p)->(%p)\n", This, aReferrer);
917 return NS_ERROR_NOT_IMPLEMENTED;
920 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
921 const nsACString *aHeader, nsACString *_retval)
923 nsChannel *This = NSCHANNEL_THIS(iface);
925 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
927 return NS_ERROR_NOT_IMPLEMENTED;
930 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
931 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
933 nsChannel *This = NSCHANNEL_THIS(iface);
935 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
937 return NS_ERROR_NOT_IMPLEMENTED;
940 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
941 nsIHttpHeaderVisitor *aVisitor)
943 nsChannel *This = NSCHANNEL_THIS(iface);
945 FIXME("(%p)->(%p)\n", This, aVisitor);
947 return NS_ERROR_NOT_IMPLEMENTED;
950 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
952 nsChannel *This = NSCHANNEL_THIS(iface);
954 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
956 return NS_ERROR_NOT_IMPLEMENTED;
959 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
961 nsChannel *This = NSCHANNEL_THIS(iface);
963 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
965 return NS_ERROR_NOT_IMPLEMENTED;
968 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
970 nsChannel *This = NSCHANNEL_THIS(iface);
972 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
974 return NS_ERROR_NOT_IMPLEMENTED;
977 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
979 nsChannel *This = NSCHANNEL_THIS(iface);
981 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
983 return NS_ERROR_NOT_IMPLEMENTED;
986 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
988 nsChannel *This = NSCHANNEL_THIS(iface);
990 TRACE("(%p)->(%p)\n", This, aResponseStatus);
992 if(This->response_status) {
993 *aResponseStatus = This->response_status;
997 WARN("No response status\n");
998 return NS_ERROR_UNEXPECTED;
1001 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1002 nsACString *aResponseStatusText)
1004 nsChannel *This = NSCHANNEL_THIS(iface);
1006 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1008 return NS_ERROR_NOT_IMPLEMENTED;
1011 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1012 PRBool *aRequestSucceeded)
1014 nsChannel *This = NSCHANNEL_THIS(iface);
1016 FIXME("(%p)->(%p)\n", This, aRequestSucceeded);
1018 return NS_ERROR_NOT_IMPLEMENTED;
1021 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1022 const nsACString *header, nsACString *_retval)
1024 nsChannel *This = NSCHANNEL_THIS(iface);
1026 FIXME("(%p)->(%p %p)\n", This, header, _retval);
1028 return NS_ERROR_NOT_IMPLEMENTED;
1031 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1032 const nsACString *header, const nsACString *value, PRBool merge)
1034 nsChannel *This = NSCHANNEL_THIS(iface);
1036 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
1038 return NS_ERROR_NOT_IMPLEMENTED;
1041 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1042 nsIHttpHeaderVisitor *aVisitor)
1044 nsChannel *This = NSCHANNEL_THIS(iface);
1046 FIXME("(%p)->(%p)\n", This, aVisitor);
1048 return NS_ERROR_NOT_IMPLEMENTED;
1051 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1053 nsChannel *This = NSCHANNEL_THIS(iface);
1055 FIXME("(%p)->(%p)\n", This, _retval);
1057 return NS_ERROR_NOT_IMPLEMENTED;
1060 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1062 nsChannel *This = NSCHANNEL_THIS(iface);
1064 FIXME("(%p)->(%p)\n", This, _retval);
1066 return NS_ERROR_NOT_IMPLEMENTED;
1069 #undef NSCHANNEL_THIS
1071 static const nsIHttpChannelVtbl nsChannelVtbl = {
1072 nsChannel_QueryInterface,
1076 nsChannel_IsPending,
1077 nsChannel_GetStatus,
1081 nsChannel_GetLoadGroup,
1082 nsChannel_SetLoadGroup,
1083 nsChannel_GetLoadFlags,
1084 nsChannel_SetLoadFlags,
1085 nsChannel_GetOriginalURI,
1086 nsChannel_SetOriginalURI,
1090 nsChannel_GetNotificationCallbacks,
1091 nsChannel_SetNotificationCallbacks,
1092 nsChannel_GetSecurityInfo,
1093 nsChannel_GetContentType,
1094 nsChannel_SetContentType,
1095 nsChannel_GetContentCharset,
1096 nsChannel_SetContentCharset,
1097 nsChannel_GetContentLength,
1098 nsChannel_SetContentLength,
1100 nsChannel_AsyncOpen,
1101 nsChannel_GetRequestMethod,
1102 nsChannel_SetRequestMethod,
1103 nsChannel_GetReferrer,
1104 nsChannel_SetReferrer,
1105 nsChannel_GetRequestHeader,
1106 nsChannel_SetRequestHeader,
1107 nsChannel_VisitRequestHeaders,
1108 nsChannel_GetAllowPipelining,
1109 nsChannel_SetAllowPipelining,
1110 nsChannel_GetRedirectionLimit,
1111 nsChannel_SetRedirectionLimit,
1112 nsChannel_GetResponseStatus,
1113 nsChannel_GetResponseStatusText,
1114 nsChannel_GetRequestSucceeded,
1115 nsChannel_GetResponseHeader,
1116 nsChannel_SetResponseHeader,
1117 nsChannel_VisitResponseHeaders,
1118 nsChannel_IsNoStoreResponse,
1119 nsChannel_IsNoCacheResponse
1122 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1124 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1127 nsChannel *This = NSUPCHANNEL_THIS(iface);
1128 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1131 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1133 nsChannel *This = NSUPCHANNEL_THIS(iface);
1134 return nsIChannel_AddRef(NSCHANNEL(This));
1137 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1139 nsChannel *This = NSUPCHANNEL_THIS(iface);
1140 return nsIChannel_Release(NSCHANNEL(This));
1143 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1144 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1146 nsChannel *This = NSUPCHANNEL_THIS(iface);
1147 const char *content_type;
1150 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1152 if(This->post_data_stream)
1153 nsIInputStream_Release(This->post_data_stream);
1156 nsACString_GetData(aContentType, &content_type);
1158 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1161 if(aContentLength != -1)
1162 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1164 if(This->post_data_stream)
1165 nsIInputStream_Release(This->post_data_stream);
1166 This->post_data_stream = aStream;
1168 nsIInputStream_AddRef(aStream);
1170 if(This->post_data_stream) {
1171 nsIUploadChannel *upload_channel;
1173 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
1174 (void**)&upload_channel);
1175 if(NS_SUCCEEDED(nsres)) {
1176 nsres = nsIUploadChannel_SetUploadStream(upload_channel, aStream, aContentType, aContentLength);
1177 nsIUploadChannel_Release(upload_channel);
1178 if(NS_FAILED(nsres))
1179 WARN("SetUploadStream failed: %08x\n", nsres);
1187 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1188 nsIInputStream **aUploadStream)
1190 nsChannel *This = NSUPCHANNEL_THIS(iface);
1192 TRACE("(%p)->(%p)\n", This, aUploadStream);
1194 if(This->post_data_stream)
1195 nsIInputStream_AddRef(This->post_data_stream);
1197 *aUploadStream = This->post_data_stream;
1201 #undef NSUPCHANNEL_THIS
1203 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1204 nsUploadChannel_QueryInterface,
1205 nsUploadChannel_AddRef,
1206 nsUploadChannel_Release,
1207 nsUploadChannel_SetUploadStream,
1208 nsUploadChannel_GetUploadStream
1211 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1213 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1216 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1217 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1220 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1222 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1223 return nsIChannel_AddRef(NSCHANNEL(This));
1226 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1228 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1229 return nsIChannel_Release(NSCHANNEL(This));
1232 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1234 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1236 FIXME("(%p)->()\n", This);
1238 return NS_ERROR_NOT_IMPLEMENTED;
1241 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1243 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1245 FIXME("(%p)->()\n", This);
1247 return NS_ERROR_NOT_IMPLEMENTED;
1250 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1252 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1254 FIXME("(%p)->()\n", This);
1256 return NS_ERROR_NOT_IMPLEMENTED;
1259 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1261 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1263 FIXME("(%p)->()\n", This);
1265 return NS_ERROR_NOT_IMPLEMENTED;
1268 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1270 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1272 FIXME("(%p)->()\n", This);
1274 return NS_ERROR_NOT_IMPLEMENTED;
1277 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1279 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1281 FIXME("(%p)->()\n", This);
1283 return NS_ERROR_NOT_IMPLEMENTED;
1286 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1288 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1290 FIXME("(%p)->()\n", This);
1292 return NS_ERROR_NOT_IMPLEMENTED;
1295 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1297 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1299 FIXME("(%p)->()\n", This);
1301 return NS_ERROR_NOT_IMPLEMENTED;
1304 #undef NSHTTPINTERNAL_THIS
1306 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1307 nsHttpChannelInternal_QueryInterface,
1308 nsHttpChannelInternal_AddRef,
1309 nsHttpChannelInternal_Release,
1310 nsHttpChannelInternal_GetDocumentURI,
1311 nsHttpChannelInternal_SetDocumentURI,
1312 nsHttpChannelInternal_GetRequestVersion,
1313 nsHttpChannelInternal_GetResponseVersion,
1314 nsHttpChannelInternal_SetCookie,
1315 nsHttpChannelInternal_SetupFallbackChannel,
1316 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1317 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1320 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1322 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1324 nsURI *This = NSURI_THIS(iface);
1328 if(IsEqualGUID(&IID_nsISupports, riid)) {
1329 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1330 *result = NSURI(This);
1331 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1332 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1333 *result = NSURI(This);
1334 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1335 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1336 *result = NSURI(This);
1337 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1338 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1339 *result = NSURI(This);
1343 nsIURI_AddRef(NSURI(This));
1347 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1348 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1351 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1353 nsURI *This = NSURI_THIS(iface);
1354 LONG ref = InterlockedIncrement(&This->ref);
1356 TRACE("(%p) ref=%d\n", This, ref);
1361 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1363 nsURI *This = NSURI_THIS(iface);
1364 LONG ref = InterlockedDecrement(&This->ref);
1366 TRACE("(%p) ref=%d\n", This, ref);
1369 if(This->window_ref)
1370 windowref_release(This->window_ref);
1372 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1374 nsIURL_Release(This->nsurl);
1376 nsIURI_Release(This->uri);
1377 heap_free(This->wine_url);
1384 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1386 nsURI *This = NSURI_THIS(iface);
1388 TRACE("(%p)->(%p)\n", This, aSpec);
1390 if(This->use_wine_url) {
1391 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1392 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1393 nsACString_SetData(aSpec, speca);
1399 return nsIURI_GetSpec(This->uri, aSpec);
1401 TRACE("returning error\n");
1402 return NS_ERROR_NOT_IMPLEMENTED;
1406 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1408 nsURI *This = NSURI_THIS(iface);
1410 TRACE("(%p)->(%p)\n", This, aSpec);
1413 return nsIURI_SetSpec(This->uri, aSpec);
1415 FIXME("default action not implemented\n");
1416 return NS_ERROR_NOT_IMPLEMENTED;
1419 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1421 nsURI *This = NSURI_THIS(iface);
1423 TRACE("(%p)->(%p)\n", This, aPrePath);
1426 return nsIURI_GetPrePath(This->uri, aPrePath);
1428 FIXME("default action not implemented\n");
1429 return NS_ERROR_NOT_IMPLEMENTED;
1432 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1434 nsURI *This = NSURI_THIS(iface);
1436 TRACE("(%p)->(%p)\n", This, aScheme);
1438 if(This->use_wine_url) {
1440 * For Gecko we set scheme to unknown so it won't be handled
1441 * as any special case.
1443 nsACString_SetData(aScheme, "wine");
1448 return nsIURI_GetScheme(This->uri, aScheme);
1450 TRACE("returning error\n");
1451 return NS_ERROR_NOT_IMPLEMENTED;
1454 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1456 nsURI *This = NSURI_THIS(iface);
1458 TRACE("(%p)->(%p)\n", This, aScheme);
1461 return nsIURI_SetScheme(This->uri, aScheme);
1463 FIXME("default action not implemented\n");
1464 return NS_ERROR_NOT_IMPLEMENTED;
1467 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1469 nsURI *This = NSURI_THIS(iface);
1471 TRACE("(%p)->(%p)\n", This, aUserPass);
1474 return nsIURI_GetUserPass(This->uri, aUserPass);
1476 FIXME("default action not implemented\n");
1477 return NS_ERROR_NOT_IMPLEMENTED;
1480 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1482 nsURI *This = NSURI_THIS(iface);
1484 TRACE("(%p)->(%p)\n", This, aUserPass);
1487 return nsIURI_SetUserPass(This->uri, aUserPass);
1489 FIXME("default action not implemented\n");
1490 return NS_ERROR_NOT_IMPLEMENTED;
1493 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1495 nsURI *This = NSURI_THIS(iface);
1497 TRACE("(%p)->(%p)\n", This, aUsername);
1500 return nsIURI_GetUsername(This->uri, aUsername);
1502 FIXME("default action not implemented\n");
1503 return NS_ERROR_NOT_IMPLEMENTED;
1506 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1508 nsURI *This = NSURI_THIS(iface);
1510 TRACE("(%p)->(%p)\n", This, aUsername);
1513 return nsIURI_SetUsername(This->uri, aUsername);
1515 FIXME("default action not implemented\n");
1516 return NS_ERROR_NOT_IMPLEMENTED;
1519 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1521 nsURI *This = NSURI_THIS(iface);
1523 TRACE("(%p)->(%p)\n", This, aPassword);
1526 return nsIURI_GetPassword(This->uri, aPassword);
1528 FIXME("default action not implemented\n");
1529 return NS_ERROR_NOT_IMPLEMENTED;
1532 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1534 nsURI *This = NSURI_THIS(iface);
1536 TRACE("(%p)->(%p)\n", This, aPassword);
1539 return nsIURI_SetPassword(This->uri, aPassword);
1541 FIXME("default action not implemented\n");
1542 return NS_ERROR_NOT_IMPLEMENTED;
1545 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1547 nsURI *This = NSURI_THIS(iface);
1549 TRACE("(%p)->(%p)\n", This, aHostPort);
1552 return nsIURI_GetHostPort(This->uri, aHostPort);
1554 FIXME("default action not implemented\n");
1555 return NS_ERROR_NOT_IMPLEMENTED;
1558 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1560 nsURI *This = NSURI_THIS(iface);
1562 TRACE("(%p)->(%p)\n", This, aHostPort);
1565 return nsIURI_SetHostPort(This->uri, aHostPort);
1567 FIXME("default action not implemented\n");
1568 return NS_ERROR_NOT_IMPLEMENTED;
1571 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1573 nsURI *This = NSURI_THIS(iface);
1575 TRACE("(%p)->(%p)\n", This, aHost);
1578 return nsIURI_GetHost(This->uri, aHost);
1580 FIXME("default action not implemented\n");
1581 return NS_ERROR_NOT_IMPLEMENTED;
1584 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1586 nsURI *This = NSURI_THIS(iface);
1588 TRACE("(%p)->(%p)\n", This, aHost);
1591 return nsIURI_SetHost(This->uri, aHost);
1593 FIXME("default action not implemented\n");
1594 return NS_ERROR_NOT_IMPLEMENTED;
1597 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1599 nsURI *This = NSURI_THIS(iface);
1601 TRACE("(%p)->(%p)\n", This, aPort);
1604 return nsIURI_GetPort(This->uri, aPort);
1606 FIXME("default action not implemented\n");
1607 return NS_ERROR_NOT_IMPLEMENTED;
1610 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1612 nsURI *This = NSURI_THIS(iface);
1614 TRACE("(%p)->(%d)\n", This, aPort);
1617 return nsIURI_SetPort(This->uri, aPort);
1619 FIXME("default action not implemented\n");
1620 return NS_ERROR_NOT_IMPLEMENTED;
1623 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1625 nsURI *This = NSURI_THIS(iface);
1627 TRACE("(%p)->(%p)\n", This, aPath);
1630 return nsIURI_GetPath(This->uri, aPath);
1632 FIXME("default action not implemented\n");
1633 return NS_ERROR_NOT_IMPLEMENTED;
1636 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1638 nsURI *This = NSURI_THIS(iface);
1641 nsACString_GetData(aPath, &path);
1642 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1645 if(This->wine_url) {
1646 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1647 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1651 pathw = heap_strdupAtoW(path);
1652 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1655 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1657 WARN("UrlCombine failed: %08x\n", hres);
1663 return nsIURI_SetPath(This->uri, aPath);
1666 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1668 nsURI *This = NSURI_THIS(iface);
1669 nsIWineURI *wine_uri;
1670 LPCWSTR other_url = NULL;
1673 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1676 return nsIURI_Equals(This->uri, other, _retval);
1678 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1679 if(NS_FAILED(nsres)) {
1680 TRACE("Could not get nsIWineURI interface\n");
1685 nsIWineURI_GetWineURL(wine_uri, &other_url);
1686 *_retval = other_url && !UrlCompareW(This->wine_url, other_url, TRUE);
1687 nsIWineURI_Release(wine_uri);
1692 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1694 nsURI *This = NSURI_THIS(iface);
1696 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1698 if(This->use_wine_url) {
1699 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1700 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1702 *_retval = lstrlenW(This->wine_url) > len
1703 && This->wine_url[len] == ':'
1704 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1709 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1711 TRACE("returning error\n");
1712 return NS_ERROR_NOT_IMPLEMENTED;
1715 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1717 nsURI *This = NSURI_THIS(iface);
1718 nsIURI *nsuri = NULL;
1719 nsIWineURI *wine_uri;
1722 TRACE("(%p)->(%p)\n", This, _retval);
1725 nsres = nsIURI_Clone(This->uri, &nsuri);
1726 if(NS_FAILED(nsres)) {
1727 WARN("Clone failed: %08x\n", nsres);
1732 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1733 if(NS_FAILED(nsres)) {
1734 WARN("create_uri failed: %08x\n", nsres);
1738 *_retval = (nsIURI*)wine_uri;
1739 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1742 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1743 nsACString *_retval)
1745 nsURI *This = NSURI_THIS(iface);
1747 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1750 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1752 FIXME("default action not implemented\n");
1753 return NS_ERROR_NOT_IMPLEMENTED;
1756 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1758 nsURI *This = NSURI_THIS(iface);
1760 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1762 if(This->use_wine_url)
1763 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1766 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1768 TRACE("returning error\n");
1769 return NS_ERROR_NOT_IMPLEMENTED;
1772 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1774 nsURI *This = NSURI_THIS(iface);
1776 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1779 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1781 FIXME("default action not implemented\n");
1782 return NS_ERROR_NOT_IMPLEMENTED;
1785 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1787 nsURI *This = NSURI_THIS(iface);
1789 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1792 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1794 FIXME("default action not implemented\n");
1795 return NS_ERROR_NOT_IMPLEMENTED;
1798 static nsresult NSAPI nsURL_GetFilePath(nsIWineURI *iface, nsACString *aFilePath)
1800 nsURI *This = NSURI_THIS(iface);
1802 TRACE("(%p)->(%p)\n", This, aFilePath);
1805 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1807 FIXME("default action not implemented\n");
1808 return NS_ERROR_NOT_IMPLEMENTED;
1811 static nsresult NSAPI nsURL_SetFilePath(nsIWineURI *iface, const nsACString *aFilePath)
1813 nsURI *This = NSURI_THIS(iface);
1815 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1818 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1820 FIXME("default action not implemented\n");
1821 return NS_ERROR_NOT_IMPLEMENTED;
1824 static nsresult NSAPI nsURL_GetParam(nsIWineURI *iface, nsACString *aParam)
1826 nsURI *This = NSURI_THIS(iface);
1828 TRACE("(%p)->(%p)\n", This, aParam);
1831 return nsIURL_GetParam(This->nsurl, aParam);
1833 FIXME("default action not implemented\n");
1834 return NS_ERROR_NOT_IMPLEMENTED;
1837 static nsresult NSAPI nsURL_SetParam(nsIWineURI *iface, const nsACString *aParam)
1839 nsURI *This = NSURI_THIS(iface);
1841 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1844 return nsIURL_SetParam(This->nsurl, aParam);
1846 FIXME("default action not implemented\n");
1847 return NS_ERROR_NOT_IMPLEMENTED;
1850 static nsresult NSAPI nsURL_GetQuery(nsIWineURI *iface, nsACString *aQuery)
1852 nsURI *This = NSURI_THIS(iface);
1854 TRACE("(%p)->(%p)\n", This, aQuery);
1857 return nsIURL_GetQuery(This->nsurl, aQuery);
1859 FIXME("default action not implemented\n");
1860 return NS_ERROR_NOT_IMPLEMENTED;
1863 static nsresult NSAPI nsURL_SetQuery(nsIWineURI *iface, const nsACString *aQuery)
1865 nsURI *This = NSURI_THIS(iface);
1866 const WCHAR *ptr1, *ptr2;
1868 WCHAR *new_url, *ptr;
1871 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1874 nsIURL_SetQuery(This->nsurl, aQuery);
1879 nsACString_GetData(aQuery, &query);
1880 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1881 ptr1 = strchrW(This->wine_url, '?');
1883 size += ptr1-This->wine_url;
1884 ptr2 = strchrW(ptr1, '#');
1886 size += strlenW(ptr2);
1888 ptr1 = This->wine_url + strlenW(This->wine_url);
1890 size += strlenW(This->wine_url);
1896 new_url = heap_alloc(size*sizeof(WCHAR));
1897 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1898 ptr = new_url + (ptr1-This->wine_url);
1901 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1909 TRACE("setting %s\n", debugstr_w(new_url));
1911 heap_free(This->wine_url);
1912 This->wine_url = new_url;
1916 static nsresult NSAPI nsURL_GetRef(nsIWineURI *iface, nsACString *aRef)
1918 nsURI *This = NSURI_THIS(iface);
1920 TRACE("(%p)->(%p)\n", This, aRef);
1923 return nsIURL_GetRef(This->nsurl, aRef);
1925 FIXME("default action not implemented\n");
1926 return NS_ERROR_NOT_IMPLEMENTED;
1929 static nsresult NSAPI nsURL_SetRef(nsIWineURI *iface, const nsACString *aRef)
1931 nsURI *This = NSURI_THIS(iface);
1934 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1937 return nsIURL_SetRef(This->nsurl, aRef);
1939 nsACString_GetData(aRef, &refa);
1943 FIXME("default action not implemented\n");
1944 return NS_ERROR_NOT_IMPLEMENTED;
1947 static nsresult NSAPI nsURL_GetDirectory(nsIWineURI *iface, nsACString *aDirectory)
1949 nsURI *This = NSURI_THIS(iface);
1951 TRACE("(%p)->(%p)\n", This, aDirectory);
1954 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1956 FIXME("default action not implemented\n");
1957 return NS_ERROR_NOT_IMPLEMENTED;
1960 static nsresult NSAPI nsURL_SetDirectory(nsIWineURI *iface, const nsACString *aDirectory)
1962 nsURI *This = NSURI_THIS(iface);
1964 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
1967 return nsIURL_SetDirectory(This->nsurl, aDirectory);
1969 FIXME("default action not implemented\n");
1970 return NS_ERROR_NOT_IMPLEMENTED;
1973 static nsresult NSAPI nsURL_GetFileName(nsIWineURI *iface, nsACString *aFileName)
1975 nsURI *This = NSURI_THIS(iface);
1977 TRACE("(%p)->(%p)\n", This, aFileName);
1980 return nsIURL_GetFileName(This->nsurl, aFileName);
1982 FIXME("default action not implemented\n");
1983 return NS_ERROR_NOT_IMPLEMENTED;
1986 static nsresult NSAPI nsURL_SetFileName(nsIWineURI *iface, const nsACString *aFileName)
1988 nsURI *This = NSURI_THIS(iface);
1990 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
1993 return nsIURL_SetFileName(This->nsurl, aFileName);
1995 FIXME("default action not implemented\n");
1996 return NS_ERROR_NOT_IMPLEMENTED;
1999 static nsresult NSAPI nsURL_GetFileBaseName(nsIWineURI *iface, nsACString *aFileBaseName)
2001 nsURI *This = NSURI_THIS(iface);
2003 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2006 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2008 FIXME("default action not implemented\n");
2009 return NS_ERROR_NOT_IMPLEMENTED;
2012 static nsresult NSAPI nsURL_SetFileBaseName(nsIWineURI *iface, const nsACString *aFileBaseName)
2014 nsURI *This = NSURI_THIS(iface);
2016 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2019 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2021 FIXME("default action not implemented\n");
2022 return NS_ERROR_NOT_IMPLEMENTED;
2025 static nsresult NSAPI nsURL_GetFileExtension(nsIWineURI *iface, nsACString *aFileExtension)
2027 nsURI *This = NSURI_THIS(iface);
2029 TRACE("(%p)->(%p)\n", This, aFileExtension);
2032 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2034 FIXME("default action not implemented\n");
2035 return NS_ERROR_NOT_IMPLEMENTED;
2038 static nsresult NSAPI nsURL_SetFileExtension(nsIWineURI *iface, const nsACString *aFileExtension)
2040 nsURI *This = NSURI_THIS(iface);
2042 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2045 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2047 FIXME("default action not implemented\n");
2048 return NS_ERROR_NOT_IMPLEMENTED;
2051 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
2053 nsURI *This = NSURI_THIS(iface);
2055 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2058 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2060 FIXME("default action not implemented\n");
2061 return NS_ERROR_NOT_IMPLEMENTED;
2064 static nsresult NSAPI nsURL_GetRelativeSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
2066 nsURI *This = NSURI_THIS(iface);
2068 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2071 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2073 FIXME("default action not implemented\n");
2074 return NS_ERROR_NOT_IMPLEMENTED;
2077 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
2079 nsURI *This = NSURI_THIS(iface);
2081 TRACE("(%p)->(%p)\n", This, aContainer);
2084 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
2085 *aContainer = This->container;
2090 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
2092 nsURI *This = NSURI_THIS(iface);
2094 TRACE("(%p)->(%p)\n", This, aContainer);
2096 if(This->container) {
2097 if(This->container == aContainer)
2099 TRACE("Changing %p -> %p\n", This->container, aContainer);
2100 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
2104 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
2105 This->container = aContainer;
2110 static nsresult NSAPI nsURI_GetWindow(nsIWineURI *iface, HTMLWindow **aHTMLWindow)
2112 nsURI *This = NSURI_THIS(iface);
2114 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2116 if(This->window_ref && This->window_ref->window) {
2117 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window_ref->window));
2118 *aHTMLWindow = This->window_ref->window;
2120 *aHTMLWindow = NULL;
2126 static nsresult NSAPI nsURI_SetWindow(nsIWineURI *iface, HTMLWindow *aHTMLWindow)
2128 nsURI *This = NSURI_THIS(iface);
2130 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2132 if(This->window_ref) {
2133 if(This->window_ref->window == aHTMLWindow)
2135 TRACE("Changing %p -> %p\n", This->window_ref->window, aHTMLWindow);
2136 windowref_release(This->window_ref);
2140 windowref_addref(aHTMLWindow->window_ref);
2141 This->window_ref = aHTMLWindow->window_ref;
2143 if(aHTMLWindow->doc_obj)
2144 nsIWineURI_SetNSContainer(NSWINEURI(This), aHTMLWindow->doc_obj->nscontainer);
2146 This->window_ref = NULL;
2152 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
2154 nsURI *This = NSURI_THIS(iface);
2156 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
2158 *aIsDocumentURI = This->is_doc_uri;
2162 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
2164 nsURI *This = NSURI_THIS(iface);
2166 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
2168 This->is_doc_uri = aIsDocumentURI;
2172 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
2174 nsURI *This = NSURI_THIS(iface);
2176 TRACE("(%p)->(%p)\n", This, aURL);
2178 *aURL = This->wine_url;
2182 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
2184 nsURI *This = NSURI_THIS(iface);
2186 static const WCHAR wszFtp[] = {'f','t','p',':'};
2187 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
2188 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
2190 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
2192 heap_free(This->wine_url);
2195 int len = strlenW(aURL)+1;
2196 This->wine_url = heap_alloc(len*sizeof(WCHAR));
2197 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
2200 /* FIXME: Always use wine url */
2201 This->use_wine_url =
2202 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
2203 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
2204 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
2206 This->use_wine_url = TRUE;
2209 This->wine_url = NULL;
2210 This->use_wine_url = FALSE;
2218 static const nsIWineURIVtbl nsWineURIVtbl = {
2219 nsURI_QueryInterface,
2247 nsURI_GetOriginCharset,
2260 nsURL_GetFileBaseName,
2261 nsURL_SetFileBaseName,
2262 nsURL_GetFileExtension,
2263 nsURL_SetFileExtension,
2264 nsURL_GetCommonBaseSpec,
2265 nsURL_GetRelativeSpec,
2266 nsURI_GetNSContainer,
2267 nsURI_SetNSContainer,
2270 nsURI_GetIsDocumentURI,
2271 nsURI_SetIsDocumentURI,
2276 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsIWineURI **_retval)
2278 nsURI *ret = heap_alloc_zero(sizeof(nsURI));
2280 ret->lpWineURIVtbl = &nsWineURIVtbl;
2284 nsIWineURI_SetNSContainer(NSWINEURI(ret), container);
2285 nsIWineURI_SetWindow(NSWINEURI(ret), window);
2288 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2292 TRACE("retval=%p\n", ret);
2293 *_retval = NSWINEURI(ret);
2297 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsIWineURI **ret)
2302 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2303 if(NS_FAILED(nsres))
2306 nsIWineURI_SetWineURL(uri, url);
2307 nsIWineURI_SetIsDocumentURI(uri, TRUE);
2314 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2318 nsIProtocolHandler *nshandler;
2319 } nsProtocolHandler;
2321 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2323 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2325 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2328 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2332 if(IsEqualGUID(&IID_nsISupports, riid)) {
2333 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2334 *result = NSPROTHANDLER(This);
2335 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2336 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2337 *result = NSPROTHANDLER(This);
2338 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2339 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2340 return NS_NOINTERFACE;
2344 nsISupports_AddRef((nsISupports*)*result);
2348 WARN("(%s %p)\n", debugstr_guid(riid), result);
2349 return NS_NOINTERFACE;
2352 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2354 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2355 LONG ref = InterlockedIncrement(&This->ref);
2357 TRACE("(%p) ref=%d\n", This, ref);
2362 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2364 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2365 LONG ref = InterlockedDecrement(&This->ref);
2367 TRACE("(%p) ref=%d\n", This, ref);
2371 nsIProtocolHandler_Release(This->nshandler);
2378 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2380 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2382 TRACE("(%p)->(%p)\n", This, aScheme);
2385 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2386 return NS_ERROR_NOT_IMPLEMENTED;
2389 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2390 PRInt32 *aDefaultPort)
2392 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2394 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2397 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2398 return NS_ERROR_NOT_IMPLEMENTED;
2401 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2402 PRUint32 *aProtocolFlags)
2404 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2406 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2409 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2410 return NS_ERROR_NOT_IMPLEMENTED;
2413 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2414 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2416 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2418 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2421 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2422 return NS_ERROR_NOT_IMPLEMENTED;
2425 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2426 nsIURI *aURI, nsIChannel **_retval)
2428 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2430 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2433 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2434 return NS_ERROR_NOT_IMPLEMENTED;
2437 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2438 PRInt32 port, const char *scheme, PRBool *_retval)
2440 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2442 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2445 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2446 return NS_ERROR_NOT_IMPLEMENTED;
2449 #undef NSPROTHANDLER_THIS
2451 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2452 nsProtocolHandler_QueryInterface,
2453 nsProtocolHandler_AddRef,
2454 nsProtocolHandler_Release,
2455 nsProtocolHandler_GetScheme,
2456 nsProtocolHandler_GetDefaultPort,
2457 nsProtocolHandler_GetProtocolFlags,
2458 nsProtocolHandler_NewURI,
2459 nsProtocolHandler_NewChannel,
2460 nsProtocolHandler_AllowPort
2463 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2465 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2467 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2469 ret->nshandler = nshandler;
2471 return NSPROTHANDLER(ret);
2474 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2476 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2481 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2486 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2487 nsIProtocolHandler **_retval)
2489 nsIExternalProtocolHandler *nsexthandler;
2490 nsIProtocolHandler *nshandler;
2493 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2495 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2496 if(NS_FAILED(nsres)) {
2497 WARN("GetProtocolHandler failed: %08x\n", nsres);
2501 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2502 (void**)&nsexthandler);
2503 if(NS_FAILED(nsres)) {
2504 *_retval = nshandler;
2508 nsIExternalProtocolHandler_Release(nsexthandler);
2509 *_retval = create_protocol_handler(nshandler);
2510 TRACE("return %p\n", *_retval);
2514 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2517 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2518 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2521 static BOOL is_gecko_special_uri(const char *spec)
2523 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2526 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2527 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2534 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2535 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2537 const char *spec = NULL;
2538 HTMLWindow *window = NULL;
2540 LPCWSTR base_wine_url = NULL;
2541 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2542 BOOL is_wine_uri = FALSE;
2545 nsACString_GetData(aSpec, &spec);
2547 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2550 if(is_gecko_special_uri(spec))
2551 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2553 if(!strncmp(spec, "wine:", 5)) {
2559 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2561 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2562 if(NS_SUCCEEDED(nsres)) {
2563 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2564 nsIWineURI_GetWindow(base_wine_uri, &window);
2565 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2566 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2567 TRACE("not wraping\n");
2568 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2570 WARN("Could not get base nsIWineURI: %08x\n", nsres);
2574 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2575 if(NS_FAILED(nsres))
2576 TRACE("NewURI failed: %08x\n", nsres);
2578 nsres = create_uri(uri, window, NULL, &wine_uri);
2579 *_retval = (nsIURI*)wine_uri;
2582 IHTMLWindow2_Release(HTMLWINDOW2(window));
2585 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2589 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2591 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2592 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2593 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2595 nsIWineURI_SetWineURL(wine_uri, url);
2597 WARN("CoCombineUrl failed: %08x\n", hres);
2598 }else if(is_wine_uri) {
2599 WCHAR url[INTERNET_MAX_URL_LENGTH];
2601 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2602 nsIWineURI_SetWineURL(wine_uri, url);
2606 nsIWineURI_Release(base_wine_uri);
2611 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2614 TRACE("(%p %p)\n", aFile, _retval);
2615 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2618 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2619 nsIChannel **_retval)
2621 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2622 nsIChannel *channel = NULL;
2624 nsIWineURI *wine_uri;
2628 TRACE("(%p %p)\n", aURI, _retval);
2630 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2631 if(NS_FAILED(nsres)) {
2632 TRACE("Could not get nsIWineURI: %08x\n", nsres);
2633 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2636 nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2638 ret = heap_alloc_zero(sizeof(nsChannel));
2640 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2641 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2642 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2644 ret->channel = channel;
2645 ret->uri = wine_uri;
2647 nsIURI_AddRef(aURI);
2648 ret->original_uri = aURI;
2650 nsIWineURI_GetWineURL(wine_uri, &url);
2651 ret->url_scheme = url && SUCCEEDED(ParseURLW(url, &parsed_url)) ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2653 *_retval = NSCHANNEL(ret);
2657 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2658 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2660 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2661 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2664 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2666 TRACE("(%p)\n", aOffline);
2667 return nsIIOService_GetOffline(nsio, aOffline);
2670 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2672 TRACE("(%x)\n", aOffline);
2673 return nsIIOService_SetOffline(nsio, aOffline);
2676 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2677 const char *aScheme, PRBool *_retval)
2679 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2680 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2683 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2684 nsACString * _retval)
2686 TRACE("(%p %p)\n", urlString, _retval);
2687 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2690 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2691 nsIOService_QueryInterface,
2693 nsIOService_Release,
2694 nsIOService_GetProtocolHandler,
2695 nsIOService_GetProtocolFlags,
2697 nsIOService_NewFileURI,
2698 nsIOService_NewChannelFromURI,
2699 nsIOService_NewChannel,
2700 nsIOService_GetOffline,
2701 nsIOService_SetOffline,
2702 nsIOService_AllowPort,
2703 nsIOService_ExtractScheme
2706 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2708 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2711 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2714 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2719 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2724 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2725 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2727 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2729 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2732 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2736 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2739 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2741 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2743 if(aFlags == (1<<11)) {
2748 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2751 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2753 TRACE("(%p %p)\n", aURI, _retval);
2755 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2758 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2759 PRUint32 aEscapeType, nsACString *_retval)
2761 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2763 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2766 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2767 nsACString *_retval)
2769 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2771 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2774 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2775 PRUint32 aFlags, nsACString *_retval)
2777 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2779 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2782 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2783 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2785 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2787 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2790 static const nsINetUtilVtbl nsNetUtilVtbl = {
2791 nsNetUtil_QueryInterface,
2794 nsNetUtil_ParseContentType,
2795 nsNetUtil_ProtocolHasFlags,
2796 nsNetUtil_URIChainHasFlags,
2797 nsNetUtil_ToImmutableURI,
2798 nsNetUtil_EscapeString,
2799 nsNetUtil_EscapeURL,
2800 nsNetUtil_UnescapeString,
2801 nsNetUtil_ExtractCharsetFromContentType
2804 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2806 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2811 if(IsEqualGUID(&IID_nsISupports, riid))
2812 *result = &nsIOService;
2813 else if(IsEqualGUID(&IID_nsIIOService, riid))
2814 *result = &nsIOService;
2815 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2816 *result = &nsNetUtil;
2819 nsISupports_AddRef((nsISupports*)*result);
2823 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2824 return NS_NOINTERFACE;
2827 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2832 if(IsEqualGUID(&IID_nsISupports, riid)) {
2833 TRACE("(IID_nsISupports %p)\n", result);
2835 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2836 TRACE("(IID_nsIFactory %p)\n", result);
2841 nsIFactory_AddRef(iface);
2845 WARN("(%s %p)\n", debugstr_guid(riid), result);
2846 return NS_NOINTERFACE;
2849 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2854 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2859 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2860 nsISupports *aOuter, const nsIID *iid, void **result)
2862 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2865 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2867 WARN("(%x)\n", lock);
2871 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2872 nsIOServiceFactory_QueryInterface,
2873 nsIOServiceFactory_AddRef,
2874 nsIOServiceFactory_Release,
2875 nsIOServiceFactory_CreateInstance,
2876 nsIOServiceFactory_LockFactory
2879 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2881 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2883 nsIFactory *old_factory = NULL;
2886 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2887 &IID_nsIFactory, (void**)&old_factory);
2888 if(NS_FAILED(nsres)) {
2889 ERR("Could not get factory: %08x\n", nsres);
2893 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2894 if(NS_FAILED(nsres)) {
2895 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2896 nsIFactory_Release(old_factory);
2900 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2901 if(NS_FAILED(nsres)) {
2902 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2903 nsIIOService_Release(nsio);
2907 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2908 nsIFactory_Release(old_factory);
2909 if(NS_FAILED(nsres))
2910 ERR("UnregisterFactory failed: %08x\n", nsres);
2912 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2913 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2914 if(NS_FAILED(nsres))
2915 ERR("RegisterFactory failed: %08x\n", nsres);
2918 void release_nsio(void)
2921 nsINetUtil_Release(net_util);
2926 nsIIOService_Release(nsio);