2 * Copyright 2006-2010 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
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 #define NS_IOSERVICE_CLASSNAME "nsIOService"
43 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
45 static const IID NS_IOSERVICE_CID =
46 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 static const IID IID_nsWineURI =
48 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
50 static nsIIOService *nsio = NULL;
51 static nsINetUtil *net_util;
53 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
56 nsIFileURL nsIFileURL_iface; /* For non-file URL objects, it's just nsIURL */
57 nsIStandardURL nsIStandardURL_iface;
61 NSContainer *container;
62 windowref_t *window_ref;
63 nsChannelBSC *channel_bsc;
65 IUriBuilder *uri_builder;
71 static BOOL ensure_uri(nsWineURI *This)
75 assert(This->uri || This->uri_builder);
78 hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
80 WARN("CreateUriSimple failed: %08x\n", hres);
88 IUri *nsuri_get_uri(nsWineURI *nsuri)
90 if(!ensure_uri(nsuri))
93 IUri_AddRef(nsuri->uri);
97 static IUri *get_uri_nofrag(IUri *uri)
99 IUriBuilder *uri_builder;
104 hres = IUri_HasProperty(uri, Uri_PROPERTY_FRAGMENT, &b);
105 if(SUCCEEDED(hres) && !b) {
110 hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
114 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_FRAGMENT);
116 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &ret);
117 IUriBuilder_Release(uri_builder);
124 BOOL compare_ignoring_frag(IUri *uri1, IUri *uri2)
126 IUri *uri_nofrag1, *uri_nofrag2;
129 uri_nofrag1 = get_uri_nofrag(uri1);
133 uri_nofrag2 = get_uri_nofrag(uri2);
135 IUri_IsEqual(uri_nofrag1, uri_nofrag2, &ret);
136 IUri_Release(uri_nofrag2);
139 IUri_Release(uri_nofrag1);
143 static nsresult create_nsuri(IUri*,HTMLOuterWindow*,NSContainer*,nsWineURI**);
145 static const char *debugstr_nsacstr(const nsACString *nsstr)
149 nsACString_GetData(nsstr, &data);
150 return debugstr_a(data);
153 static nsresult return_wstr_nsacstr(nsACString *ret_str, const WCHAR *str, int len)
158 TRACE("returning %s\n", debugstr_wn(str, len));
161 nsACString_SetData(ret_str, "");
165 lena = WideCharToMultiByte(CP_ACP, 0, str, len, NULL, 0, NULL, NULL);
166 stra = heap_alloc(lena+1);
168 return NS_ERROR_OUT_OF_MEMORY;
170 WideCharToMultiByte(CP_ACP, 0, str, len, stra, lena, NULL, NULL);
173 nsACString_SetData(ret_str, stra);
178 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
180 const WCHAR *ptr = nsuri;
182 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
184 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
185 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
187 if(*ptr || ret_empty) {
188 *ret = SysAllocString(ptr);
190 return E_OUTOFMEMORY;
195 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
199 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
201 IOleCommandTarget *cmdtrg = NULL;
204 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
205 if(SUCCEEDED(hres)) {
206 VARIANT varUrl, varRes;
208 V_VT(&varUrl) = VT_BSTR;
209 V_BSTR(&varUrl) = url;
210 V_VT(&varRes) = VT_BOOL;
212 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
214 IOleCommandTarget_Release(cmdtrg);
216 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
217 TRACE("got VARIANT_FALSE, do not load\n");
225 static nsresult before_async_open(nsChannel *channel, NSContainer *container, BOOL *cancel)
227 HTMLDocumentObj *doc = container->doc;
236 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
238 return NS_ERROR_FAILURE;
240 if(!exec_shldocvw_67(doc, display_uri)) {
241 SysFreeString(display_uri);
246 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, 0, cancel);
247 SysFreeString(display_uri);
253 HRESULT load_nsuri(HTMLOuterWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
255 nsIWebNavigation *web_navigation;
256 nsIDocShell *doc_shell;
257 HTMLDocumentNode *doc;
260 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
261 if(NS_FAILED(nsres)) {
262 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
266 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
267 nsIWebNavigation_Release(web_navigation);
268 if(NS_FAILED(nsres)) {
269 ERR("Could not get nsIDocShell: %08x\n", nsres);
273 uri->channel_bsc = channelbsc;
274 doc = window->base.inner_window->doc;
275 doc->skip_mutation_notif = TRUE;
276 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIFileURL_iface, NULL, flags, FALSE);
277 if(doc == window->base.inner_window->doc)
278 doc->skip_mutation_notif = FALSE;
279 uri->channel_bsc = NULL;
280 nsIDocShell_Release(doc_shell);
281 if(NS_FAILED(nsres)) {
282 WARN("LoadURI failed: %08x\n", nsres);
289 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
291 if(This->container) {
292 if(This->container == nscontainer)
294 TRACE("Changing %p -> %p\n", This->container, nscontainer);
295 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
299 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
300 This->container = nscontainer;
303 static void set_uri_window(nsWineURI *This, HTMLOuterWindow *window)
305 if(This->window_ref) {
306 if(This->window_ref->window == window)
308 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
309 windowref_release(This->window_ref);
313 windowref_addref(window->window_ref);
314 This->window_ref = window->window_ref;
317 set_uri_nscontainer(This, window->doc_obj->nscontainer);
319 This->window_ref = NULL;
323 static inline BOOL is_http_channel(nsChannel *This)
325 return This->uri->scheme == URL_SCHEME_HTTP || This->uri->scheme == URL_SCHEME_HTTPS;
328 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
332 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
333 if(!strcmpiW(iter->header, name))
340 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
343 const char *header_namea;
344 http_header_t *header;
348 nsACString_GetData(header_name_str, &header_namea);
349 header_name = heap_strdupAtoW(header_namea);
351 return NS_ERROR_UNEXPECTED;
353 header = find_http_header(headers, header_name, strlenW(header_name));
354 heap_free(header_name);
356 return NS_ERROR_NOT_AVAILABLE;
358 data = heap_strdupWtoA(header->data);
360 return NS_ERROR_UNEXPECTED;
362 TRACE("%s -> %s\n", debugstr_a(header_namea), debugstr_a(data));
363 nsACString_SetData(_retval, data);
368 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
369 const WCHAR *value, int value_len)
371 http_header_t *header;
373 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
375 header = find_http_header(headers, name, name_len);
379 new_data = heap_strndupW(value, value_len);
381 return E_OUTOFMEMORY;
383 heap_free(header->data);
384 header->data = new_data;
386 header = heap_alloc(sizeof(http_header_t));
388 return E_OUTOFMEMORY;
390 header->header = heap_strndupW(name, name_len);
391 header->data = heap_strndupW(value, value_len);
392 if(!header->header || !header->data) {
393 heap_free(header->header);
394 heap_free(header->data);
396 return E_OUTOFMEMORY;
399 list_add_tail(headers, &header->entry);
405 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
406 const nsACString *value_str)
408 const char *namea, *valuea;
412 nsACString_GetData(name_str, &namea);
413 name = heap_strdupAtoW(namea);
415 return NS_ERROR_UNEXPECTED;
417 nsACString_GetData(value_str, &valuea);
418 value = heap_strdupAtoW(valuea);
421 return NS_ERROR_UNEXPECTED;
424 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
428 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
431 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
433 nsACString header_str, value_str;
434 char *header, *value;
438 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
439 header = heap_strdupWtoA(iter->header);
441 return NS_ERROR_OUT_OF_MEMORY;
443 value = heap_strdupWtoA(iter->data);
446 return NS_ERROR_OUT_OF_MEMORY;
449 nsACString_InitDepend(&header_str, header);
450 nsACString_InitDepend(&value_str, value);
451 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
452 nsACString_Finish(&header_str);
453 nsACString_Finish(&value_str);
463 static void free_http_headers(struct list *list)
465 http_header_t *iter, *iter_next;
467 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
468 list_remove(&iter->entry);
469 heap_free(iter->header);
470 heap_free(iter->data);
475 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
477 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
480 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
482 nsChannel *This = impl_from_nsIHttpChannel(iface);
484 if(IsEqualGUID(&IID_nsISupports, riid)) {
485 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
486 *result = &This->nsIHttpChannel_iface;
487 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
488 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
489 *result = &This->nsIHttpChannel_iface;
490 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
491 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
492 *result = &This->nsIHttpChannel_iface;
493 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
494 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
495 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
496 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
497 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
498 *result = &This->nsIUploadChannel_iface;
499 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
500 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
501 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
503 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
508 nsIChannel_AddRef(&This->nsIHttpChannel_iface);
512 return NS_NOINTERFACE;
515 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
517 nsChannel *This = impl_from_nsIHttpChannel(iface);
518 nsrefcnt ref = InterlockedIncrement(&This->ref);
520 TRACE("(%p) ref=%d\n", This, ref);
525 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
527 nsChannel *This = impl_from_nsIHttpChannel(iface);
528 LONG ref = InterlockedDecrement(&This->ref);
531 nsIURI_Release(&This->uri->nsIFileURL_iface);
533 nsISupports_Release(This->owner);
534 if(This->post_data_stream)
535 nsIInputStream_Release(This->post_data_stream);
537 nsILoadGroup_Release(This->load_group);
538 if(This->notif_callback)
539 nsIInterfaceRequestor_Release(This->notif_callback);
540 if(This->original_uri)
541 nsIURI_Release(This->original_uri);
543 nsIURI_Release(This->referrer);
545 free_http_headers(&This->response_headers);
546 free_http_headers(&This->request_headers);
548 heap_free(This->content_type);
549 heap_free(This->charset);
556 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
558 nsChannel *This = impl_from_nsIHttpChannel(iface);
560 TRACE("(%p)->(%p)\n", This, aName);
562 return nsIURI_GetSpec(&This->uri->nsIFileURL_iface, aName);
565 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, cpp_bool *_retval)
567 nsChannel *This = impl_from_nsIHttpChannel(iface);
569 FIXME("(%p)->(%p)\n", This, _retval);
571 return NS_ERROR_NOT_IMPLEMENTED;
574 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
576 nsChannel *This = impl_from_nsIHttpChannel(iface);
578 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
580 return *aStatus = NS_OK;
583 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
585 nsChannel *This = impl_from_nsIHttpChannel(iface);
587 FIXME("(%p)->(%08x)\n", This, aStatus);
589 return NS_ERROR_NOT_IMPLEMENTED;
592 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
594 nsChannel *This = impl_from_nsIHttpChannel(iface);
596 FIXME("(%p)\n", This);
598 return NS_ERROR_NOT_IMPLEMENTED;
601 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
603 nsChannel *This = impl_from_nsIHttpChannel(iface);
605 FIXME("(%p)\n", This);
607 return NS_ERROR_NOT_IMPLEMENTED;
610 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
612 nsChannel *This = impl_from_nsIHttpChannel(iface);
614 TRACE("(%p)->(%p)\n", This, aLoadGroup);
617 nsILoadGroup_AddRef(This->load_group);
619 *aLoadGroup = This->load_group;
623 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
625 nsChannel *This = impl_from_nsIHttpChannel(iface);
627 TRACE("(%p)->(%p)\n", This, aLoadGroup);
630 nsILoadGroup_Release(This->load_group);
632 nsILoadGroup_AddRef(aLoadGroup);
633 This->load_group = aLoadGroup;
638 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
640 nsChannel *This = impl_from_nsIHttpChannel(iface);
642 TRACE("(%p)->(%p)\n", This, aLoadFlags);
644 *aLoadFlags = This->load_flags;
648 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
650 nsChannel *This = impl_from_nsIHttpChannel(iface);
652 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
654 This->load_flags = aLoadFlags;
658 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
660 nsChannel *This = impl_from_nsIHttpChannel(iface);
662 TRACE("(%p)->(%p)\n", This, aOriginalURI);
664 if(This->original_uri)
665 nsIURI_AddRef(This->original_uri);
667 *aOriginalURI = This->original_uri;
671 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
673 nsChannel *This = impl_from_nsIHttpChannel(iface);
675 TRACE("(%p)->(%p)\n", This, aOriginalURI);
677 if(This->original_uri)
678 nsIURI_Release(This->original_uri);
680 nsIURI_AddRef(aOriginalURI);
681 This->original_uri = aOriginalURI;
685 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
687 nsChannel *This = impl_from_nsIHttpChannel(iface);
689 TRACE("(%p)->(%p)\n", This, aURI);
691 nsIURI_AddRef(&This->uri->nsIFileURL_iface);
692 *aURI = (nsIURI*)This->uri;
697 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
699 nsChannel *This = impl_from_nsIHttpChannel(iface);
701 TRACE("(%p)->(%p)\n", This, aOwner);
704 nsISupports_AddRef(This->owner);
705 *aOwner = This->owner;
710 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
712 nsChannel *This = impl_from_nsIHttpChannel(iface);
714 TRACE("(%p)->(%p)\n", This, aOwner);
717 nsISupports_AddRef(aOwner);
719 nsISupports_Release(This->owner);
720 This->owner = aOwner;
725 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
726 nsIInterfaceRequestor **aNotificationCallbacks)
728 nsChannel *This = impl_from_nsIHttpChannel(iface);
730 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
732 if(This->notif_callback)
733 nsIInterfaceRequestor_AddRef(This->notif_callback);
734 *aNotificationCallbacks = This->notif_callback;
739 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
740 nsIInterfaceRequestor *aNotificationCallbacks)
742 nsChannel *This = impl_from_nsIHttpChannel(iface);
744 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
746 if(This->notif_callback)
747 nsIInterfaceRequestor_Release(This->notif_callback);
748 if(aNotificationCallbacks)
749 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
751 This->notif_callback = aNotificationCallbacks;
756 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
758 nsChannel *This = impl_from_nsIHttpChannel(iface);
760 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
762 return NS_ERROR_NOT_IMPLEMENTED;
765 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
767 nsChannel *This = impl_from_nsIHttpChannel(iface);
769 TRACE("(%p)->(%p)\n", This, aContentType);
771 if(This->content_type) {
772 nsACString_SetData(aContentType, This->content_type);
776 if(This->uri->is_doc_uri) {
777 WARN("Document channel with no MIME set. Assuming text/html\n");
778 nsACString_SetData(aContentType, "text/html");
782 WARN("unknown type\n");
783 return NS_ERROR_FAILURE;
786 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
787 const nsACString *aContentType)
789 nsChannel *This = impl_from_nsIHttpChannel(iface);
790 const char *content_type;
792 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
794 nsACString_GetData(aContentType, &content_type);
795 heap_free(This->content_type);
796 This->content_type = heap_strdupA(content_type);
801 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
802 nsACString *aContentCharset)
804 nsChannel *This = impl_from_nsIHttpChannel(iface);
806 TRACE("(%p)->(%p)\n", This, aContentCharset);
809 nsACString_SetData(aContentCharset, This->charset);
813 nsACString_SetData(aContentCharset, "");
817 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
818 const nsACString *aContentCharset)
820 nsChannel *This = impl_from_nsIHttpChannel(iface);
824 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
826 nsACString_GetData(aContentCharset, &data);
827 charset = heap_strdupA(data);
829 return NS_ERROR_OUT_OF_MEMORY;
831 heap_free(This->charset);
832 This->charset = charset;
836 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
838 nsChannel *This = impl_from_nsIHttpChannel(iface);
840 FIXME("(%p)->(%p)\n", This, aContentLength);
842 return NS_ERROR_NOT_IMPLEMENTED;
845 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
847 nsChannel *This = impl_from_nsIHttpChannel(iface);
849 FIXME("(%p)->(%d)\n", This, aContentLength);
851 return NS_ERROR_NOT_IMPLEMENTED;
854 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
856 nsChannel *This = impl_from_nsIHttpChannel(iface);
858 FIXME("(%p)->(%p)\n", This, _retval);
860 return NS_ERROR_NOT_IMPLEMENTED;
863 static HTMLOuterWindow *get_window_from_load_group(nsChannel *This)
865 HTMLOuterWindow *window;
872 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
873 if(NS_FAILED(nsres)) {
874 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
881 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
882 nsIRequest_Release(req);
883 if(NS_FAILED(nsres)) {
884 WARN("Could not get nsIChannel interface: %08x\n", nsres);
888 nsres = nsIChannel_GetURI(channel, &uri);
889 nsIChannel_Release(channel);
890 if(NS_FAILED(nsres)) {
891 ERR("GetURI failed: %08x\n", nsres);
895 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
897 if(NS_FAILED(nsres)) {
898 TRACE("Could not get nsWineURI: %08x\n", nsres);
902 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
904 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
905 nsIURI_Release(&wine_uri->nsIFileURL_iface);
910 static HTMLOuterWindow *get_channel_window(nsChannel *This)
912 nsIWebProgress *web_progress;
913 nsIDOMWindow *nswindow;
914 HTMLOuterWindow *window;
917 if(This->load_group) {
918 nsIRequestObserver *req_observer;
920 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
921 if(NS_FAILED(nsres) || !req_observer) {
922 ERR("GetGroupObserver failed: %08x\n", nsres);
926 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
927 nsIRequestObserver_Release(req_observer);
928 if(NS_FAILED(nsres)) {
929 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
932 }else if(This->notif_callback) {
933 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
934 if(NS_FAILED(nsres)) {
935 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
939 ERR("no load group nor notif callback\n");
943 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
944 nsIWebProgress_Release(web_progress);
945 if(NS_FAILED(nsres) || !nswindow) {
946 ERR("GetDOMWindow failed: %08x\n", nsres);
950 window = nswindow_to_window(nswindow);
951 nsIDOMWindow_Release(nswindow);
954 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
956 FIXME("NULL window for %p\n", nswindow);
962 HTMLInnerWindow *window;
963 nsChannelBSC *bscallback;
964 } start_binding_task_t;
966 static void start_binding_proc(task_t *_task)
968 start_binding_task_t *task = (start_binding_task_t*)_task;
970 start_binding(task->window, (BSCallback*)task->bscallback, NULL);
973 static void start_binding_task_destr(task_t *_task)
975 start_binding_task_t *task = (start_binding_task_t*)_task;
977 IBindStatusCallback_Release(&task->bscallback->bsc.IBindStatusCallback_iface);
981 static nsresult async_open(nsChannel *This, HTMLOuterWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
982 nsISupports *context)
984 nsChannelBSC *bscallback;
985 IMoniker *mon = NULL;
988 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
990 WARN("CreateURLMoniker failed: %08x\n", hres);
991 return NS_ERROR_UNEXPECTED;
995 set_current_mon(window, mon);
997 hres = create_channelbsc(mon, NULL, NULL, 0, is_doc_channel, &bscallback);
998 IMoniker_Release(mon);
1000 return NS_ERROR_UNEXPECTED;
1002 channelbsc_set_channel(bscallback, This, listener, context);
1004 if(is_doc_channel) {
1005 hres = create_pending_window(window, bscallback);
1007 async_start_doc_binding(window, window->pending_window);
1008 IUnknown_Release((IUnknown*)bscallback);
1010 return NS_ERROR_UNEXPECTED;
1012 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
1014 task->window = window->base.inner_window;
1015 task->bscallback = bscallback;
1016 push_task(&task->header, start_binding_proc, start_binding_task_destr, window->base.inner_window->task_magic);
1022 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
1023 nsISupports *aContext)
1025 nsChannel *This = impl_from_nsIHttpChannel(iface);
1026 HTMLOuterWindow *window = NULL;
1027 BOOL cancel = FALSE;
1028 nsresult nsres = NS_OK;
1030 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
1032 if(!ensure_uri(This->uri))
1033 return NS_ERROR_FAILURE;
1035 if(TRACE_ON(mshtml)) {
1037 IUri_GetDisplayUri(This->uri->uri, &uri_str);
1038 TRACE("opening %s\n", debugstr_w(uri_str));
1039 SysFreeString(uri_str);
1042 if(This->uri->is_doc_uri) {
1043 window = get_channel_window(This);
1045 set_uri_window(This->uri, window);
1046 }else if(This->uri->container) {
1049 /* nscontainer->doc should be NULL which means navigation to a new window */
1050 if(This->uri->container->doc)
1051 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
1053 nsres = before_async_open(This, This->uri->container, &b);
1054 if(NS_FAILED(nsres))
1057 FIXME("Navigation not cancelled\n");
1058 return NS_ERROR_UNEXPECTED;
1063 if(This->uri->window_ref && This->uri->window_ref->window) {
1064 window = This->uri->window_ref->window;
1065 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1067 /* FIXME: Analyze removing get_window_from_load_group call */
1068 if(This->load_group)
1069 window = get_window_from_load_group(This);
1071 window = get_channel_window(This);
1073 set_uri_window(This->uri, window);
1078 ERR("window = NULL\n");
1079 return NS_ERROR_UNEXPECTED;
1082 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1083 if(This->uri->channel_bsc) {
1084 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1086 if(window->doc_obj->mime) {
1087 heap_free(This->content_type);
1088 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1093 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
1094 if(NS_SUCCEEDED(nsres) && cancel) {
1095 TRACE("canceled\n");
1096 nsres = NS_BINDING_ABORTED;
1102 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1104 if(NS_SUCCEEDED(nsres) && This->load_group) {
1105 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1107 if(NS_FAILED(nsres))
1108 ERR("AddRequest failed: %08x\n", nsres);
1111 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
1115 static nsresult NSAPI nsChannel_GetContentDisposition(nsIHttpChannel *iface, PRUint32 *aContentDisposition)
1117 nsChannel *This = impl_from_nsIHttpChannel(iface);
1118 FIXME("(%p)->(%p)\n", This, aContentDisposition);
1119 return NS_ERROR_NOT_IMPLEMENTED;
1122 static nsresult NSAPI nsChannel_GetContentDispositionFilename(nsIHttpChannel *iface, nsAString *aContentDispositionFilename)
1124 nsChannel *This = impl_from_nsIHttpChannel(iface);
1125 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1126 return NS_ERROR_NOT_IMPLEMENTED;
1129 static nsresult NSAPI nsChannel_GetContentDispositionHeader(nsIHttpChannel *iface, nsACString *aContentDispositionHeader)
1131 nsChannel *This = impl_from_nsIHttpChannel(iface);
1132 FIXME("(%p)->(%p)\n", This, aContentDispositionHeader);
1133 return NS_ERROR_NOT_IMPLEMENTED;
1136 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1138 nsChannel *This = impl_from_nsIHttpChannel(iface);
1140 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1142 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1146 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1147 const nsACString *aRequestMethod)
1149 nsChannel *This = impl_from_nsIHttpChannel(iface);
1153 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1155 nsACString_GetData(aRequestMethod, &method);
1156 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1157 if(!strcasecmp(method, request_method_strings[i])) {
1158 This->request_method = i;
1163 ERR("Invalid method %s\n", debugstr_a(method));
1164 return NS_ERROR_UNEXPECTED;
1167 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1169 nsChannel *This = impl_from_nsIHttpChannel(iface);
1171 TRACE("(%p)->(%p)\n", This, aReferrer);
1174 nsIURI_AddRef(This->referrer);
1175 *aReferrer = This->referrer;
1179 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1181 nsChannel *This = impl_from_nsIHttpChannel(iface);
1183 TRACE("(%p)->(%p)\n", This, aReferrer);
1186 nsIURI_AddRef(aReferrer);
1188 nsIURI_Release(This->referrer);
1189 This->referrer = aReferrer;
1193 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1194 const nsACString *aHeader, nsACString *_retval)
1196 nsChannel *This = impl_from_nsIHttpChannel(iface);
1198 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1200 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1203 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1204 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1206 nsChannel *This = impl_from_nsIHttpChannel(iface);
1208 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1211 FIXME("aMerge not supported\n");
1213 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1216 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1217 nsIHttpHeaderVisitor *aVisitor)
1219 nsChannel *This = impl_from_nsIHttpChannel(iface);
1221 FIXME("(%p)->(%p)\n", This, aVisitor);
1223 return NS_ERROR_NOT_IMPLEMENTED;
1226 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1228 nsChannel *This = impl_from_nsIHttpChannel(iface);
1230 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1232 return NS_ERROR_NOT_IMPLEMENTED;
1235 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1237 nsChannel *This = impl_from_nsIHttpChannel(iface);
1239 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1241 return NS_ERROR_NOT_IMPLEMENTED;
1244 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1246 nsChannel *This = impl_from_nsIHttpChannel(iface);
1248 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1250 return NS_ERROR_NOT_IMPLEMENTED;
1253 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1255 nsChannel *This = impl_from_nsIHttpChannel(iface);
1257 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1259 return NS_ERROR_NOT_IMPLEMENTED;
1262 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1264 nsChannel *This = impl_from_nsIHttpChannel(iface);
1266 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1268 if(This->response_status) {
1269 *aResponseStatus = This->response_status;
1273 WARN("No response status\n");
1274 return NS_ERROR_UNEXPECTED;
1277 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1278 nsACString *aResponseStatusText)
1280 nsChannel *This = impl_from_nsIHttpChannel(iface);
1282 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1284 return NS_ERROR_NOT_IMPLEMENTED;
1287 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1288 cpp_bool *aRequestSucceeded)
1290 nsChannel *This = impl_from_nsIHttpChannel(iface);
1292 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1294 if(!This->response_status)
1295 return NS_ERROR_NOT_AVAILABLE;
1297 *aRequestSucceeded = This->response_status/100 == 2;
1302 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1303 const nsACString *header, nsACString *_retval)
1305 nsChannel *This = impl_from_nsIHttpChannel(iface);
1307 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1309 return get_channel_http_header(&This->response_headers, header, _retval);
1312 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1313 const nsACString *header, const nsACString *value, cpp_bool merge)
1315 nsChannel *This = impl_from_nsIHttpChannel(iface);
1317 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1319 return NS_ERROR_NOT_IMPLEMENTED;
1322 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1323 nsIHttpHeaderVisitor *aVisitor)
1325 nsChannel *This = impl_from_nsIHttpChannel(iface);
1327 TRACE("(%p)->(%p)\n", This, aVisitor);
1329 return visit_http_headers(&This->response_headers, aVisitor);
1332 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1334 nsChannel *This = impl_from_nsIHttpChannel(iface);
1335 http_header_t *header;
1337 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1338 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1340 TRACE("(%p)->(%p)\n", This, _retval);
1342 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1343 *_retval = header && !strcmpiW(header->data, no_storeW);
1347 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1349 nsChannel *This = impl_from_nsIHttpChannel(iface);
1351 FIXME("(%p)->(%p)\n", This, _retval);
1353 return NS_ERROR_NOT_IMPLEMENTED;
1356 static const nsIHttpChannelVtbl nsChannelVtbl = {
1357 nsChannel_QueryInterface,
1361 nsChannel_IsPending,
1362 nsChannel_GetStatus,
1366 nsChannel_GetLoadGroup,
1367 nsChannel_SetLoadGroup,
1368 nsChannel_GetLoadFlags,
1369 nsChannel_SetLoadFlags,
1370 nsChannel_GetOriginalURI,
1371 nsChannel_SetOriginalURI,
1375 nsChannel_GetNotificationCallbacks,
1376 nsChannel_SetNotificationCallbacks,
1377 nsChannel_GetSecurityInfo,
1378 nsChannel_GetContentType,
1379 nsChannel_SetContentType,
1380 nsChannel_GetContentCharset,
1381 nsChannel_SetContentCharset,
1382 nsChannel_GetContentLength,
1383 nsChannel_SetContentLength,
1385 nsChannel_AsyncOpen,
1386 nsChannel_GetContentDisposition,
1387 nsChannel_GetContentDispositionFilename,
1388 nsChannel_GetContentDispositionHeader,
1389 nsChannel_GetRequestMethod,
1390 nsChannel_SetRequestMethod,
1391 nsChannel_GetReferrer,
1392 nsChannel_SetReferrer,
1393 nsChannel_GetRequestHeader,
1394 nsChannel_SetRequestHeader,
1395 nsChannel_VisitRequestHeaders,
1396 nsChannel_GetAllowPipelining,
1397 nsChannel_SetAllowPipelining,
1398 nsChannel_GetRedirectionLimit,
1399 nsChannel_SetRedirectionLimit,
1400 nsChannel_GetResponseStatus,
1401 nsChannel_GetResponseStatusText,
1402 nsChannel_GetRequestSucceeded,
1403 nsChannel_GetResponseHeader,
1404 nsChannel_SetResponseHeader,
1405 nsChannel_VisitResponseHeaders,
1406 nsChannel_IsNoStoreResponse,
1407 nsChannel_IsNoCacheResponse
1410 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1412 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1415 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1418 nsChannel *This = impl_from_nsIUploadChannel(iface);
1419 return nsIChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1422 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1424 nsChannel *This = impl_from_nsIUploadChannel(iface);
1425 return nsIChannel_AddRef(&This->nsIHttpChannel_iface);
1428 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1430 nsChannel *This = impl_from_nsIUploadChannel(iface);
1431 return nsIChannel_Release(&This->nsIHttpChannel_iface);
1434 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1435 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1437 nsChannel *This = impl_from_nsIUploadChannel(iface);
1438 const char *content_type;
1440 static const WCHAR content_typeW[] =
1441 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1443 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1445 This->post_data_contains_headers = TRUE;
1448 nsACString_GetData(aContentType, &content_type);
1452 ct = heap_strdupAtoW(content_type);
1454 return NS_ERROR_UNEXPECTED;
1456 set_http_header(&This->request_headers, content_typeW,
1457 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1459 This->post_data_contains_headers = FALSE;
1463 if(This->post_data_stream)
1464 nsIInputStream_Release(This->post_data_stream);
1466 if(aContentLength != -1)
1467 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1469 if(This->post_data_stream)
1470 nsIInputStream_Release(This->post_data_stream);
1471 This->post_data_stream = aStream;
1473 nsIInputStream_AddRef(aStream);
1475 This->request_method = METHOD_POST;
1479 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1480 nsIInputStream **aUploadStream)
1482 nsChannel *This = impl_from_nsIUploadChannel(iface);
1484 TRACE("(%p)->(%p)\n", This, aUploadStream);
1486 if(This->post_data_stream)
1487 nsIInputStream_AddRef(This->post_data_stream);
1489 *aUploadStream = This->post_data_stream;
1493 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1494 nsUploadChannel_QueryInterface,
1495 nsUploadChannel_AddRef,
1496 nsUploadChannel_Release,
1497 nsUploadChannel_SetUploadStream,
1498 nsUploadChannel_GetUploadStream
1501 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1503 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1506 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1509 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1510 return nsIChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1513 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1515 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1516 return nsIChannel_AddRef(&This->nsIHttpChannel_iface);
1519 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1521 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1522 return nsIChannel_Release(&This->nsIHttpChannel_iface);
1525 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1527 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1529 FIXME("(%p)->()\n", This);
1531 return NS_ERROR_NOT_IMPLEMENTED;
1534 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1536 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1538 FIXME("(%p)->()\n", This);
1540 return NS_ERROR_NOT_IMPLEMENTED;
1543 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1545 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1547 FIXME("(%p)->()\n", This);
1549 return NS_ERROR_NOT_IMPLEMENTED;
1552 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1554 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1556 FIXME("(%p)->()\n", This);
1558 return NS_ERROR_NOT_IMPLEMENTED;
1561 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1563 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1565 FIXME("(%p)->()\n", This);
1567 return NS_ERROR_NOT_IMPLEMENTED;
1570 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1572 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1574 FIXME("(%p)->()\n", This);
1576 return NS_ERROR_NOT_IMPLEMENTED;
1579 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1581 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1583 FIXME("(%p)->()\n", This);
1585 return NS_ERROR_NOT_IMPLEMENTED;
1588 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1590 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1592 FIXME("(%p)->()\n", This);
1594 return NS_ERROR_NOT_IMPLEMENTED;
1597 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1599 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1601 FIXME("(%p)->(%p)\n", This, aCanceled);
1603 return NS_ERROR_NOT_IMPLEMENTED;
1606 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1608 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1610 FIXME("(%p)->(%p)\n", This, aCanceled);
1612 return NS_ERROR_NOT_IMPLEMENTED;
1615 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1617 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1619 FIXME("(%p)->(%x)\n", This, aCanceled);
1621 return NS_ERROR_NOT_IMPLEMENTED;
1624 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1626 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1628 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1630 return NS_ERROR_NOT_IMPLEMENTED;
1633 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, PRInt32 *aLocalPort)
1635 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1637 FIXME("(%p)->(%p)\n", This, aLocalPort);
1639 return NS_ERROR_NOT_IMPLEMENTED;
1642 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1644 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1646 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1648 return NS_ERROR_NOT_IMPLEMENTED;
1651 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, PRInt32 *aRemotePort)
1653 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1655 FIXME("(%p)->(%p)\n", This, aRemotePort);
1657 return NS_ERROR_NOT_IMPLEMENTED;
1660 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1662 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1664 FIXME("(%p)->(%p)\n", This, cacheKeys);
1666 return NS_ERROR_NOT_IMPLEMENTED;
1669 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1670 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1672 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1673 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1674 return NS_ERROR_NOT_IMPLEMENTED;
1677 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1679 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1680 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1681 return NS_ERROR_NOT_IMPLEMENTED;
1684 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1686 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1687 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1688 return NS_ERROR_NOT_IMPLEMENTED;
1691 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1692 nsHttpChannelInternal_QueryInterface,
1693 nsHttpChannelInternal_AddRef,
1694 nsHttpChannelInternal_Release,
1695 nsHttpChannelInternal_GetDocumentURI,
1696 nsHttpChannelInternal_SetDocumentURI,
1697 nsHttpChannelInternal_GetRequestVersion,
1698 nsHttpChannelInternal_GetResponseVersion,
1699 nsHttpChannelInternal_SetCookie,
1700 nsHttpChannelInternal_SetupFallbackChannel,
1701 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1702 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1703 nsHttpChannelInternal_GetCanceled,
1704 nsHttpChannelInternal_GetChannelIsForDownload,
1705 nsHttpChannelInternal_SetChannelIsForDownload,
1706 nsHttpChannelInternal_GetLocalAddress,
1707 nsHttpChannelInternal_GetLocalPort,
1708 nsHttpChannelInternal_GetRemoteAddress,
1709 nsHttpChannelInternal_GetRemotePort,
1710 nsHttpChannelInternal_SetCacheKeysRedirectChain,
1711 nsHttpChannelInternal_HTTPUpgrade,
1712 nsHttpChannelInternal_GetAllowSpdy,
1713 nsHttpChannelInternal_SetAllowSpdy
1717 static void invalidate_uri(nsWineURI *This)
1720 IUri_Release(This->uri);
1725 static BOOL ensure_uri_builder(nsWineURI *This)
1727 if(!This->is_mutable) {
1728 WARN("Not mutable URI\n");
1732 if(!This->uri_builder) {
1735 if(!ensure_uri(This))
1738 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1740 WARN("CreateIUriBuilder failed: %08x\n", hres);
1745 invalidate_uri(This);
1749 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1755 if(!ensure_uri(This))
1756 return NS_ERROR_UNEXPECTED;
1758 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1760 WARN("GetPropertyBSTR failed: %08x\n", hres);
1761 return NS_ERROR_UNEXPECTED;
1764 vala = heap_strdupWtoA(val);
1767 return NS_ERROR_OUT_OF_MEMORY;
1769 TRACE("ret %s\n", debugstr_a(vala));
1770 nsACString_SetData(ret, vala);
1775 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
1777 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
1780 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
1782 nsWineURI *This = impl_from_nsIFileURL(iface);
1786 if(IsEqualGUID(&IID_nsISupports, riid)) {
1787 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1788 *result = &This->nsIFileURL_iface;
1789 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1790 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1791 *result = &This->nsIFileURL_iface;
1792 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1793 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1794 *result = &This->nsIFileURL_iface;
1795 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
1796 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
1797 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
1798 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
1799 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
1800 *result = &This->nsIStandardURL_iface;
1801 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
1802 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
1803 *result = &This->nsIStandardURL_iface;
1804 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1805 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1810 nsIURI_AddRef(&This->nsIFileURL_iface);
1814 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1815 return NS_NOINTERFACE;
1818 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
1820 nsWineURI *This = impl_from_nsIFileURL(iface);
1821 LONG ref = InterlockedIncrement(&This->ref);
1823 TRACE("(%p) ref=%d\n", This, ref);
1828 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
1830 nsWineURI *This = impl_from_nsIFileURL(iface);
1831 LONG ref = InterlockedDecrement(&This->ref);
1833 TRACE("(%p) ref=%d\n", This, ref);
1836 if(This->window_ref)
1837 windowref_release(This->window_ref);
1839 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1841 IUri_Release(This->uri);
1848 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
1850 nsWineURI *This = impl_from_nsIFileURL(iface);
1852 TRACE("(%p)->(%p)\n", This, aSpec);
1854 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1857 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
1859 nsWineURI *This = impl_from_nsIFileURL(iface);
1865 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1867 if(!This->is_mutable)
1868 return NS_ERROR_UNEXPECTED;
1870 nsACString_GetData(aSpec, &speca);
1871 spec = heap_strdupAtoW(speca);
1873 return NS_ERROR_OUT_OF_MEMORY;
1875 hres = CreateUri(spec, 0, 0, &uri);
1878 WARN("CreateUri failed: %08x\n", hres);
1879 return NS_ERROR_FAILURE;
1882 invalidate_uri(This);
1883 if(This->uri_builder) {
1884 IUriBuilder_Release(This->uri_builder);
1885 This->uri_builder = NULL;
1892 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
1894 nsWineURI *This = impl_from_nsIFileURL(iface);
1895 FIXME("(%p)->(%p)\n", This, aPrePath);
1896 return NS_ERROR_NOT_IMPLEMENTED;
1899 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
1901 nsWineURI *This = impl_from_nsIFileURL(iface);
1905 TRACE("(%p)->(%p)\n", This, aScheme);
1907 if(!ensure_uri(This))
1908 return NS_ERROR_UNEXPECTED;
1910 hres = IUri_GetScheme(This->uri, &scheme);
1912 WARN("GetScheme failed: %08x\n", hres);
1913 return NS_ERROR_UNEXPECTED;
1916 if(scheme == URL_SCHEME_ABOUT) {
1917 nsACString_SetData(aScheme, "wine");
1921 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1924 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
1926 nsWineURI *This = impl_from_nsIFileURL(iface);
1927 const char *schemea;
1931 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1933 if(!ensure_uri_builder(This))
1934 return NS_ERROR_UNEXPECTED;
1936 nsACString_GetData(aScheme, &schemea);
1937 scheme = heap_strdupAtoW(schemea);
1939 return NS_ERROR_OUT_OF_MEMORY;
1941 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
1944 return NS_ERROR_UNEXPECTED;
1949 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
1951 nsWineURI *This = impl_from_nsIFileURL(iface);
1955 TRACE("(%p)->(%p)\n", This, aUserPass);
1957 if(!ensure_uri(This))
1958 return NS_ERROR_UNEXPECTED;
1960 hres = IUri_GetUserName(This->uri, &user);
1962 return NS_ERROR_FAILURE;
1964 hres = IUri_GetPassword(This->uri, &pass);
1966 SysFreeString(user);
1967 return NS_ERROR_FAILURE;
1970 if(*user || *pass) {
1971 FIXME("Construct user:pass string\n");
1973 nsACString_SetData(aUserPass, "");
1976 SysFreeString(user);
1977 SysFreeString(pass);
1981 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
1983 nsWineURI *This = impl_from_nsIFileURL(iface);
1984 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
1985 const char *user_pass;
1988 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
1990 if(!ensure_uri_builder(This))
1991 return NS_ERROR_UNEXPECTED;
1993 nsACString_GetData(aUserPass, &user_pass);
1997 buf = heap_strdupAtoW(user_pass);
1999 return NS_ERROR_OUT_OF_MEMORY;
2001 ptr = strchrW(buf, ':');
2004 }else if(ptr != buf) {
2014 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2016 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2019 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2022 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2024 nsWineURI *This = impl_from_nsIFileURL(iface);
2026 TRACE("(%p)->(%p)\n", This, aUsername);
2028 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2031 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2033 nsWineURI *This = impl_from_nsIFileURL(iface);
2038 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2040 if(!ensure_uri_builder(This))
2041 return NS_ERROR_UNEXPECTED;
2043 nsACString_GetData(aUsername, &usera);
2044 user = heap_strdupAtoW(usera);
2046 return NS_ERROR_OUT_OF_MEMORY;
2048 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2051 return NS_ERROR_UNEXPECTED;
2056 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2058 nsWineURI *This = impl_from_nsIFileURL(iface);
2060 TRACE("(%p)->(%p)\n", This, aPassword);
2062 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2065 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2067 nsWineURI *This = impl_from_nsIFileURL(iface);
2072 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2074 if(!ensure_uri_builder(This))
2075 return NS_ERROR_UNEXPECTED;
2077 nsACString_GetData(aPassword, &passa);
2078 pass = heap_strdupAtoW(passa);
2080 return NS_ERROR_OUT_OF_MEMORY;
2082 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2085 return NS_ERROR_UNEXPECTED;
2090 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2092 nsWineURI *This = impl_from_nsIFileURL(iface);
2098 TRACE("(%p)->(%p)\n", This, aHostPort);
2100 if(!ensure_uri(This))
2101 return NS_ERROR_UNEXPECTED;
2103 hres = IUri_GetAuthority(This->uri, &val);
2105 WARN("GetAuthority failed: %08x\n", hres);
2106 return NS_ERROR_UNEXPECTED;
2109 ptr = strchrW(val, '@');
2113 vala = heap_strdupWtoA(ptr);
2116 return NS_ERROR_OUT_OF_MEMORY;
2118 TRACE("ret %s\n", debugstr_a(vala));
2119 nsACString_SetData(aHostPort, vala);
2124 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2126 nsWineURI *This = impl_from_nsIFileURL(iface);
2128 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2130 /* Not implemented by Gecko */
2131 return NS_ERROR_NOT_IMPLEMENTED;
2134 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2136 nsWineURI *This = impl_from_nsIFileURL(iface);
2138 TRACE("(%p)->(%p)\n", This, aHost);
2140 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2143 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2145 nsWineURI *This = impl_from_nsIFileURL(iface);
2150 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2152 if(!ensure_uri_builder(This))
2153 return NS_ERROR_UNEXPECTED;
2155 nsACString_GetData(aHost, &hosta);
2156 host = heap_strdupAtoW(hosta);
2158 return NS_ERROR_OUT_OF_MEMORY;
2160 hres = IUriBuilder_SetHost(This->uri_builder, host);
2163 return NS_ERROR_UNEXPECTED;
2168 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, PRInt32 *aPort)
2170 nsWineURI *This = impl_from_nsIFileURL(iface);
2174 TRACE("(%p)->(%p)\n", This, aPort);
2176 if(!ensure_uri(This))
2177 return NS_ERROR_UNEXPECTED;
2179 hres = IUri_GetPort(This->uri, &port);
2181 WARN("GetPort failed: %08x\n", hres);
2182 return NS_ERROR_UNEXPECTED;
2185 *aPort = port ? port : -1;
2189 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, PRInt32 aPort)
2191 nsWineURI *This = impl_from_nsIFileURL(iface);
2194 TRACE("(%p)->(%d)\n", This, aPort);
2196 if(!ensure_uri_builder(This))
2197 return NS_ERROR_UNEXPECTED;
2199 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2200 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2203 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2205 nsWineURI *This = impl_from_nsIFileURL(iface);
2207 TRACE("(%p)->(%p)\n", This, aPath);
2209 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2212 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2214 nsWineURI *This = impl_from_nsIFileURL(iface);
2219 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2221 if(!ensure_uri_builder(This))
2222 return NS_ERROR_UNEXPECTED;
2224 nsACString_GetData(aPath, &patha);
2225 path = heap_strdupAtoW(patha);
2227 return NS_ERROR_OUT_OF_MEMORY;
2229 hres = IUriBuilder_SetPath(This->uri_builder, path);
2232 return NS_ERROR_UNEXPECTED;
2237 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2239 nsWineURI *This = impl_from_nsIFileURL(iface);
2240 nsWineURI *other_obj;
2244 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2246 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2247 if(NS_FAILED(nsres)) {
2248 TRACE("Could not get nsWineURI interface\n");
2253 if(ensure_uri(This) && ensure_uri(other_obj)) {
2256 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2257 if(SUCCEEDED(hres)) {
2261 nsres = NS_ERROR_FAILURE;
2264 nsres = NS_ERROR_UNEXPECTED;
2267 nsIURI_Release(&other_obj->nsIFileURL_iface);
2271 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2273 nsWineURI *This = impl_from_nsIFileURL(iface);
2274 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2278 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2280 if(!ensure_uri(This))
2281 return NS_ERROR_UNEXPECTED;
2283 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2285 return NS_ERROR_UNEXPECTED;
2287 MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2288 *_retval = !strcmpW(scheme_name, buf);
2289 SysFreeString(scheme_name);
2293 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2295 nsWineURI *This = impl_from_nsIFileURL(iface);
2296 nsWineURI *wine_uri;
2299 TRACE("(%p)->(%p)\n", This, _retval);
2301 if(!ensure_uri(This))
2302 return NS_ERROR_UNEXPECTED;
2304 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2305 if(NS_FAILED(nsres)) {
2306 WARN("create_nsuri failed: %08x\n", nsres);
2310 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2314 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2315 nsACString *_retval)
2317 nsWineURI *This = impl_from_nsIFileURL(iface);
2325 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2327 if(!ensure_uri(This))
2328 return NS_ERROR_UNEXPECTED;
2330 nsACString_GetData(aRelativePath, &patha);
2331 path = heap_strdupAtoW(patha);
2333 return NS_ERROR_OUT_OF_MEMORY;
2335 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2338 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2339 return NS_ERROR_FAILURE;
2342 hres = IUri_GetDisplayUri(new_uri, &ret);
2343 IUri_Release(new_uri);
2345 return NS_ERROR_FAILURE;
2347 reta = heap_strdupWtoA(ret);
2350 return NS_ERROR_OUT_OF_MEMORY;
2352 TRACE("returning %s\n", debugstr_a(reta));
2353 nsACString_SetData(_retval, reta);
2358 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2360 nsWineURI *This = impl_from_nsIFileURL(iface);
2362 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2364 return nsIURI_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2367 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2369 nsWineURI *This = impl_from_nsIFileURL(iface);
2371 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2373 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2376 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2378 nsWineURI *This = impl_from_nsIFileURL(iface);
2379 FIXME("(%p)->(%p)\n", This, aOriginCharset);
2380 return NS_ERROR_NOT_IMPLEMENTED;
2383 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2385 nsWineURI *This = impl_from_nsIFileURL(iface);
2390 TRACE("(%p)->(%p)\n", This, aRef);
2392 if(!ensure_uri(This))
2393 return NS_ERROR_UNEXPECTED;
2395 hres = IUri_GetFragment(This->uri, &ref);
2397 return NS_ERROR_UNEXPECTED;
2399 refa = heap_strdupWtoA(ref);
2402 return NS_ERROR_OUT_OF_MEMORY;
2404 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2409 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2411 nsWineURI *This = impl_from_nsIFileURL(iface);
2416 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2418 if(!ensure_uri_builder(This))
2419 return NS_ERROR_UNEXPECTED;
2421 nsACString_GetData(aRef, &refa);
2422 ref = heap_strdupAtoW(refa);
2424 return NS_ERROR_OUT_OF_MEMORY;
2426 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2429 return NS_ERROR_UNEXPECTED;
2434 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2436 nsWineURI *This = impl_from_nsIFileURL(iface);
2437 nsWineURI *other_obj;
2440 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2442 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2443 if(NS_FAILED(nsres)) {
2444 TRACE("Could not get nsWineURI interface\n");
2449 if(ensure_uri(This) && ensure_uri(other_obj)) {
2450 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2453 nsres = NS_ERROR_UNEXPECTED;
2456 nsIURI_Release(&other_obj->nsIFileURL_iface);
2460 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2462 nsWineURI *This = impl_from_nsIFileURL(iface);
2463 nsWineURI *wine_uri;
2467 TRACE("(%p)->(%p)\n", This, _retval);
2469 if(!ensure_uri(This))
2470 return NS_ERROR_UNEXPECTED;
2472 uri = get_uri_nofrag(This->uri);
2474 return NS_ERROR_FAILURE;
2476 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2478 if(NS_FAILED(nsres)) {
2479 WARN("create_nsuri failed: %08x\n", nsres);
2483 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2487 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2489 nsWineURI *This = impl_from_nsIFileURL(iface);
2491 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2493 return nsIURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2496 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2498 nsWineURI *This = impl_from_nsIFileURL(iface);
2502 TRACE("(%p)->(%p)\n", This, aHasRef);
2504 if(!ensure_uri(This))
2505 return NS_ERROR_UNEXPECTED;
2507 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2509 return NS_ERROR_FAILURE;
2515 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2517 nsWineURI *This = impl_from_nsIFileURL(iface);
2519 TRACE("(%p)->(%p)\n", This, aFilePath);
2521 return nsIURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2524 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2526 nsWineURI *This = impl_from_nsIFileURL(iface);
2528 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2530 if(!This->is_mutable)
2531 return NS_ERROR_UNEXPECTED;
2533 return nsIURL_SetPath(&This->nsIFileURL_iface, aFilePath);
2536 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
2538 nsWineURI *This = impl_from_nsIFileURL(iface);
2540 TRACE("(%p)->(%p)\n", This, aQuery);
2542 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2545 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
2547 nsWineURI *This = impl_from_nsIFileURL(iface);
2552 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2554 if(!ensure_uri_builder(This))
2555 return NS_ERROR_UNEXPECTED;
2557 nsACString_GetData(aQuery, &querya);
2558 query = heap_strdupAtoW(querya);
2560 return NS_ERROR_OUT_OF_MEMORY;
2562 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2565 return NS_ERROR_UNEXPECTED;
2570 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
2575 if(!ensure_uri(This))
2576 return NS_ERROR_UNEXPECTED;
2578 hres = IUri_GetPath(This->uri, path);
2580 return NS_ERROR_FAILURE;
2582 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
2583 if(*ptr == '/' || *ptr == '\\')
2588 ptr = strrchrW(ptr, '.');
2590 ptr = *path + SysStringLen(*path);
2597 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
2599 nsWineURI *This = impl_from_nsIFileURL(iface);
2604 TRACE("(%p)->(%p)\n", This, aDirectory);
2606 nsres = get_uri_path(This, &path, &file, NULL);
2607 if(NS_FAILED(nsres))
2610 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
2611 SysFreeString(path);
2615 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
2617 nsWineURI *This = impl_from_nsIFileURL(iface);
2619 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2621 /* Not implemented by Gecko */
2622 return NS_ERROR_NOT_IMPLEMENTED;
2625 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
2627 nsWineURI *This = impl_from_nsIFileURL(iface);
2632 TRACE("(%p)->(%p)\n", This, aFileName);
2634 nsres = get_uri_path(This, &path, &file, NULL);
2635 if(NS_FAILED(nsres))
2638 nsres = return_wstr_nsacstr(aFileName, file, -1);
2639 SysFreeString(path);
2643 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
2645 nsWineURI *This = impl_from_nsIFileURL(iface);
2646 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2647 return NS_ERROR_NOT_IMPLEMENTED;
2650 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
2652 nsWineURI *This = impl_from_nsIFileURL(iface);
2653 const WCHAR *file, *ext;
2657 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2659 nsres = get_uri_path(This, &path, &file, &ext);
2660 if(NS_FAILED(nsres))
2663 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
2664 SysFreeString(path);
2668 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
2670 nsWineURI *This = impl_from_nsIFileURL(iface);
2671 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2672 return NS_ERROR_NOT_IMPLEMENTED;
2675 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
2677 nsWineURI *This = impl_from_nsIFileURL(iface);
2679 TRACE("(%p)->(%p)\n", This, aFileExtension);
2681 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
2684 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
2686 nsWineURI *This = impl_from_nsIFileURL(iface);
2687 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2688 return NS_ERROR_NOT_IMPLEMENTED;
2691 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2693 nsWineURI *This = impl_from_nsIFileURL(iface);
2694 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2695 return NS_ERROR_NOT_IMPLEMENTED;
2698 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2700 nsWineURI *This = impl_from_nsIFileURL(iface);
2701 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2702 return NS_ERROR_NOT_IMPLEMENTED;
2705 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
2707 nsWineURI *This = impl_from_nsIFileURL(iface);
2708 WCHAR path[MAX_PATH];
2712 TRACE("(%p)->(%p)\n", This, aFile);
2714 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
2716 WARN("CoInternetParseIUri failed: %08x\n", hres);
2717 return NS_ERROR_FAILURE;
2720 return create_nsfile(path, aFile);
2723 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
2725 nsWineURI *This = impl_from_nsIFileURL(iface);
2726 FIXME("(%p)->(%p)\n", This, aFile);
2727 return NS_ERROR_NOT_IMPLEMENTED;
2730 static const nsIFileURLVtbl nsFileURLVtbl = {
2731 nsURI_QueryInterface,
2759 nsURI_GetOriginCharset,
2762 nsURI_EqualsExceptRef,
2763 nsURI_CloneIgnoreRef,
2764 nsURI_GetSpecIgnoringRef,
2774 nsURL_GetFileBaseName,
2775 nsURL_SetFileBaseName,
2776 nsURL_GetFileExtension,
2777 nsURL_SetFileExtension,
2778 nsURL_GetCommonBaseSpec,
2779 nsURL_GetRelativeSpec,
2784 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
2786 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
2789 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
2792 nsWineURI *This = impl_from_nsIStandardURL(iface);
2793 return nsIURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
2796 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
2798 nsWineURI *This = impl_from_nsIStandardURL(iface);
2799 return nsIURL_AddRef(&This->nsIFileURL_iface);
2802 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
2804 nsWineURI *This = impl_from_nsIStandardURL(iface);
2805 return nsIURL_Release(&This->nsIFileURL_iface);
2808 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
2810 nsWineURI *This = impl_from_nsIStandardURL(iface);
2812 TRACE("(%p)->(%p)\n", This, aMutable);
2814 *aMutable = This->is_mutable;
2818 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
2820 nsWineURI *This = impl_from_nsIStandardURL(iface);
2822 TRACE("(%p)->(%x)\n", This, aMutable);
2824 This->is_mutable = aMutable;
2828 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, PRUint32 aUrlType, PRInt32 aDefaultPort,
2829 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
2831 nsWineURI *This = impl_from_nsIStandardURL(iface);
2832 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
2833 return NS_ERROR_NOT_IMPLEMENTED;
2836 static const nsIStandardURLVtbl nsStandardURLVtbl = {
2837 nsStandardURL_QueryInterface,
2838 nsStandardURL_AddRef,
2839 nsStandardURL_Release,
2840 nsStandardURL_GetMutable,
2841 nsStandardURL_SetMutable,
2845 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container, nsWineURI **_retval)
2847 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2850 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
2851 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
2853 ret->is_mutable = TRUE;
2855 set_uri_nscontainer(ret, container);
2856 set_uri_window(ret, window);
2861 hres = IUri_GetScheme(iuri, &ret->scheme);
2863 ret->scheme = URL_SCHEME_UNKNOWN;
2865 TRACE("retval=%p\n", ret);
2870 HRESULT create_doc_uri(HTMLOuterWindow *window, WCHAR *url, nsWineURI **ret)
2877 hres = CreateUri(url, 0, 0, &iuri);
2881 nsres = create_nsuri(iuri, window, window->doc_obj->nscontainer, &uri);
2883 if(NS_FAILED(nsres))
2886 uri->is_doc_uri = TRUE;
2892 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2896 if(!ensure_uri(uri))
2897 return NS_ERROR_UNEXPECTED;
2899 channel = heap_alloc_zero(sizeof(nsChannel));
2901 return NS_ERROR_OUT_OF_MEMORY;
2903 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2904 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2905 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2907 channel->request_method = METHOD_GET;
2908 list_init(&channel->response_headers);
2909 list_init(&channel->request_headers);
2911 nsIURL_AddRef(&uri->nsIFileURL_iface);
2918 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
2920 HTMLOuterWindow *window = NULL;
2927 hres = CreateUri(url, 0, 0, &iuri);
2931 if(orig_channel->uri->window_ref)
2932 window = orig_channel->uri->window_ref->window;
2933 nsres = create_nsuri(iuri, window, NULL, &uri);
2935 if(NS_FAILED(nsres))
2938 nsres = create_nschannel(uri, &channel);
2939 nsIURL_Release(&uri->nsIFileURL_iface);
2940 if(NS_FAILED(nsres))
2943 if(orig_channel->load_group) {
2944 nsILoadGroup_AddRef(orig_channel->load_group);
2945 channel->load_group = orig_channel->load_group;
2948 if(orig_channel->notif_callback) {
2949 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
2950 channel->notif_callback = orig_channel->notif_callback;
2953 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
2955 if(orig_channel->request_method == METHOD_POST)
2956 FIXME("unsupported POST method\n");
2958 if(orig_channel->original_uri) {
2959 nsIURI_AddRef(orig_channel->original_uri);
2960 channel->original_uri = orig_channel->original_uri;
2963 if(orig_channel->referrer) {
2964 nsIURI_AddRef(orig_channel->referrer);
2965 channel->referrer = orig_channel->referrer;
2973 nsIProtocolHandler nsIProtocolHandler_iface;
2977 nsIProtocolHandler *nshandler;
2978 } nsProtocolHandler;
2980 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
2982 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
2985 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2988 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2992 if(IsEqualGUID(&IID_nsISupports, riid)) {
2993 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2994 *result = &This->nsIProtocolHandler_iface;
2995 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2996 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2997 *result = &This->nsIProtocolHandler_iface;
2998 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2999 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3000 return NS_NOINTERFACE;
3004 nsISupports_AddRef((nsISupports*)*result);
3008 WARN("(%s %p)\n", debugstr_guid(riid), result);
3009 return NS_NOINTERFACE;
3012 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3014 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3015 LONG ref = InterlockedIncrement(&This->ref);
3017 TRACE("(%p) ref=%d\n", This, ref);
3022 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3024 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3025 LONG ref = InterlockedDecrement(&This->ref);
3027 TRACE("(%p) ref=%d\n", This, ref);
3031 nsIProtocolHandler_Release(This->nshandler);
3038 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3040 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3042 TRACE("(%p)->(%p)\n", This, aScheme);
3045 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3046 return NS_ERROR_NOT_IMPLEMENTED;
3049 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3050 PRInt32 *aDefaultPort)
3052 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3054 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3057 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3058 return NS_ERROR_NOT_IMPLEMENTED;
3061 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3062 PRUint32 *aProtocolFlags)
3064 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3066 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3069 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3070 return NS_ERROR_NOT_IMPLEMENTED;
3073 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3074 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3076 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3078 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3082 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3083 return NS_ERROR_NOT_IMPLEMENTED;
3086 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3087 nsIURI *aURI, nsIChannel **_retval)
3089 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3091 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3094 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3095 return NS_ERROR_NOT_IMPLEMENTED;
3098 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3099 PRInt32 port, const char *scheme, cpp_bool *_retval)
3101 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3103 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3106 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3107 return NS_ERROR_NOT_IMPLEMENTED;
3110 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3111 nsProtocolHandler_QueryInterface,
3112 nsProtocolHandler_AddRef,
3113 nsProtocolHandler_Release,
3114 nsProtocolHandler_GetScheme,
3115 nsProtocolHandler_GetDefaultPort,
3116 nsProtocolHandler_GetProtocolFlags,
3117 nsProtocolHandler_NewURI,
3118 nsProtocolHandler_NewChannel,
3119 nsProtocolHandler_AllowPort
3122 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
3124 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
3126 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3128 ret->nshandler = nshandler;
3130 return &ret->nsIProtocolHandler_iface;
3133 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
3135 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
3140 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
3145 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
3146 nsIProtocolHandler **_retval)
3148 nsIExternalProtocolHandler *nsexthandler;
3149 nsIProtocolHandler *nshandler;
3152 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3154 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
3155 if(NS_FAILED(nsres)) {
3156 WARN("GetProtocolHandler failed: %08x\n", nsres);
3160 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
3161 (void**)&nsexthandler);
3162 if(NS_FAILED(nsres)) {
3163 *_retval = nshandler;
3167 nsIExternalProtocolHandler_Release(nsexthandler);
3168 *_retval = create_protocol_handler(nshandler);
3169 TRACE("return %p\n", *_retval);
3173 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
3176 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3177 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
3180 static BOOL is_gecko_special_uri(const char *spec)
3182 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3185 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3186 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3190 if(!strncasecmp(spec, "file:", 5)) {
3191 const char *ptr = spec+5;
3194 return is_gecko_path(ptr);
3200 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
3201 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3203 nsWineURI *wine_uri, *base_wine_uri = NULL;
3204 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3205 HTMLOuterWindow *window = NULL;
3206 const char *spec = NULL;
3211 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3214 nsACString_GetData(aSpec, &spec);
3215 if(is_gecko_special_uri(spec))
3216 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3218 if(!strncmp(spec, "wine:", 5))
3222 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3223 if(NS_SUCCEEDED(nsres)) {
3224 if(!ensure_uri(base_wine_uri))
3225 return NS_ERROR_UNEXPECTED;
3226 if(base_wine_uri->window_ref)
3227 window = base_wine_uri->window_ref->window;
3229 WARN("Could not get base nsWineURI: %08x\n", nsres);
3233 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3236 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
3239 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
3241 hres = CreateUri(new_spec, 0, 0, &urlmon_uri);
3243 WARN("CreateUri failed: %08x\n", hres);
3247 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3249 nsres = create_nsuri(urlmon_uri, window, NULL, &wine_uri);
3250 IUri_Release(urlmon_uri);
3252 nsIURI_Release(&base_wine_uri->nsIFileURL_iface);
3253 if(NS_FAILED(nsres))
3256 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3260 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
3263 TRACE("(%p %p)\n", aFile, _retval);
3264 return nsIIOService_NewFileURI(nsio, aFile, _retval);
3267 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
3268 nsIChannel **_retval)
3270 nsWineURI *wine_uri;
3274 TRACE("(%p %p)\n", aURI, _retval);
3276 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3277 if(NS_FAILED(nsres)) {
3278 TRACE("Could not get nsWineURI: %08x\n", nsres);
3279 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
3282 nsres = create_nschannel(wine_uri, &ret);
3283 nsIURL_Release(&wine_uri->nsIFileURL_iface);
3284 if(NS_FAILED(nsres))
3287 nsIURI_AddRef(aURI);
3288 ret->original_uri = aURI;
3290 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3294 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
3295 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
3297 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
3298 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3301 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, cpp_bool *aOffline)
3303 TRACE("(%p)\n", aOffline);
3304 return nsIIOService_GetOffline(nsio, aOffline);
3307 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, cpp_bool aOffline)
3309 TRACE("(%x)\n", aOffline);
3310 return nsIIOService_SetOffline(nsio, aOffline);
3313 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
3314 const char *aScheme, cpp_bool *_retval)
3316 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
3317 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
3320 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
3321 nsACString * _retval)
3323 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
3324 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
3327 static const nsIIOServiceVtbl nsIOServiceVtbl = {
3328 nsIOService_QueryInterface,
3330 nsIOService_Release,
3331 nsIOService_GetProtocolHandler,
3332 nsIOService_GetProtocolFlags,
3334 nsIOService_NewFileURI,
3335 nsIOService_NewChannelFromURI,
3336 nsIOService_NewChannel,
3337 nsIOService_GetOffline,
3338 nsIOService_SetOffline,
3339 nsIOService_AllowPort,
3340 nsIOService_ExtractScheme
3343 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3345 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3348 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3351 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3356 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3361 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3362 nsACString *aCharset, cpp_bool *aHadCharset, nsACString *aContentType)
3364 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3366 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3369 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, cpp_bool *_retval)
3373 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3376 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, cpp_bool *_retval)
3378 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3380 if(aFlags == (1<<11)) {
3385 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3388 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3390 TRACE("(%p %p)\n", aURI, _retval);
3392 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3395 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3397 TRACE("(%p %p)\n", aURI, _retval);
3399 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3402 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3403 PRUint32 aEscapeType, nsACString *_retval)
3405 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3407 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3410 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
3411 nsACString *_retval)
3413 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3415 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3418 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3419 PRUint32 aFlags, nsACString *_retval)
3421 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3423 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3426 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3427 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, cpp_bool *_retval)
3429 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3430 aCharsetEnd, _retval);
3432 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3435 static const nsINetUtilVtbl nsNetUtilVtbl = {
3436 nsNetUtil_QueryInterface,
3439 nsNetUtil_ParseContentType,
3440 nsNetUtil_ProtocolHasFlags,
3441 nsNetUtil_URIChainHasFlags,
3442 nsNetUtil_ToImmutableURI,
3443 nsNetUtil_NewSimpleNestedURI,
3444 nsNetUtil_EscapeString,
3445 nsNetUtil_EscapeURL,
3446 nsNetUtil_UnescapeString,
3447 nsNetUtil_ExtractCharsetFromContentType
3450 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3452 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3457 if(IsEqualGUID(&IID_nsISupports, riid))
3458 *result = &nsIOService;
3459 else if(IsEqualGUID(&IID_nsIIOService, riid))
3460 *result = &nsIOService;
3461 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3462 *result = &nsNetUtil;
3465 nsISupports_AddRef((nsISupports*)*result);
3469 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3470 return NS_NOINTERFACE;
3473 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3478 if(IsEqualGUID(&IID_nsISupports, riid)) {
3479 TRACE("(IID_nsISupports %p)\n", result);
3481 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3482 TRACE("(IID_nsIFactory %p)\n", result);
3487 nsIFactory_AddRef(iface);
3491 WARN("(%s %p)\n", debugstr_guid(riid), result);
3492 return NS_NOINTERFACE;
3495 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3500 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3505 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3506 nsISupports *aOuter, const nsIID *iid, void **result)
3508 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3511 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
3513 WARN("(%x)\n", lock);
3517 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3518 nsIOServiceFactory_QueryInterface,
3519 nsIOServiceFactory_AddRef,
3520 nsIOServiceFactory_Release,
3521 nsIOServiceFactory_CreateInstance,
3522 nsIOServiceFactory_LockFactory
3525 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3527 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3529 OLECHAR *new_url = NULL;
3534 if(!doc->hostui || !ensure_uri(uri))
3537 hres = IUri_GetDisplayUri(uri->uri, &url);
3541 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3542 if(hres == S_OK && new_url) {
3543 if(strcmpW(url, new_url)) {
3544 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3547 CoTaskMemFree(new_url);
3554 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
3556 nsWineURI *wine_uri;
3561 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3562 if(NS_FAILED(nsres)) {
3563 WARN("Could not get nsWineURI: %08x\n", nsres);
3564 return NS_ERROR_NOT_IMPLEMENTED;
3567 if(!wine_uri->is_doc_uri) {
3568 wine_uri->is_doc_uri = TRUE;
3570 if(!wine_uri->container) {
3571 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3572 wine_uri->container = nscontainer;
3575 if(nscontainer->doc)
3576 *_retval = translate_url(nscontainer->doc, wine_uri);
3579 nsIURI_Release(&wine_uri->nsIFileURL_iface);
3583 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3585 nsIFactory *old_factory = NULL;
3588 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3589 &IID_nsIFactory, (void**)&old_factory);
3590 if(NS_FAILED(nsres)) {
3591 ERR("Could not get factory: %08x\n", nsres);
3595 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3596 if(NS_FAILED(nsres)) {
3597 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3598 nsIFactory_Release(old_factory);
3602 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3603 if(NS_FAILED(nsres)) {
3604 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3605 nsIIOService_Release(nsio);
3609 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3610 nsIFactory_Release(old_factory);
3611 if(NS_FAILED(nsres))
3612 ERR("UnregisterFactory failed: %08x\n", nsres);
3614 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3615 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3616 if(NS_FAILED(nsres))
3617 ERR("RegisterFactory failed: %08x\n", nsres);
3620 void release_nsio(void)
3623 nsINetUtil_Release(net_util);
3628 nsIIOService_Release(nsio);