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 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 static 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 nsIHttpChannel_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 nsIFileURL_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 nsIFileURL_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 nsIFileURL_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 nsIFileURL_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 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1010 return NS_ERROR_UNEXPECTED;
1012 start_binding_task_t *task;
1014 task = heap_alloc(sizeof(start_binding_task_t));
1016 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1017 return NS_ERROR_OUT_OF_MEMORY;
1020 task->window = window->base.inner_window;
1021 task->bscallback = bscallback;
1022 hres = push_task(&task->header, start_binding_proc, start_binding_task_destr, window->base.inner_window->task_magic);
1024 return NS_ERROR_OUT_OF_MEMORY;
1030 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
1031 nsISupports *aContext)
1033 nsChannel *This = impl_from_nsIHttpChannel(iface);
1034 HTMLOuterWindow *window = NULL;
1035 BOOL cancel = FALSE;
1036 nsresult nsres = NS_OK;
1038 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
1040 if(!ensure_uri(This->uri))
1041 return NS_ERROR_FAILURE;
1043 if(TRACE_ON(mshtml)) {
1045 IUri_GetDisplayUri(This->uri->uri, &uri_str);
1046 TRACE("opening %s\n", debugstr_w(uri_str));
1047 SysFreeString(uri_str);
1050 if(This->uri->is_doc_uri) {
1051 window = get_channel_window(This);
1053 set_uri_window(This->uri, window);
1054 }else if(This->uri->container) {
1057 /* nscontainer->doc should be NULL which means navigation to a new window */
1058 if(This->uri->container->doc)
1059 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
1061 nsres = before_async_open(This, This->uri->container, &b);
1062 if(NS_FAILED(nsres))
1065 FIXME("Navigation not cancelled\n");
1066 return NS_ERROR_UNEXPECTED;
1071 if(This->uri->window_ref && This->uri->window_ref->window) {
1072 window = This->uri->window_ref->window;
1073 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1075 /* FIXME: Analyze removing get_window_from_load_group call */
1076 if(This->load_group)
1077 window = get_window_from_load_group(This);
1079 window = get_channel_window(This);
1081 set_uri_window(This->uri, window);
1086 ERR("window = NULL\n");
1087 return NS_ERROR_UNEXPECTED;
1090 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1091 if(This->uri->channel_bsc) {
1092 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1094 if(window->doc_obj->mime) {
1095 heap_free(This->content_type);
1096 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1101 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
1102 if(NS_SUCCEEDED(nsres) && cancel) {
1103 TRACE("canceled\n");
1104 nsres = NS_BINDING_ABORTED;
1110 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1112 if(NS_SUCCEEDED(nsres) && This->load_group) {
1113 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1115 if(NS_FAILED(nsres))
1116 ERR("AddRequest failed: %08x\n", nsres);
1119 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
1123 static nsresult NSAPI nsChannel_GetContentDisposition(nsIHttpChannel *iface, PRUint32 *aContentDisposition)
1125 nsChannel *This = impl_from_nsIHttpChannel(iface);
1126 FIXME("(%p)->(%p)\n", This, aContentDisposition);
1127 return NS_ERROR_NOT_IMPLEMENTED;
1130 static nsresult NSAPI nsChannel_GetContentDispositionFilename(nsIHttpChannel *iface, nsAString *aContentDispositionFilename)
1132 nsChannel *This = impl_from_nsIHttpChannel(iface);
1133 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1134 return NS_ERROR_NOT_IMPLEMENTED;
1137 static nsresult NSAPI nsChannel_GetContentDispositionHeader(nsIHttpChannel *iface, nsACString *aContentDispositionHeader)
1139 nsChannel *This = impl_from_nsIHttpChannel(iface);
1140 FIXME("(%p)->(%p)\n", This, aContentDispositionHeader);
1141 return NS_ERROR_NOT_IMPLEMENTED;
1144 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1146 nsChannel *This = impl_from_nsIHttpChannel(iface);
1148 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1150 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1154 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1155 const nsACString *aRequestMethod)
1157 nsChannel *This = impl_from_nsIHttpChannel(iface);
1161 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1163 nsACString_GetData(aRequestMethod, &method);
1164 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1165 if(!strcasecmp(method, request_method_strings[i])) {
1166 This->request_method = i;
1171 ERR("Invalid method %s\n", debugstr_a(method));
1172 return NS_ERROR_UNEXPECTED;
1175 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1177 nsChannel *This = impl_from_nsIHttpChannel(iface);
1179 TRACE("(%p)->(%p)\n", This, aReferrer);
1182 nsIURI_AddRef(This->referrer);
1183 *aReferrer = This->referrer;
1187 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1189 nsChannel *This = impl_from_nsIHttpChannel(iface);
1191 TRACE("(%p)->(%p)\n", This, aReferrer);
1194 nsIURI_AddRef(aReferrer);
1196 nsIURI_Release(This->referrer);
1197 This->referrer = aReferrer;
1201 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1202 const nsACString *aHeader, nsACString *_retval)
1204 nsChannel *This = impl_from_nsIHttpChannel(iface);
1206 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1208 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1211 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1212 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1214 nsChannel *This = impl_from_nsIHttpChannel(iface);
1216 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1219 FIXME("aMerge not supported\n");
1221 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1224 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1225 nsIHttpHeaderVisitor *aVisitor)
1227 nsChannel *This = impl_from_nsIHttpChannel(iface);
1229 FIXME("(%p)->(%p)\n", This, aVisitor);
1231 return NS_ERROR_NOT_IMPLEMENTED;
1234 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1236 nsChannel *This = impl_from_nsIHttpChannel(iface);
1238 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1240 return NS_ERROR_NOT_IMPLEMENTED;
1243 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1245 nsChannel *This = impl_from_nsIHttpChannel(iface);
1247 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1249 return NS_ERROR_NOT_IMPLEMENTED;
1252 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1254 nsChannel *This = impl_from_nsIHttpChannel(iface);
1256 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1258 return NS_ERROR_NOT_IMPLEMENTED;
1261 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1263 nsChannel *This = impl_from_nsIHttpChannel(iface);
1265 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1267 return NS_ERROR_NOT_IMPLEMENTED;
1270 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1272 nsChannel *This = impl_from_nsIHttpChannel(iface);
1274 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1276 if(This->response_status) {
1277 *aResponseStatus = This->response_status;
1281 WARN("No response status\n");
1282 return NS_ERROR_UNEXPECTED;
1285 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1286 nsACString *aResponseStatusText)
1288 nsChannel *This = impl_from_nsIHttpChannel(iface);
1290 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1292 return NS_ERROR_NOT_IMPLEMENTED;
1295 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1296 cpp_bool *aRequestSucceeded)
1298 nsChannel *This = impl_from_nsIHttpChannel(iface);
1300 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1302 if(!This->response_status)
1303 return NS_ERROR_NOT_AVAILABLE;
1305 *aRequestSucceeded = This->response_status/100 == 2;
1310 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1311 const nsACString *header, nsACString *_retval)
1313 nsChannel *This = impl_from_nsIHttpChannel(iface);
1315 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1317 return get_channel_http_header(&This->response_headers, header, _retval);
1320 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1321 const nsACString *header, const nsACString *value, cpp_bool merge)
1323 nsChannel *This = impl_from_nsIHttpChannel(iface);
1325 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1327 return NS_ERROR_NOT_IMPLEMENTED;
1330 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1331 nsIHttpHeaderVisitor *aVisitor)
1333 nsChannel *This = impl_from_nsIHttpChannel(iface);
1335 TRACE("(%p)->(%p)\n", This, aVisitor);
1337 return visit_http_headers(&This->response_headers, aVisitor);
1340 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1342 nsChannel *This = impl_from_nsIHttpChannel(iface);
1343 http_header_t *header;
1345 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1346 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1348 TRACE("(%p)->(%p)\n", This, _retval);
1350 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1351 *_retval = header && !strcmpiW(header->data, no_storeW);
1355 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1357 nsChannel *This = impl_from_nsIHttpChannel(iface);
1359 FIXME("(%p)->(%p)\n", This, _retval);
1361 return NS_ERROR_NOT_IMPLEMENTED;
1364 static const nsIHttpChannelVtbl nsChannelVtbl = {
1365 nsChannel_QueryInterface,
1369 nsChannel_IsPending,
1370 nsChannel_GetStatus,
1374 nsChannel_GetLoadGroup,
1375 nsChannel_SetLoadGroup,
1376 nsChannel_GetLoadFlags,
1377 nsChannel_SetLoadFlags,
1378 nsChannel_GetOriginalURI,
1379 nsChannel_SetOriginalURI,
1383 nsChannel_GetNotificationCallbacks,
1384 nsChannel_SetNotificationCallbacks,
1385 nsChannel_GetSecurityInfo,
1386 nsChannel_GetContentType,
1387 nsChannel_SetContentType,
1388 nsChannel_GetContentCharset,
1389 nsChannel_SetContentCharset,
1390 nsChannel_GetContentLength,
1391 nsChannel_SetContentLength,
1393 nsChannel_AsyncOpen,
1394 nsChannel_GetContentDisposition,
1395 nsChannel_GetContentDispositionFilename,
1396 nsChannel_GetContentDispositionHeader,
1397 nsChannel_GetRequestMethod,
1398 nsChannel_SetRequestMethod,
1399 nsChannel_GetReferrer,
1400 nsChannel_SetReferrer,
1401 nsChannel_GetRequestHeader,
1402 nsChannel_SetRequestHeader,
1403 nsChannel_VisitRequestHeaders,
1404 nsChannel_GetAllowPipelining,
1405 nsChannel_SetAllowPipelining,
1406 nsChannel_GetRedirectionLimit,
1407 nsChannel_SetRedirectionLimit,
1408 nsChannel_GetResponseStatus,
1409 nsChannel_GetResponseStatusText,
1410 nsChannel_GetRequestSucceeded,
1411 nsChannel_GetResponseHeader,
1412 nsChannel_SetResponseHeader,
1413 nsChannel_VisitResponseHeaders,
1414 nsChannel_IsNoStoreResponse,
1415 nsChannel_IsNoCacheResponse
1418 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1420 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1423 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1426 nsChannel *This = impl_from_nsIUploadChannel(iface);
1427 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1430 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1432 nsChannel *This = impl_from_nsIUploadChannel(iface);
1433 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1436 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1438 nsChannel *This = impl_from_nsIUploadChannel(iface);
1439 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1442 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1443 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1445 nsChannel *This = impl_from_nsIUploadChannel(iface);
1446 const char *content_type;
1448 static const WCHAR content_typeW[] =
1449 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1451 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1453 This->post_data_contains_headers = TRUE;
1456 nsACString_GetData(aContentType, &content_type);
1460 ct = heap_strdupAtoW(content_type);
1462 return NS_ERROR_UNEXPECTED;
1464 set_http_header(&This->request_headers, content_typeW,
1465 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1467 This->post_data_contains_headers = FALSE;
1471 if(This->post_data_stream)
1472 nsIInputStream_Release(This->post_data_stream);
1474 if(aContentLength != -1)
1475 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1477 if(This->post_data_stream)
1478 nsIInputStream_Release(This->post_data_stream);
1479 This->post_data_stream = aStream;
1481 nsIInputStream_AddRef(aStream);
1483 This->request_method = METHOD_POST;
1487 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1488 nsIInputStream **aUploadStream)
1490 nsChannel *This = impl_from_nsIUploadChannel(iface);
1492 TRACE("(%p)->(%p)\n", This, aUploadStream);
1494 if(This->post_data_stream)
1495 nsIInputStream_AddRef(This->post_data_stream);
1497 *aUploadStream = This->post_data_stream;
1501 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1502 nsUploadChannel_QueryInterface,
1503 nsUploadChannel_AddRef,
1504 nsUploadChannel_Release,
1505 nsUploadChannel_SetUploadStream,
1506 nsUploadChannel_GetUploadStream
1509 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1511 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1514 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1517 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1518 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1521 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1523 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1524 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1527 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1529 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1530 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1533 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1535 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1537 FIXME("(%p)->()\n", This);
1539 return NS_ERROR_NOT_IMPLEMENTED;
1542 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1544 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1546 FIXME("(%p)->()\n", This);
1548 return NS_ERROR_NOT_IMPLEMENTED;
1551 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1553 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1555 FIXME("(%p)->()\n", This);
1557 return NS_ERROR_NOT_IMPLEMENTED;
1560 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1562 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1564 FIXME("(%p)->()\n", This);
1566 return NS_ERROR_NOT_IMPLEMENTED;
1569 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1571 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1573 FIXME("(%p)->()\n", This);
1575 return NS_ERROR_NOT_IMPLEMENTED;
1578 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1580 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1582 FIXME("(%p)->()\n", This);
1584 return NS_ERROR_NOT_IMPLEMENTED;
1587 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1589 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1591 FIXME("(%p)->()\n", This);
1593 return NS_ERROR_NOT_IMPLEMENTED;
1596 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1598 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1600 FIXME("(%p)->()\n", This);
1602 return NS_ERROR_NOT_IMPLEMENTED;
1605 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1607 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1609 FIXME("(%p)->(%p)\n", This, aCanceled);
1611 return NS_ERROR_NOT_IMPLEMENTED;
1614 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1616 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1618 FIXME("(%p)->(%p)\n", This, aCanceled);
1620 return NS_ERROR_NOT_IMPLEMENTED;
1623 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1625 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1627 FIXME("(%p)->(%x)\n", This, aCanceled);
1629 return NS_ERROR_NOT_IMPLEMENTED;
1632 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1634 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1636 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1638 return NS_ERROR_NOT_IMPLEMENTED;
1641 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, PRInt32 *aLocalPort)
1643 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1645 FIXME("(%p)->(%p)\n", This, aLocalPort);
1647 return NS_ERROR_NOT_IMPLEMENTED;
1650 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1652 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1654 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1656 return NS_ERROR_NOT_IMPLEMENTED;
1659 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, PRInt32 *aRemotePort)
1661 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1663 FIXME("(%p)->(%p)\n", This, aRemotePort);
1665 return NS_ERROR_NOT_IMPLEMENTED;
1668 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1670 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1672 FIXME("(%p)->(%p)\n", This, cacheKeys);
1674 return NS_ERROR_NOT_IMPLEMENTED;
1677 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1678 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1680 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1681 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1682 return NS_ERROR_NOT_IMPLEMENTED;
1685 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1687 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1688 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1689 return NS_ERROR_NOT_IMPLEMENTED;
1692 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1694 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1695 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1696 return NS_ERROR_NOT_IMPLEMENTED;
1699 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1700 nsHttpChannelInternal_QueryInterface,
1701 nsHttpChannelInternal_AddRef,
1702 nsHttpChannelInternal_Release,
1703 nsHttpChannelInternal_GetDocumentURI,
1704 nsHttpChannelInternal_SetDocumentURI,
1705 nsHttpChannelInternal_GetRequestVersion,
1706 nsHttpChannelInternal_GetResponseVersion,
1707 nsHttpChannelInternal_SetCookie,
1708 nsHttpChannelInternal_SetupFallbackChannel,
1709 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1710 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1711 nsHttpChannelInternal_GetCanceled,
1712 nsHttpChannelInternal_GetChannelIsForDownload,
1713 nsHttpChannelInternal_SetChannelIsForDownload,
1714 nsHttpChannelInternal_GetLocalAddress,
1715 nsHttpChannelInternal_GetLocalPort,
1716 nsHttpChannelInternal_GetRemoteAddress,
1717 nsHttpChannelInternal_GetRemotePort,
1718 nsHttpChannelInternal_SetCacheKeysRedirectChain,
1719 nsHttpChannelInternal_HTTPUpgrade,
1720 nsHttpChannelInternal_GetAllowSpdy,
1721 nsHttpChannelInternal_SetAllowSpdy
1725 static void invalidate_uri(nsWineURI *This)
1728 IUri_Release(This->uri);
1733 static BOOL ensure_uri_builder(nsWineURI *This)
1735 if(!This->is_mutable) {
1736 WARN("Not mutable URI\n");
1740 if(!This->uri_builder) {
1743 if(!ensure_uri(This))
1746 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1748 WARN("CreateIUriBuilder failed: %08x\n", hres);
1753 invalidate_uri(This);
1757 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1763 if(!ensure_uri(This))
1764 return NS_ERROR_UNEXPECTED;
1766 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1768 WARN("GetPropertyBSTR failed: %08x\n", hres);
1769 return NS_ERROR_UNEXPECTED;
1772 vala = heap_strdupWtoA(val);
1775 return NS_ERROR_OUT_OF_MEMORY;
1777 TRACE("ret %s\n", debugstr_a(vala));
1778 nsACString_SetData(ret, vala);
1783 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
1785 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
1788 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
1790 nsWineURI *This = impl_from_nsIFileURL(iface);
1794 if(IsEqualGUID(&IID_nsISupports, riid)) {
1795 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1796 *result = &This->nsIFileURL_iface;
1797 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1798 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1799 *result = &This->nsIFileURL_iface;
1800 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1801 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1802 *result = &This->nsIFileURL_iface;
1803 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
1804 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
1805 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
1806 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
1807 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
1808 *result = &This->nsIStandardURL_iface;
1809 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
1810 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
1811 *result = &This->nsIStandardURL_iface;
1812 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1813 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1818 nsIFileURL_AddRef(&This->nsIFileURL_iface);
1822 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1823 return NS_NOINTERFACE;
1826 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
1828 nsWineURI *This = impl_from_nsIFileURL(iface);
1829 LONG ref = InterlockedIncrement(&This->ref);
1831 TRACE("(%p) ref=%d\n", This, ref);
1836 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
1838 nsWineURI *This = impl_from_nsIFileURL(iface);
1839 LONG ref = InterlockedDecrement(&This->ref);
1841 TRACE("(%p) ref=%d\n", This, ref);
1844 if(This->window_ref)
1845 windowref_release(This->window_ref);
1847 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1849 IUri_Release(This->uri);
1856 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
1858 nsWineURI *This = impl_from_nsIFileURL(iface);
1860 TRACE("(%p)->(%p)\n", This, aSpec);
1862 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1865 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
1867 nsWineURI *This = impl_from_nsIFileURL(iface);
1873 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1875 if(!This->is_mutable)
1876 return NS_ERROR_UNEXPECTED;
1878 nsACString_GetData(aSpec, &speca);
1879 spec = heap_strdupAtoW(speca);
1881 return NS_ERROR_OUT_OF_MEMORY;
1883 hres = CreateUri(spec, 0, 0, &uri);
1886 WARN("CreateUri failed: %08x\n", hres);
1887 return NS_ERROR_FAILURE;
1890 invalidate_uri(This);
1891 if(This->uri_builder) {
1892 IUriBuilder_Release(This->uri_builder);
1893 This->uri_builder = NULL;
1900 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
1902 nsWineURI *This = impl_from_nsIFileURL(iface);
1903 FIXME("(%p)->(%p)\n", This, aPrePath);
1904 return NS_ERROR_NOT_IMPLEMENTED;
1907 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
1909 nsWineURI *This = impl_from_nsIFileURL(iface);
1913 TRACE("(%p)->(%p)\n", This, aScheme);
1915 if(!ensure_uri(This))
1916 return NS_ERROR_UNEXPECTED;
1918 hres = IUri_GetScheme(This->uri, &scheme);
1920 WARN("GetScheme failed: %08x\n", hres);
1921 return NS_ERROR_UNEXPECTED;
1924 if(scheme == URL_SCHEME_ABOUT) {
1925 nsACString_SetData(aScheme, "wine");
1929 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1932 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
1934 nsWineURI *This = impl_from_nsIFileURL(iface);
1935 const char *schemea;
1939 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1941 if(!ensure_uri_builder(This))
1942 return NS_ERROR_UNEXPECTED;
1944 nsACString_GetData(aScheme, &schemea);
1945 scheme = heap_strdupAtoW(schemea);
1947 return NS_ERROR_OUT_OF_MEMORY;
1949 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
1952 return NS_ERROR_UNEXPECTED;
1957 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
1959 nsWineURI *This = impl_from_nsIFileURL(iface);
1963 TRACE("(%p)->(%p)\n", This, aUserPass);
1965 if(!ensure_uri(This))
1966 return NS_ERROR_UNEXPECTED;
1968 hres = IUri_GetUserName(This->uri, &user);
1970 return NS_ERROR_FAILURE;
1972 hres = IUri_GetPassword(This->uri, &pass);
1974 SysFreeString(user);
1975 return NS_ERROR_FAILURE;
1978 if(*user || *pass) {
1979 FIXME("Construct user:pass string\n");
1981 nsACString_SetData(aUserPass, "");
1984 SysFreeString(user);
1985 SysFreeString(pass);
1989 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
1991 nsWineURI *This = impl_from_nsIFileURL(iface);
1992 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
1993 const char *user_pass;
1996 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
1998 if(!ensure_uri_builder(This))
1999 return NS_ERROR_UNEXPECTED;
2001 nsACString_GetData(aUserPass, &user_pass);
2005 buf = heap_strdupAtoW(user_pass);
2007 return NS_ERROR_OUT_OF_MEMORY;
2009 ptr = strchrW(buf, ':');
2012 }else if(ptr != buf) {
2022 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2024 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2027 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2030 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2032 nsWineURI *This = impl_from_nsIFileURL(iface);
2034 TRACE("(%p)->(%p)\n", This, aUsername);
2036 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2039 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2041 nsWineURI *This = impl_from_nsIFileURL(iface);
2046 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2048 if(!ensure_uri_builder(This))
2049 return NS_ERROR_UNEXPECTED;
2051 nsACString_GetData(aUsername, &usera);
2052 user = heap_strdupAtoW(usera);
2054 return NS_ERROR_OUT_OF_MEMORY;
2056 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2059 return NS_ERROR_UNEXPECTED;
2064 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2066 nsWineURI *This = impl_from_nsIFileURL(iface);
2068 TRACE("(%p)->(%p)\n", This, aPassword);
2070 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2073 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2075 nsWineURI *This = impl_from_nsIFileURL(iface);
2080 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2082 if(!ensure_uri_builder(This))
2083 return NS_ERROR_UNEXPECTED;
2085 nsACString_GetData(aPassword, &passa);
2086 pass = heap_strdupAtoW(passa);
2088 return NS_ERROR_OUT_OF_MEMORY;
2090 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2093 return NS_ERROR_UNEXPECTED;
2098 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2100 nsWineURI *This = impl_from_nsIFileURL(iface);
2106 TRACE("(%p)->(%p)\n", This, aHostPort);
2108 if(!ensure_uri(This))
2109 return NS_ERROR_UNEXPECTED;
2111 hres = IUri_GetAuthority(This->uri, &val);
2113 WARN("GetAuthority failed: %08x\n", hres);
2114 return NS_ERROR_UNEXPECTED;
2117 ptr = strchrW(val, '@');
2121 vala = heap_strdupWtoA(ptr);
2124 return NS_ERROR_OUT_OF_MEMORY;
2126 TRACE("ret %s\n", debugstr_a(vala));
2127 nsACString_SetData(aHostPort, vala);
2132 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2134 nsWineURI *This = impl_from_nsIFileURL(iface);
2136 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2138 /* Not implemented by Gecko */
2139 return NS_ERROR_NOT_IMPLEMENTED;
2142 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2144 nsWineURI *This = impl_from_nsIFileURL(iface);
2146 TRACE("(%p)->(%p)\n", This, aHost);
2148 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2151 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2153 nsWineURI *This = impl_from_nsIFileURL(iface);
2158 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2160 if(!ensure_uri_builder(This))
2161 return NS_ERROR_UNEXPECTED;
2163 nsACString_GetData(aHost, &hosta);
2164 host = heap_strdupAtoW(hosta);
2166 return NS_ERROR_OUT_OF_MEMORY;
2168 hres = IUriBuilder_SetHost(This->uri_builder, host);
2171 return NS_ERROR_UNEXPECTED;
2176 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, PRInt32 *aPort)
2178 nsWineURI *This = impl_from_nsIFileURL(iface);
2182 TRACE("(%p)->(%p)\n", This, aPort);
2184 if(!ensure_uri(This))
2185 return NS_ERROR_UNEXPECTED;
2187 hres = IUri_GetPort(This->uri, &port);
2189 WARN("GetPort failed: %08x\n", hres);
2190 return NS_ERROR_UNEXPECTED;
2193 *aPort = port ? port : -1;
2197 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, PRInt32 aPort)
2199 nsWineURI *This = impl_from_nsIFileURL(iface);
2202 TRACE("(%p)->(%d)\n", This, aPort);
2204 if(!ensure_uri_builder(This))
2205 return NS_ERROR_UNEXPECTED;
2207 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2208 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2211 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2213 nsWineURI *This = impl_from_nsIFileURL(iface);
2215 TRACE("(%p)->(%p)\n", This, aPath);
2217 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2220 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2222 nsWineURI *This = impl_from_nsIFileURL(iface);
2227 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2229 if(!ensure_uri_builder(This))
2230 return NS_ERROR_UNEXPECTED;
2232 nsACString_GetData(aPath, &patha);
2233 path = heap_strdupAtoW(patha);
2235 return NS_ERROR_OUT_OF_MEMORY;
2237 hres = IUriBuilder_SetPath(This->uri_builder, path);
2240 return NS_ERROR_UNEXPECTED;
2245 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2247 nsWineURI *This = impl_from_nsIFileURL(iface);
2248 nsWineURI *other_obj;
2252 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2254 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2255 if(NS_FAILED(nsres)) {
2256 TRACE("Could not get nsWineURI interface\n");
2261 if(ensure_uri(This) && ensure_uri(other_obj)) {
2264 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2265 if(SUCCEEDED(hres)) {
2269 nsres = NS_ERROR_FAILURE;
2272 nsres = NS_ERROR_UNEXPECTED;
2275 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2279 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2281 nsWineURI *This = impl_from_nsIFileURL(iface);
2282 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2286 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2288 if(!ensure_uri(This))
2289 return NS_ERROR_UNEXPECTED;
2291 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2293 return NS_ERROR_UNEXPECTED;
2295 MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2296 *_retval = !strcmpW(scheme_name, buf);
2297 SysFreeString(scheme_name);
2301 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2303 nsWineURI *This = impl_from_nsIFileURL(iface);
2304 nsWineURI *wine_uri;
2307 TRACE("(%p)->(%p)\n", This, _retval);
2309 if(!ensure_uri(This))
2310 return NS_ERROR_UNEXPECTED;
2312 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2313 if(NS_FAILED(nsres)) {
2314 WARN("create_nsuri failed: %08x\n", nsres);
2318 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2322 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2323 nsACString *_retval)
2325 nsWineURI *This = impl_from_nsIFileURL(iface);
2333 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2335 if(!ensure_uri(This))
2336 return NS_ERROR_UNEXPECTED;
2338 nsACString_GetData(aRelativePath, &patha);
2339 path = heap_strdupAtoW(patha);
2341 return NS_ERROR_OUT_OF_MEMORY;
2343 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2346 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2347 return NS_ERROR_FAILURE;
2350 hres = IUri_GetDisplayUri(new_uri, &ret);
2351 IUri_Release(new_uri);
2353 return NS_ERROR_FAILURE;
2355 reta = heap_strdupWtoA(ret);
2358 return NS_ERROR_OUT_OF_MEMORY;
2360 TRACE("returning %s\n", debugstr_a(reta));
2361 nsACString_SetData(_retval, reta);
2366 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2368 nsWineURI *This = impl_from_nsIFileURL(iface);
2370 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2372 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2375 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2377 nsWineURI *This = impl_from_nsIFileURL(iface);
2379 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2381 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2384 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2386 nsWineURI *This = impl_from_nsIFileURL(iface);
2387 FIXME("(%p)->(%p)\n", This, aOriginCharset);
2388 return NS_ERROR_NOT_IMPLEMENTED;
2391 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2393 nsWineURI *This = impl_from_nsIFileURL(iface);
2398 TRACE("(%p)->(%p)\n", This, aRef);
2400 if(!ensure_uri(This))
2401 return NS_ERROR_UNEXPECTED;
2403 hres = IUri_GetFragment(This->uri, &ref);
2405 return NS_ERROR_UNEXPECTED;
2407 refa = heap_strdupWtoA(ref);
2410 return NS_ERROR_OUT_OF_MEMORY;
2412 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2417 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2419 nsWineURI *This = impl_from_nsIFileURL(iface);
2424 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2426 if(!ensure_uri_builder(This))
2427 return NS_ERROR_UNEXPECTED;
2429 nsACString_GetData(aRef, &refa);
2430 ref = heap_strdupAtoW(refa);
2432 return NS_ERROR_OUT_OF_MEMORY;
2434 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2437 return NS_ERROR_UNEXPECTED;
2442 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2444 nsWineURI *This = impl_from_nsIFileURL(iface);
2445 nsWineURI *other_obj;
2448 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2450 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2451 if(NS_FAILED(nsres)) {
2452 TRACE("Could not get nsWineURI interface\n");
2457 if(ensure_uri(This) && ensure_uri(other_obj)) {
2458 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2461 nsres = NS_ERROR_UNEXPECTED;
2464 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2468 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2470 nsWineURI *This = impl_from_nsIFileURL(iface);
2471 nsWineURI *wine_uri;
2475 TRACE("(%p)->(%p)\n", This, _retval);
2477 if(!ensure_uri(This))
2478 return NS_ERROR_UNEXPECTED;
2480 uri = get_uri_nofrag(This->uri);
2482 return NS_ERROR_FAILURE;
2484 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2486 if(NS_FAILED(nsres)) {
2487 WARN("create_nsuri failed: %08x\n", nsres);
2491 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2495 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2497 nsWineURI *This = impl_from_nsIFileURL(iface);
2499 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2501 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2504 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2506 nsWineURI *This = impl_from_nsIFileURL(iface);
2510 TRACE("(%p)->(%p)\n", This, aHasRef);
2512 if(!ensure_uri(This))
2513 return NS_ERROR_UNEXPECTED;
2515 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2517 return NS_ERROR_FAILURE;
2523 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2525 nsWineURI *This = impl_from_nsIFileURL(iface);
2527 TRACE("(%p)->(%p)\n", This, aFilePath);
2529 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2532 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2534 nsWineURI *This = impl_from_nsIFileURL(iface);
2536 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2538 if(!This->is_mutable)
2539 return NS_ERROR_UNEXPECTED;
2541 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
2544 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
2546 nsWineURI *This = impl_from_nsIFileURL(iface);
2548 TRACE("(%p)->(%p)\n", This, aQuery);
2550 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2553 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
2555 nsWineURI *This = impl_from_nsIFileURL(iface);
2560 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2562 if(!ensure_uri_builder(This))
2563 return NS_ERROR_UNEXPECTED;
2565 nsACString_GetData(aQuery, &querya);
2566 query = heap_strdupAtoW(querya);
2568 return NS_ERROR_OUT_OF_MEMORY;
2570 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2573 return NS_ERROR_UNEXPECTED;
2578 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
2583 if(!ensure_uri(This))
2584 return NS_ERROR_UNEXPECTED;
2586 hres = IUri_GetPath(This->uri, path);
2588 return NS_ERROR_FAILURE;
2590 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
2591 if(*ptr == '/' || *ptr == '\\')
2596 ptr = strrchrW(ptr, '.');
2598 ptr = *path + SysStringLen(*path);
2605 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
2607 nsWineURI *This = impl_from_nsIFileURL(iface);
2612 TRACE("(%p)->(%p)\n", This, aDirectory);
2614 nsres = get_uri_path(This, &path, &file, NULL);
2615 if(NS_FAILED(nsres))
2618 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
2619 SysFreeString(path);
2623 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
2625 nsWineURI *This = impl_from_nsIFileURL(iface);
2627 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2629 /* Not implemented by Gecko */
2630 return NS_ERROR_NOT_IMPLEMENTED;
2633 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
2635 nsWineURI *This = impl_from_nsIFileURL(iface);
2640 TRACE("(%p)->(%p)\n", This, aFileName);
2642 nsres = get_uri_path(This, &path, &file, NULL);
2643 if(NS_FAILED(nsres))
2646 nsres = return_wstr_nsacstr(aFileName, file, -1);
2647 SysFreeString(path);
2651 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
2653 nsWineURI *This = impl_from_nsIFileURL(iface);
2654 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2655 return NS_ERROR_NOT_IMPLEMENTED;
2658 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
2660 nsWineURI *This = impl_from_nsIFileURL(iface);
2661 const WCHAR *file, *ext;
2665 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2667 nsres = get_uri_path(This, &path, &file, &ext);
2668 if(NS_FAILED(nsres))
2671 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
2672 SysFreeString(path);
2676 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
2678 nsWineURI *This = impl_from_nsIFileURL(iface);
2679 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2680 return NS_ERROR_NOT_IMPLEMENTED;
2683 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
2685 nsWineURI *This = impl_from_nsIFileURL(iface);
2687 TRACE("(%p)->(%p)\n", This, aFileExtension);
2689 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
2692 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
2694 nsWineURI *This = impl_from_nsIFileURL(iface);
2695 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2696 return NS_ERROR_NOT_IMPLEMENTED;
2699 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2701 nsWineURI *This = impl_from_nsIFileURL(iface);
2702 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2703 return NS_ERROR_NOT_IMPLEMENTED;
2706 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2708 nsWineURI *This = impl_from_nsIFileURL(iface);
2709 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2710 return NS_ERROR_NOT_IMPLEMENTED;
2713 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
2715 nsWineURI *This = impl_from_nsIFileURL(iface);
2716 WCHAR path[MAX_PATH];
2720 TRACE("(%p)->(%p)\n", This, aFile);
2722 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
2724 WARN("CoInternetParseIUri failed: %08x\n", hres);
2725 return NS_ERROR_FAILURE;
2728 return create_nsfile(path, aFile);
2731 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
2733 nsWineURI *This = impl_from_nsIFileURL(iface);
2734 FIXME("(%p)->(%p)\n", This, aFile);
2735 return NS_ERROR_NOT_IMPLEMENTED;
2738 static const nsIFileURLVtbl nsFileURLVtbl = {
2739 nsURI_QueryInterface,
2767 nsURI_GetOriginCharset,
2770 nsURI_EqualsExceptRef,
2771 nsURI_CloneIgnoreRef,
2772 nsURI_GetSpecIgnoringRef,
2782 nsURL_GetFileBaseName,
2783 nsURL_SetFileBaseName,
2784 nsURL_GetFileExtension,
2785 nsURL_SetFileExtension,
2786 nsURL_GetCommonBaseSpec,
2787 nsURL_GetRelativeSpec,
2792 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
2794 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
2797 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
2800 nsWineURI *This = impl_from_nsIStandardURL(iface);
2801 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
2804 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
2806 nsWineURI *This = impl_from_nsIStandardURL(iface);
2807 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
2810 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
2812 nsWineURI *This = impl_from_nsIStandardURL(iface);
2813 return nsIFileURL_Release(&This->nsIFileURL_iface);
2816 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
2818 nsWineURI *This = impl_from_nsIStandardURL(iface);
2820 TRACE("(%p)->(%p)\n", This, aMutable);
2822 *aMutable = This->is_mutable;
2826 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
2828 nsWineURI *This = impl_from_nsIStandardURL(iface);
2830 TRACE("(%p)->(%x)\n", This, aMutable);
2832 This->is_mutable = aMutable;
2836 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, PRUint32 aUrlType, PRInt32 aDefaultPort,
2837 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
2839 nsWineURI *This = impl_from_nsIStandardURL(iface);
2840 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
2841 return NS_ERROR_NOT_IMPLEMENTED;
2844 static const nsIStandardURLVtbl nsStandardURLVtbl = {
2845 nsStandardURL_QueryInterface,
2846 nsStandardURL_AddRef,
2847 nsStandardURL_Release,
2848 nsStandardURL_GetMutable,
2849 nsStandardURL_SetMutable,
2853 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container, nsWineURI **_retval)
2858 ret = heap_alloc_zero(sizeof(nsWineURI));
2860 return NS_ERROR_OUT_OF_MEMORY;
2862 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
2863 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
2865 ret->is_mutable = TRUE;
2867 set_uri_nscontainer(ret, container);
2868 set_uri_window(ret, window);
2873 hres = IUri_GetScheme(iuri, &ret->scheme);
2875 ret->scheme = URL_SCHEME_UNKNOWN;
2877 TRACE("retval=%p\n", ret);
2882 HRESULT create_doc_uri(HTMLOuterWindow *window, const WCHAR *url, nsWineURI **ret)
2889 hres = CreateUri(url, 0, 0, &iuri);
2893 nsres = create_nsuri(iuri, window, window->doc_obj->nscontainer, &uri);
2895 if(NS_FAILED(nsres))
2898 uri->is_doc_uri = TRUE;
2904 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2908 if(!ensure_uri(uri))
2909 return NS_ERROR_UNEXPECTED;
2911 channel = heap_alloc_zero(sizeof(nsChannel));
2913 return NS_ERROR_OUT_OF_MEMORY;
2915 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2916 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2917 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2919 channel->request_method = METHOD_GET;
2920 list_init(&channel->response_headers);
2921 list_init(&channel->request_headers);
2923 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
2930 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
2932 HTMLOuterWindow *window = NULL;
2939 hres = CreateUri(url, 0, 0, &iuri);
2943 if(orig_channel->uri->window_ref)
2944 window = orig_channel->uri->window_ref->window;
2945 nsres = create_nsuri(iuri, window, NULL, &uri);
2947 if(NS_FAILED(nsres))
2950 nsres = create_nschannel(uri, &channel);
2951 nsIFileURL_Release(&uri->nsIFileURL_iface);
2952 if(NS_FAILED(nsres))
2955 if(orig_channel->load_group) {
2956 nsILoadGroup_AddRef(orig_channel->load_group);
2957 channel->load_group = orig_channel->load_group;
2960 if(orig_channel->notif_callback) {
2961 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
2962 channel->notif_callback = orig_channel->notif_callback;
2965 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
2967 if(orig_channel->request_method == METHOD_POST)
2968 FIXME("unsupported POST method\n");
2970 if(orig_channel->original_uri) {
2971 nsIURI_AddRef(orig_channel->original_uri);
2972 channel->original_uri = orig_channel->original_uri;
2975 if(orig_channel->referrer) {
2976 nsIURI_AddRef(orig_channel->referrer);
2977 channel->referrer = orig_channel->referrer;
2985 nsIProtocolHandler nsIProtocolHandler_iface;
2989 nsIProtocolHandler *nshandler;
2990 } nsProtocolHandler;
2992 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
2994 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
2997 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3000 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3004 if(IsEqualGUID(&IID_nsISupports, riid)) {
3005 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3006 *result = &This->nsIProtocolHandler_iface;
3007 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3008 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3009 *result = &This->nsIProtocolHandler_iface;
3010 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3011 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3012 return NS_NOINTERFACE;
3016 nsISupports_AddRef((nsISupports*)*result);
3020 WARN("(%s %p)\n", debugstr_guid(riid), result);
3021 return NS_NOINTERFACE;
3024 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3026 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3027 LONG ref = InterlockedIncrement(&This->ref);
3029 TRACE("(%p) ref=%d\n", This, ref);
3034 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3036 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3037 LONG ref = InterlockedDecrement(&This->ref);
3039 TRACE("(%p) ref=%d\n", This, ref);
3043 nsIProtocolHandler_Release(This->nshandler);
3050 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3052 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3054 TRACE("(%p)->(%p)\n", This, aScheme);
3057 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3058 return NS_ERROR_NOT_IMPLEMENTED;
3061 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3062 PRInt32 *aDefaultPort)
3064 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3066 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3069 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3070 return NS_ERROR_NOT_IMPLEMENTED;
3073 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3074 PRUint32 *aProtocolFlags)
3076 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3078 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3081 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3082 return NS_ERROR_NOT_IMPLEMENTED;
3085 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3086 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3088 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3090 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3094 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3095 return NS_ERROR_NOT_IMPLEMENTED;
3098 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3099 nsIURI *aURI, nsIChannel **_retval)
3101 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3103 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3106 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3107 return NS_ERROR_NOT_IMPLEMENTED;
3110 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3111 PRInt32 port, const char *scheme, cpp_bool *_retval)
3113 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3115 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3118 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3119 return NS_ERROR_NOT_IMPLEMENTED;
3122 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3123 nsProtocolHandler_QueryInterface,
3124 nsProtocolHandler_AddRef,
3125 nsProtocolHandler_Release,
3126 nsProtocolHandler_GetScheme,
3127 nsProtocolHandler_GetDefaultPort,
3128 nsProtocolHandler_GetProtocolFlags,
3129 nsProtocolHandler_NewURI,
3130 nsProtocolHandler_NewChannel,
3131 nsProtocolHandler_AllowPort
3134 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
3136 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
3141 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
3146 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
3147 nsIProtocolHandler **_retval)
3149 nsIExternalProtocolHandler *nsexthandler;
3150 nsIProtocolHandler *nshandler;
3151 nsProtocolHandler *ret;
3154 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3156 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
3157 if(NS_FAILED(nsres)) {
3158 WARN("GetProtocolHandler failed: %08x\n", nsres);
3162 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
3163 (void**)&nsexthandler);
3164 if(NS_FAILED(nsres)) {
3165 *_retval = nshandler;
3169 nsIExternalProtocolHandler_Release(nsexthandler);
3171 ret = heap_alloc(sizeof(nsProtocolHandler));
3173 return NS_ERROR_OUT_OF_MEMORY;
3175 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3177 ret->nshandler = nshandler;
3178 *_retval = &ret->nsIProtocolHandler_iface;
3180 TRACE("return %p\n", *_retval);
3184 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
3187 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3188 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
3191 static BOOL is_gecko_special_uri(const char *spec)
3193 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3196 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3197 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3201 if(!strncasecmp(spec, "file:", 5)) {
3202 const char *ptr = spec+5;
3205 return is_gecko_path(ptr);
3211 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
3212 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3214 nsWineURI *wine_uri, *base_wine_uri = NULL;
3215 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3216 HTMLOuterWindow *window = NULL;
3217 const char *spec = NULL;
3222 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3225 nsACString_GetData(aSpec, &spec);
3226 if(is_gecko_special_uri(spec))
3227 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3229 if(!strncmp(spec, "wine:", 5))
3233 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3234 if(NS_SUCCEEDED(nsres)) {
3235 if(!ensure_uri(base_wine_uri))
3236 return NS_ERROR_UNEXPECTED;
3237 if(base_wine_uri->window_ref)
3238 window = base_wine_uri->window_ref->window;
3240 WARN("Could not get base nsWineURI: %08x\n", nsres);
3244 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3247 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
3250 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
3252 hres = CreateUri(new_spec, 0, 0, &urlmon_uri);
3254 WARN("CreateUri failed: %08x\n", hres);
3258 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3260 nsres = create_nsuri(urlmon_uri, window, NULL, &wine_uri);
3261 IUri_Release(urlmon_uri);
3263 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3264 if(NS_FAILED(nsres))
3267 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3271 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
3274 TRACE("(%p %p)\n", aFile, _retval);
3275 return nsIIOService_NewFileURI(nsio, aFile, _retval);
3278 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
3279 nsIChannel **_retval)
3281 nsWineURI *wine_uri;
3285 TRACE("(%p %p)\n", aURI, _retval);
3287 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3288 if(NS_FAILED(nsres)) {
3289 TRACE("Could not get nsWineURI: %08x\n", nsres);
3290 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
3293 nsres = create_nschannel(wine_uri, &ret);
3294 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3295 if(NS_FAILED(nsres))
3298 nsIURI_AddRef(aURI);
3299 ret->original_uri = aURI;
3301 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3305 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
3306 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
3308 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
3309 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3312 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, cpp_bool *aOffline)
3314 TRACE("(%p)\n", aOffline);
3315 return nsIIOService_GetOffline(nsio, aOffline);
3318 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, cpp_bool aOffline)
3320 TRACE("(%x)\n", aOffline);
3321 return nsIIOService_SetOffline(nsio, aOffline);
3324 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
3325 const char *aScheme, cpp_bool *_retval)
3327 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
3328 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
3331 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
3332 nsACString * _retval)
3334 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
3335 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
3338 static const nsIIOServiceVtbl nsIOServiceVtbl = {
3339 nsIOService_QueryInterface,
3341 nsIOService_Release,
3342 nsIOService_GetProtocolHandler,
3343 nsIOService_GetProtocolFlags,
3345 nsIOService_NewFileURI,
3346 nsIOService_NewChannelFromURI,
3347 nsIOService_NewChannel,
3348 nsIOService_GetOffline,
3349 nsIOService_SetOffline,
3350 nsIOService_AllowPort,
3351 nsIOService_ExtractScheme
3354 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3356 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3359 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3362 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3367 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3372 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3373 nsACString *aCharset, cpp_bool *aHadCharset, nsACString *aContentType)
3375 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3377 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3380 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, cpp_bool *_retval)
3384 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3387 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, cpp_bool *_retval)
3389 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3391 if(aFlags == (1<<11)) {
3396 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3399 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3401 TRACE("(%p %p)\n", aURI, _retval);
3403 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3406 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3408 TRACE("(%p %p)\n", aURI, _retval);
3410 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3413 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3414 PRUint32 aEscapeType, nsACString *_retval)
3416 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3418 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3421 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
3422 nsACString *_retval)
3424 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3426 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3429 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3430 PRUint32 aFlags, nsACString *_retval)
3432 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3434 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3437 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3438 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, cpp_bool *_retval)
3440 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3441 aCharsetEnd, _retval);
3443 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3446 static const nsINetUtilVtbl nsNetUtilVtbl = {
3447 nsNetUtil_QueryInterface,
3450 nsNetUtil_ParseContentType,
3451 nsNetUtil_ProtocolHasFlags,
3452 nsNetUtil_URIChainHasFlags,
3453 nsNetUtil_ToImmutableURI,
3454 nsNetUtil_NewSimpleNestedURI,
3455 nsNetUtil_EscapeString,
3456 nsNetUtil_EscapeURL,
3457 nsNetUtil_UnescapeString,
3458 nsNetUtil_ExtractCharsetFromContentType
3461 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3463 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3468 if(IsEqualGUID(&IID_nsISupports, riid))
3469 *result = &nsIOService;
3470 else if(IsEqualGUID(&IID_nsIIOService, riid))
3471 *result = &nsIOService;
3472 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3473 *result = &nsNetUtil;
3476 nsISupports_AddRef((nsISupports*)*result);
3480 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3481 return NS_NOINTERFACE;
3484 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3489 if(IsEqualGUID(&IID_nsISupports, riid)) {
3490 TRACE("(IID_nsISupports %p)\n", result);
3492 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3493 TRACE("(IID_nsIFactory %p)\n", result);
3498 nsIFactory_AddRef(iface);
3502 WARN("(%s %p)\n", debugstr_guid(riid), result);
3503 return NS_NOINTERFACE;
3506 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3511 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3516 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3517 nsISupports *aOuter, const nsIID *iid, void **result)
3519 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3522 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
3524 WARN("(%x)\n", lock);
3528 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3529 nsIOServiceFactory_QueryInterface,
3530 nsIOServiceFactory_AddRef,
3531 nsIOServiceFactory_Release,
3532 nsIOServiceFactory_CreateInstance,
3533 nsIOServiceFactory_LockFactory
3536 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3538 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3540 OLECHAR *new_url = NULL;
3545 if(!doc->hostui || !ensure_uri(uri))
3548 hres = IUri_GetDisplayUri(uri->uri, &url);
3552 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3553 if(hres == S_OK && new_url) {
3554 if(strcmpW(url, new_url)) {
3555 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3558 CoTaskMemFree(new_url);
3565 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
3567 nsWineURI *wine_uri;
3572 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3573 if(NS_FAILED(nsres)) {
3574 WARN("Could not get nsWineURI: %08x\n", nsres);
3575 return NS_ERROR_NOT_IMPLEMENTED;
3578 if(!wine_uri->is_doc_uri) {
3579 wine_uri->is_doc_uri = TRUE;
3581 if(!wine_uri->container) {
3582 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3583 wine_uri->container = nscontainer;
3586 if(nscontainer->doc)
3587 *_retval = translate_url(nscontainer->doc, wine_uri);
3590 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3594 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3596 nsIFactory *old_factory = NULL;
3599 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3600 &IID_nsIFactory, (void**)&old_factory);
3601 if(NS_FAILED(nsres)) {
3602 ERR("Could not get factory: %08x\n", nsres);
3606 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3607 if(NS_FAILED(nsres)) {
3608 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3609 nsIFactory_Release(old_factory);
3613 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3614 if(NS_FAILED(nsres)) {
3615 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3616 nsIIOService_Release(nsio);
3620 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3621 nsIFactory_Release(old_factory);
3622 if(NS_FAILED(nsres))
3623 ERR("UnregisterFactory failed: %08x\n", nsres);
3625 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3626 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3627 if(NS_FAILED(nsres))
3628 ERR("RegisterFactory failed: %08x\n", nsres);
3631 void release_nsio(void)
3634 nsINetUtil_Release(net_util);
3639 nsIIOService_Release(nsio);