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;
72 static BOOL ensure_uri(nsWineURI *This)
76 assert(This->uri || This->uri_builder);
79 hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
81 WARN("CreateUriSimple failed: %08x\n", hres);
89 IUri *nsuri_get_uri(nsWineURI *nsuri)
91 if(!ensure_uri(nsuri))
94 IUri_AddRef(nsuri->uri);
98 IUri *get_uri_nofrag(IUri *uri)
100 IUriBuilder *uri_builder;
105 hres = IUri_HasProperty(uri, Uri_PROPERTY_FRAGMENT, &b);
106 if(SUCCEEDED(hres) && !b) {
111 hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
115 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_FRAGMENT);
117 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &ret);
118 IUriBuilder_Release(uri_builder);
125 static BOOL compare_ignoring_frag(IUri *uri1, IUri *uri2)
127 IUri *uri_nofrag1, *uri_nofrag2;
130 uri_nofrag1 = get_uri_nofrag(uri1);
134 uri_nofrag2 = get_uri_nofrag(uri2);
136 IUri_IsEqual(uri_nofrag1, uri_nofrag2, &ret);
137 IUri_Release(uri_nofrag2);
140 IUri_Release(uri_nofrag1);
144 static nsresult create_nsuri(IUri*,HTMLOuterWindow*,NSContainer*,const char*,nsWineURI**);
146 static const char *debugstr_nsacstr(const nsACString *nsstr)
150 nsACString_GetData(nsstr, &data);
151 return debugstr_a(data);
154 static nsresult return_wstr_nsacstr(nsACString *ret_str, const WCHAR *str, int len)
159 TRACE("returning %s\n", debugstr_wn(str, len));
162 nsACString_SetData(ret_str, "");
166 lena = WideCharToMultiByte(CP_UTF8, 0, str, len, NULL, 0, NULL, NULL);
167 stra = heap_alloc(lena+1);
169 return NS_ERROR_OUT_OF_MEMORY;
171 WideCharToMultiByte(CP_UTF8, 0, str, len, stra, lena, NULL, NULL);
174 nsACString_SetData(ret_str, stra);
179 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
181 const WCHAR *ptr = nsuri;
183 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
185 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
186 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
188 if(*ptr || ret_empty) {
189 *ret = SysAllocString(ptr);
191 return E_OUTOFMEMORY;
196 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
200 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
202 IOleCommandTarget *cmdtrg = NULL;
205 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
206 if(SUCCEEDED(hres)) {
207 VARIANT varUrl, varRes;
209 V_VT(&varUrl) = VT_BSTR;
210 V_BSTR(&varUrl) = url;
211 V_VT(&varRes) = VT_BOOL;
213 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
215 IOleCommandTarget_Release(cmdtrg);
217 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
218 TRACE("got VARIANT_FALSE, do not load\n");
226 static nsresult before_async_open(nsChannel *channel, NSContainer *container, BOOL *cancel)
228 HTMLDocumentObj *doc = container->doc;
237 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
239 return NS_ERROR_FAILURE;
241 if(!exec_shldocvw_67(doc, display_uri)) {
242 SysFreeString(display_uri);
247 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, 0, cancel);
248 SysFreeString(display_uri);
254 HRESULT load_nsuri(HTMLOuterWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
256 nsIWebNavigation *web_navigation;
257 nsIDocShell *doc_shell;
258 HTMLDocumentNode *doc;
261 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
262 if(NS_FAILED(nsres)) {
263 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
267 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
268 nsIWebNavigation_Release(web_navigation);
269 if(NS_FAILED(nsres)) {
270 ERR("Could not get nsIDocShell: %08x\n", nsres);
274 uri->channel_bsc = channelbsc;
275 doc = window->base.inner_window->doc;
276 doc->skip_mutation_notif = TRUE;
277 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIFileURL_iface, NULL, flags, FALSE);
278 if(doc == window->base.inner_window->doc)
279 doc->skip_mutation_notif = FALSE;
280 uri->channel_bsc = NULL;
281 nsIDocShell_Release(doc_shell);
282 if(NS_FAILED(nsres)) {
283 WARN("LoadURI failed: %08x\n", nsres);
290 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
292 if(This->container) {
293 if(This->container == nscontainer)
295 TRACE("Changing %p -> %p\n", This->container, nscontainer);
296 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
300 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
301 This->container = nscontainer;
304 static void set_uri_window(nsWineURI *This, HTMLOuterWindow *window)
306 if(This->window_ref) {
307 if(This->window_ref->window == window)
309 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
310 windowref_release(This->window_ref);
314 windowref_addref(window->window_ref);
315 This->window_ref = window->window_ref;
318 set_uri_nscontainer(This, window->doc_obj->nscontainer);
320 This->window_ref = NULL;
324 static inline BOOL is_http_channel(nsChannel *This)
326 return This->uri->scheme == URL_SCHEME_HTTP || This->uri->scheme == URL_SCHEME_HTTPS;
329 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
333 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
334 if(!strcmpiW(iter->header, name))
341 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
344 const char *header_namea;
345 http_header_t *header;
349 nsACString_GetData(header_name_str, &header_namea);
350 header_name = heap_strdupAtoW(header_namea);
352 return NS_ERROR_UNEXPECTED;
354 header = find_http_header(headers, header_name, strlenW(header_name));
355 heap_free(header_name);
357 return NS_ERROR_NOT_AVAILABLE;
359 data = heap_strdupWtoA(header->data);
361 return NS_ERROR_UNEXPECTED;
363 TRACE("%s -> %s\n", debugstr_a(header_namea), debugstr_a(data));
364 nsACString_SetData(_retval, data);
369 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
370 const WCHAR *value, int value_len)
372 http_header_t *header;
374 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
376 header = find_http_header(headers, name, name_len);
380 new_data = heap_strndupW(value, value_len);
382 return E_OUTOFMEMORY;
384 heap_free(header->data);
385 header->data = new_data;
387 header = heap_alloc(sizeof(http_header_t));
389 return E_OUTOFMEMORY;
391 header->header = heap_strndupW(name, name_len);
392 header->data = heap_strndupW(value, value_len);
393 if(!header->header || !header->data) {
394 heap_free(header->header);
395 heap_free(header->data);
397 return E_OUTOFMEMORY;
400 list_add_tail(headers, &header->entry);
406 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
407 const nsACString *value_str)
409 const char *namea, *valuea;
413 nsACString_GetData(name_str, &namea);
414 name = heap_strdupAtoW(namea);
416 return NS_ERROR_UNEXPECTED;
418 nsACString_GetData(value_str, &valuea);
419 value = heap_strdupAtoW(valuea);
422 return NS_ERROR_UNEXPECTED;
425 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
429 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
432 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
434 nsACString header_str, value_str;
435 char *header, *value;
439 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
440 header = heap_strdupWtoA(iter->header);
442 return NS_ERROR_OUT_OF_MEMORY;
444 value = heap_strdupWtoA(iter->data);
447 return NS_ERROR_OUT_OF_MEMORY;
450 nsACString_InitDepend(&header_str, header);
451 nsACString_InitDepend(&value_str, value);
452 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
453 nsACString_Finish(&header_str);
454 nsACString_Finish(&value_str);
464 static void free_http_headers(struct list *list)
466 http_header_t *iter, *iter_next;
468 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
469 list_remove(&iter->entry);
470 heap_free(iter->header);
471 heap_free(iter->data);
476 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
478 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
481 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
483 nsChannel *This = impl_from_nsIHttpChannel(iface);
485 if(IsEqualGUID(&IID_nsISupports, riid)) {
486 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
487 *result = &This->nsIHttpChannel_iface;
488 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
489 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
490 *result = &This->nsIHttpChannel_iface;
491 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
492 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
493 *result = &This->nsIHttpChannel_iface;
494 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
495 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
496 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
497 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
498 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
499 *result = &This->nsIUploadChannel_iface;
500 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
501 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
502 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
504 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
509 nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
513 return NS_NOINTERFACE;
516 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
518 nsChannel *This = impl_from_nsIHttpChannel(iface);
519 nsrefcnt ref = InterlockedIncrement(&This->ref);
521 TRACE("(%p) ref=%d\n", This, ref);
526 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
528 nsChannel *This = impl_from_nsIHttpChannel(iface);
529 LONG ref = InterlockedDecrement(&This->ref);
532 nsIFileURL_Release(&This->uri->nsIFileURL_iface);
534 nsISupports_Release(This->owner);
535 if(This->post_data_stream)
536 nsIInputStream_Release(This->post_data_stream);
538 nsILoadGroup_Release(This->load_group);
539 if(This->notif_callback)
540 nsIInterfaceRequestor_Release(This->notif_callback);
541 if(This->original_uri)
542 nsIURI_Release(This->original_uri);
544 nsIURI_Release(This->referrer);
546 free_http_headers(&This->response_headers);
547 free_http_headers(&This->request_headers);
549 heap_free(This->content_type);
550 heap_free(This->charset);
557 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
559 nsChannel *This = impl_from_nsIHttpChannel(iface);
561 TRACE("(%p)->(%p)\n", This, aName);
563 return nsIFileURL_GetSpec(&This->uri->nsIFileURL_iface, aName);
566 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, cpp_bool *_retval)
568 nsChannel *This = impl_from_nsIHttpChannel(iface);
570 FIXME("(%p)->(%p)\n", This, _retval);
572 return NS_ERROR_NOT_IMPLEMENTED;
575 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
577 nsChannel *This = impl_from_nsIHttpChannel(iface);
579 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
581 return *aStatus = NS_OK;
584 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
586 nsChannel *This = impl_from_nsIHttpChannel(iface);
588 FIXME("(%p)->(%08x)\n", This, aStatus);
590 return NS_ERROR_NOT_IMPLEMENTED;
593 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
595 nsChannel *This = impl_from_nsIHttpChannel(iface);
597 FIXME("(%p)\n", This);
599 return NS_ERROR_NOT_IMPLEMENTED;
602 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
604 nsChannel *This = impl_from_nsIHttpChannel(iface);
606 FIXME("(%p)\n", This);
608 return NS_ERROR_NOT_IMPLEMENTED;
611 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
613 nsChannel *This = impl_from_nsIHttpChannel(iface);
615 TRACE("(%p)->(%p)\n", This, aLoadGroup);
618 nsILoadGroup_AddRef(This->load_group);
620 *aLoadGroup = This->load_group;
624 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
626 nsChannel *This = impl_from_nsIHttpChannel(iface);
628 TRACE("(%p)->(%p)\n", This, aLoadGroup);
631 nsILoadGroup_Release(This->load_group);
633 nsILoadGroup_AddRef(aLoadGroup);
634 This->load_group = aLoadGroup;
639 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
641 nsChannel *This = impl_from_nsIHttpChannel(iface);
643 TRACE("(%p)->(%p)\n", This, aLoadFlags);
645 *aLoadFlags = This->load_flags;
649 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
651 nsChannel *This = impl_from_nsIHttpChannel(iface);
653 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
655 This->load_flags = aLoadFlags;
659 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
661 nsChannel *This = impl_from_nsIHttpChannel(iface);
663 TRACE("(%p)->(%p)\n", This, aOriginalURI);
665 if(This->original_uri)
666 nsIURI_AddRef(This->original_uri);
668 *aOriginalURI = This->original_uri;
672 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
674 nsChannel *This = impl_from_nsIHttpChannel(iface);
676 TRACE("(%p)->(%p)\n", This, aOriginalURI);
678 if(This->original_uri)
679 nsIURI_Release(This->original_uri);
681 nsIURI_AddRef(aOriginalURI);
682 This->original_uri = aOriginalURI;
686 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
688 nsChannel *This = impl_from_nsIHttpChannel(iface);
690 TRACE("(%p)->(%p)\n", This, aURI);
692 nsIFileURL_AddRef(&This->uri->nsIFileURL_iface);
693 *aURI = (nsIURI*)This->uri;
698 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
700 nsChannel *This = impl_from_nsIHttpChannel(iface);
702 TRACE("(%p)->(%p)\n", This, aOwner);
705 nsISupports_AddRef(This->owner);
706 *aOwner = This->owner;
711 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
713 nsChannel *This = impl_from_nsIHttpChannel(iface);
715 TRACE("(%p)->(%p)\n", This, aOwner);
718 nsISupports_AddRef(aOwner);
720 nsISupports_Release(This->owner);
721 This->owner = aOwner;
726 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
727 nsIInterfaceRequestor **aNotificationCallbacks)
729 nsChannel *This = impl_from_nsIHttpChannel(iface);
731 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
733 if(This->notif_callback)
734 nsIInterfaceRequestor_AddRef(This->notif_callback);
735 *aNotificationCallbacks = This->notif_callback;
740 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
741 nsIInterfaceRequestor *aNotificationCallbacks)
743 nsChannel *This = impl_from_nsIHttpChannel(iface);
745 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
747 if(This->notif_callback)
748 nsIInterfaceRequestor_Release(This->notif_callback);
749 if(aNotificationCallbacks)
750 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
752 This->notif_callback = aNotificationCallbacks;
757 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
759 nsChannel *This = impl_from_nsIHttpChannel(iface);
761 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
763 return NS_ERROR_NOT_IMPLEMENTED;
766 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
768 nsChannel *This = impl_from_nsIHttpChannel(iface);
770 TRACE("(%p)->(%p)\n", This, aContentType);
772 if(This->content_type) {
773 nsACString_SetData(aContentType, This->content_type);
777 if(This->uri->is_doc_uri) {
778 WARN("Document channel with no MIME set. Assuming text/html\n");
779 nsACString_SetData(aContentType, "text/html");
783 WARN("unknown type\n");
784 return NS_ERROR_FAILURE;
787 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
788 const nsACString *aContentType)
790 nsChannel *This = impl_from_nsIHttpChannel(iface);
791 const char *content_type;
793 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
795 nsACString_GetData(aContentType, &content_type);
796 heap_free(This->content_type);
797 This->content_type = heap_strdupA(content_type);
802 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
803 nsACString *aContentCharset)
805 nsChannel *This = impl_from_nsIHttpChannel(iface);
807 TRACE("(%p)->(%p)\n", This, aContentCharset);
810 nsACString_SetData(aContentCharset, This->charset);
814 nsACString_SetData(aContentCharset, "");
818 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
819 const nsACString *aContentCharset)
821 nsChannel *This = impl_from_nsIHttpChannel(iface);
825 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
827 nsACString_GetData(aContentCharset, &data);
828 charset = heap_strdupA(data);
830 return NS_ERROR_OUT_OF_MEMORY;
832 heap_free(This->charset);
833 This->charset = charset;
837 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
839 nsChannel *This = impl_from_nsIHttpChannel(iface);
841 FIXME("(%p)->(%p)\n", This, aContentLength);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
848 nsChannel *This = impl_from_nsIHttpChannel(iface);
850 FIXME("(%p)->(%d)\n", This, aContentLength);
852 return NS_ERROR_NOT_IMPLEMENTED;
855 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
857 nsChannel *This = impl_from_nsIHttpChannel(iface);
859 FIXME("(%p)->(%p)\n", This, _retval);
861 return NS_ERROR_NOT_IMPLEMENTED;
864 static HTMLOuterWindow *get_window_from_load_group(nsChannel *This)
866 HTMLOuterWindow *window;
873 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
874 if(NS_FAILED(nsres)) {
875 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
882 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
883 nsIRequest_Release(req);
884 if(NS_FAILED(nsres)) {
885 WARN("Could not get nsIChannel interface: %08x\n", nsres);
889 nsres = nsIChannel_GetURI(channel, &uri);
890 nsIChannel_Release(channel);
891 if(NS_FAILED(nsres)) {
892 ERR("GetURI failed: %08x\n", nsres);
896 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
898 if(NS_FAILED(nsres)) {
899 TRACE("Could not get nsWineURI: %08x\n", nsres);
903 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
905 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
906 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
911 static HTMLOuterWindow *get_channel_window(nsChannel *This)
913 nsIWebProgress *web_progress;
914 nsIDOMWindow *nswindow;
915 HTMLOuterWindow *window;
918 if(This->load_group) {
919 nsIRequestObserver *req_observer;
921 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
922 if(NS_FAILED(nsres) || !req_observer) {
923 ERR("GetGroupObserver failed: %08x\n", nsres);
927 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
928 nsIRequestObserver_Release(req_observer);
929 if(NS_FAILED(nsres)) {
930 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
933 }else if(This->notif_callback) {
934 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
935 if(NS_FAILED(nsres)) {
936 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
940 ERR("no load group nor notif callback\n");
944 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
945 nsIWebProgress_Release(web_progress);
946 if(NS_FAILED(nsres) || !nswindow) {
947 ERR("GetDOMWindow failed: %08x\n", nsres);
951 window = nswindow_to_window(nswindow);
952 nsIDOMWindow_Release(nswindow);
955 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
957 FIXME("NULL window for %p\n", nswindow);
963 HTMLInnerWindow *window;
964 nsChannelBSC *bscallback;
965 } start_binding_task_t;
967 static void start_binding_proc(task_t *_task)
969 start_binding_task_t *task = (start_binding_task_t*)_task;
971 start_binding(task->window, (BSCallback*)task->bscallback, NULL);
974 static void start_binding_task_destr(task_t *_task)
976 start_binding_task_t *task = (start_binding_task_t*)_task;
978 IBindStatusCallback_Release(&task->bscallback->bsc.IBindStatusCallback_iface);
982 static nsresult async_open(nsChannel *This, HTMLOuterWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
983 nsISupports *context)
985 nsChannelBSC *bscallback;
986 IMoniker *mon = NULL;
989 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
991 WARN("CreateURLMoniker failed: %08x\n", hres);
992 return NS_ERROR_UNEXPECTED;
996 set_current_mon(window, mon, BINDING_NAVIGATED);
998 hres = create_channelbsc(mon, NULL, NULL, 0, is_doc_channel, &bscallback);
999 IMoniker_Release(mon);
1001 return NS_ERROR_UNEXPECTED;
1003 channelbsc_set_channel(bscallback, This, listener, context);
1005 if(is_doc_channel) {
1006 hres = create_pending_window(window, bscallback);
1008 async_start_doc_binding(window, window->pending_window);
1009 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1011 return NS_ERROR_UNEXPECTED;
1013 start_binding_task_t *task;
1015 task = heap_alloc(sizeof(start_binding_task_t));
1017 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1018 return NS_ERROR_OUT_OF_MEMORY;
1021 task->window = window->base.inner_window;
1022 task->bscallback = bscallback;
1023 hres = push_task(&task->header, start_binding_proc, start_binding_task_destr, window->base.inner_window->task_magic);
1025 return NS_ERROR_OUT_OF_MEMORY;
1031 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
1032 nsISupports *aContext)
1034 nsChannel *This = impl_from_nsIHttpChannel(iface);
1035 HTMLOuterWindow *window = NULL;
1036 BOOL cancel = FALSE;
1037 nsresult nsres = NS_OK;
1039 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
1041 if(!ensure_uri(This->uri))
1042 return NS_ERROR_FAILURE;
1044 if(TRACE_ON(mshtml)) {
1048 hres = IUri_GetDisplayUri(This->uri->uri, &uri_str);
1049 if(SUCCEEDED(hres)) {
1050 TRACE("opening %s\n", debugstr_w(uri_str));
1051 SysFreeString(uri_str);
1053 WARN("GetDisplayUri failed: %08x\n", hres);
1057 if(This->uri->is_doc_uri) {
1058 window = get_channel_window(This);
1060 set_uri_window(This->uri, window);
1061 }else if(This->uri->container) {
1064 /* nscontainer->doc should be NULL which means navigation to a new window */
1065 if(This->uri->container->doc)
1066 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
1068 nsres = before_async_open(This, This->uri->container, &b);
1069 if(NS_FAILED(nsres))
1072 FIXME("Navigation not cancelled\n");
1073 return NS_ERROR_UNEXPECTED;
1078 if(This->uri->window_ref && This->uri->window_ref->window) {
1079 window = This->uri->window_ref->window;
1080 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1082 /* FIXME: Analyze removing get_window_from_load_group call */
1083 if(This->load_group)
1084 window = get_window_from_load_group(This);
1086 window = get_channel_window(This);
1088 set_uri_window(This->uri, window);
1093 ERR("window = NULL\n");
1094 return NS_ERROR_UNEXPECTED;
1097 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1098 if(This->uri->channel_bsc) {
1099 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1101 if(window->doc_obj->mime) {
1102 heap_free(This->content_type);
1103 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1108 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
1109 if(NS_SUCCEEDED(nsres) && cancel) {
1110 TRACE("canceled\n");
1111 nsres = NS_BINDING_ABORTED;
1117 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1119 if(NS_SUCCEEDED(nsres) && This->load_group) {
1120 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1122 if(NS_FAILED(nsres))
1123 ERR("AddRequest failed: %08x\n", nsres);
1126 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
1130 static nsresult NSAPI nsChannel_GetContentDisposition(nsIHttpChannel *iface, PRUint32 *aContentDisposition)
1132 nsChannel *This = impl_from_nsIHttpChannel(iface);
1133 FIXME("(%p)->(%p)\n", This, aContentDisposition);
1134 return NS_ERROR_NOT_IMPLEMENTED;
1137 static nsresult NSAPI nsChannel_GetContentDispositionFilename(nsIHttpChannel *iface, nsAString *aContentDispositionFilename)
1139 nsChannel *This = impl_from_nsIHttpChannel(iface);
1140 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1141 return NS_ERROR_NOT_IMPLEMENTED;
1144 static nsresult NSAPI nsChannel_GetContentDispositionHeader(nsIHttpChannel *iface, nsACString *aContentDispositionHeader)
1146 nsChannel *This = impl_from_nsIHttpChannel(iface);
1147 FIXME("(%p)->(%p)\n", This, aContentDispositionHeader);
1148 return NS_ERROR_NOT_IMPLEMENTED;
1151 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1153 nsChannel *This = impl_from_nsIHttpChannel(iface);
1155 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1157 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1161 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1162 const nsACString *aRequestMethod)
1164 nsChannel *This = impl_from_nsIHttpChannel(iface);
1168 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1170 nsACString_GetData(aRequestMethod, &method);
1171 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1172 if(!strcasecmp(method, request_method_strings[i])) {
1173 This->request_method = i;
1178 ERR("Invalid method %s\n", debugstr_a(method));
1179 return NS_ERROR_UNEXPECTED;
1182 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1184 nsChannel *This = impl_from_nsIHttpChannel(iface);
1186 TRACE("(%p)->(%p)\n", This, aReferrer);
1189 nsIURI_AddRef(This->referrer);
1190 *aReferrer = This->referrer;
1194 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1196 nsChannel *This = impl_from_nsIHttpChannel(iface);
1198 TRACE("(%p)->(%p)\n", This, aReferrer);
1201 nsIURI_AddRef(aReferrer);
1203 nsIURI_Release(This->referrer);
1204 This->referrer = aReferrer;
1208 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1209 const nsACString *aHeader, nsACString *_retval)
1211 nsChannel *This = impl_from_nsIHttpChannel(iface);
1213 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1215 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1218 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1219 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1221 nsChannel *This = impl_from_nsIHttpChannel(iface);
1223 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1226 FIXME("aMerge not supported\n");
1228 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1231 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1232 nsIHttpHeaderVisitor *aVisitor)
1234 nsChannel *This = impl_from_nsIHttpChannel(iface);
1236 FIXME("(%p)->(%p)\n", This, aVisitor);
1238 return NS_ERROR_NOT_IMPLEMENTED;
1241 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1243 nsChannel *This = impl_from_nsIHttpChannel(iface);
1245 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1247 return NS_ERROR_NOT_IMPLEMENTED;
1250 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1252 nsChannel *This = impl_from_nsIHttpChannel(iface);
1254 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1256 return NS_ERROR_NOT_IMPLEMENTED;
1259 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1261 nsChannel *This = impl_from_nsIHttpChannel(iface);
1263 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1265 return NS_ERROR_NOT_IMPLEMENTED;
1268 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1270 nsChannel *This = impl_from_nsIHttpChannel(iface);
1272 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1274 return NS_ERROR_NOT_IMPLEMENTED;
1277 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1279 nsChannel *This = impl_from_nsIHttpChannel(iface);
1281 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1283 if(This->response_status) {
1284 *aResponseStatus = This->response_status;
1288 WARN("No response status\n");
1289 return NS_ERROR_UNEXPECTED;
1292 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1293 nsACString *aResponseStatusText)
1295 nsChannel *This = impl_from_nsIHttpChannel(iface);
1297 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1299 return NS_ERROR_NOT_IMPLEMENTED;
1302 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1303 cpp_bool *aRequestSucceeded)
1305 nsChannel *This = impl_from_nsIHttpChannel(iface);
1307 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1309 if(!This->response_status)
1310 return NS_ERROR_NOT_AVAILABLE;
1312 *aRequestSucceeded = This->response_status/100 == 2;
1317 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1318 const nsACString *header, nsACString *_retval)
1320 nsChannel *This = impl_from_nsIHttpChannel(iface);
1322 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1324 return get_channel_http_header(&This->response_headers, header, _retval);
1327 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1328 const nsACString *header, const nsACString *value, cpp_bool merge)
1330 nsChannel *This = impl_from_nsIHttpChannel(iface);
1332 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1334 return NS_ERROR_NOT_IMPLEMENTED;
1337 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1338 nsIHttpHeaderVisitor *aVisitor)
1340 nsChannel *This = impl_from_nsIHttpChannel(iface);
1342 TRACE("(%p)->(%p)\n", This, aVisitor);
1344 return visit_http_headers(&This->response_headers, aVisitor);
1347 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1349 nsChannel *This = impl_from_nsIHttpChannel(iface);
1350 http_header_t *header;
1352 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1353 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1355 TRACE("(%p)->(%p)\n", This, _retval);
1357 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1358 *_retval = header && !strcmpiW(header->data, no_storeW);
1362 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1364 nsChannel *This = impl_from_nsIHttpChannel(iface);
1366 FIXME("(%p)->(%p)\n", This, _retval);
1368 return NS_ERROR_NOT_IMPLEMENTED;
1371 static const nsIHttpChannelVtbl nsChannelVtbl = {
1372 nsChannel_QueryInterface,
1376 nsChannel_IsPending,
1377 nsChannel_GetStatus,
1381 nsChannel_GetLoadGroup,
1382 nsChannel_SetLoadGroup,
1383 nsChannel_GetLoadFlags,
1384 nsChannel_SetLoadFlags,
1385 nsChannel_GetOriginalURI,
1386 nsChannel_SetOriginalURI,
1390 nsChannel_GetNotificationCallbacks,
1391 nsChannel_SetNotificationCallbacks,
1392 nsChannel_GetSecurityInfo,
1393 nsChannel_GetContentType,
1394 nsChannel_SetContentType,
1395 nsChannel_GetContentCharset,
1396 nsChannel_SetContentCharset,
1397 nsChannel_GetContentLength,
1398 nsChannel_SetContentLength,
1400 nsChannel_AsyncOpen,
1401 nsChannel_GetContentDisposition,
1402 nsChannel_GetContentDispositionFilename,
1403 nsChannel_GetContentDispositionHeader,
1404 nsChannel_GetRequestMethod,
1405 nsChannel_SetRequestMethod,
1406 nsChannel_GetReferrer,
1407 nsChannel_SetReferrer,
1408 nsChannel_GetRequestHeader,
1409 nsChannel_SetRequestHeader,
1410 nsChannel_VisitRequestHeaders,
1411 nsChannel_GetAllowPipelining,
1412 nsChannel_SetAllowPipelining,
1413 nsChannel_GetRedirectionLimit,
1414 nsChannel_SetRedirectionLimit,
1415 nsChannel_GetResponseStatus,
1416 nsChannel_GetResponseStatusText,
1417 nsChannel_GetRequestSucceeded,
1418 nsChannel_GetResponseHeader,
1419 nsChannel_SetResponseHeader,
1420 nsChannel_VisitResponseHeaders,
1421 nsChannel_IsNoStoreResponse,
1422 nsChannel_IsNoCacheResponse
1425 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1427 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1430 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1433 nsChannel *This = impl_from_nsIUploadChannel(iface);
1434 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1437 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1439 nsChannel *This = impl_from_nsIUploadChannel(iface);
1440 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1443 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1445 nsChannel *This = impl_from_nsIUploadChannel(iface);
1446 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1449 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1450 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1452 nsChannel *This = impl_from_nsIUploadChannel(iface);
1453 const char *content_type;
1455 static const WCHAR content_typeW[] =
1456 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1458 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1460 This->post_data_contains_headers = TRUE;
1463 nsACString_GetData(aContentType, &content_type);
1467 ct = heap_strdupAtoW(content_type);
1469 return NS_ERROR_UNEXPECTED;
1471 set_http_header(&This->request_headers, content_typeW,
1472 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1474 This->post_data_contains_headers = FALSE;
1478 if(This->post_data_stream)
1479 nsIInputStream_Release(This->post_data_stream);
1481 if(aContentLength != -1)
1482 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1484 if(This->post_data_stream)
1485 nsIInputStream_Release(This->post_data_stream);
1486 This->post_data_stream = aStream;
1488 nsIInputStream_AddRef(aStream);
1490 This->request_method = METHOD_POST;
1494 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1495 nsIInputStream **aUploadStream)
1497 nsChannel *This = impl_from_nsIUploadChannel(iface);
1499 TRACE("(%p)->(%p)\n", This, aUploadStream);
1501 if(This->post_data_stream)
1502 nsIInputStream_AddRef(This->post_data_stream);
1504 *aUploadStream = This->post_data_stream;
1508 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1509 nsUploadChannel_QueryInterface,
1510 nsUploadChannel_AddRef,
1511 nsUploadChannel_Release,
1512 nsUploadChannel_SetUploadStream,
1513 nsUploadChannel_GetUploadStream
1516 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1518 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1521 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1524 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1525 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1528 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1530 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1531 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1534 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1536 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1537 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1540 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1542 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1544 FIXME("(%p)->()\n", This);
1546 return NS_ERROR_NOT_IMPLEMENTED;
1549 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1551 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1553 FIXME("(%p)->()\n", This);
1555 return NS_ERROR_NOT_IMPLEMENTED;
1558 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1560 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1562 FIXME("(%p)->()\n", This);
1564 return NS_ERROR_NOT_IMPLEMENTED;
1567 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1569 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1571 FIXME("(%p)->()\n", This);
1573 return NS_ERROR_NOT_IMPLEMENTED;
1576 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1578 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1580 FIXME("(%p)->()\n", This);
1582 return NS_ERROR_NOT_IMPLEMENTED;
1585 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1587 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1589 FIXME("(%p)->()\n", This);
1591 return NS_ERROR_NOT_IMPLEMENTED;
1594 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1596 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1598 FIXME("(%p)->()\n", This);
1600 return NS_ERROR_NOT_IMPLEMENTED;
1603 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1605 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1607 FIXME("(%p)->()\n", This);
1609 return NS_ERROR_NOT_IMPLEMENTED;
1612 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1614 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1616 FIXME("(%p)->(%p)\n", This, aCanceled);
1618 return NS_ERROR_NOT_IMPLEMENTED;
1621 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1623 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1625 FIXME("(%p)->(%p)\n", This, aCanceled);
1627 return NS_ERROR_NOT_IMPLEMENTED;
1630 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1632 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1634 FIXME("(%p)->(%x)\n", This, aCanceled);
1636 return NS_ERROR_NOT_IMPLEMENTED;
1639 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1641 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1643 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1645 return NS_ERROR_NOT_IMPLEMENTED;
1648 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, PRInt32 *aLocalPort)
1650 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1652 FIXME("(%p)->(%p)\n", This, aLocalPort);
1654 return NS_ERROR_NOT_IMPLEMENTED;
1657 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1659 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1661 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1663 return NS_ERROR_NOT_IMPLEMENTED;
1666 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, PRInt32 *aRemotePort)
1668 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1670 FIXME("(%p)->(%p)\n", This, aRemotePort);
1672 return NS_ERROR_NOT_IMPLEMENTED;
1675 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1677 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1679 FIXME("(%p)->(%p)\n", This, cacheKeys);
1681 return NS_ERROR_NOT_IMPLEMENTED;
1684 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1685 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1687 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1688 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1689 return NS_ERROR_NOT_IMPLEMENTED;
1692 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1694 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1695 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1696 return NS_ERROR_NOT_IMPLEMENTED;
1699 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1701 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1702 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1703 return NS_ERROR_NOT_IMPLEMENTED;
1706 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1707 nsHttpChannelInternal_QueryInterface,
1708 nsHttpChannelInternal_AddRef,
1709 nsHttpChannelInternal_Release,
1710 nsHttpChannelInternal_GetDocumentURI,
1711 nsHttpChannelInternal_SetDocumentURI,
1712 nsHttpChannelInternal_GetRequestVersion,
1713 nsHttpChannelInternal_GetResponseVersion,
1714 nsHttpChannelInternal_SetCookie,
1715 nsHttpChannelInternal_SetupFallbackChannel,
1716 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1717 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1718 nsHttpChannelInternal_GetCanceled,
1719 nsHttpChannelInternal_GetChannelIsForDownload,
1720 nsHttpChannelInternal_SetChannelIsForDownload,
1721 nsHttpChannelInternal_GetLocalAddress,
1722 nsHttpChannelInternal_GetLocalPort,
1723 nsHttpChannelInternal_GetRemoteAddress,
1724 nsHttpChannelInternal_GetRemotePort,
1725 nsHttpChannelInternal_SetCacheKeysRedirectChain,
1726 nsHttpChannelInternal_HTTPUpgrade,
1727 nsHttpChannelInternal_GetAllowSpdy,
1728 nsHttpChannelInternal_SetAllowSpdy
1732 static void invalidate_uri(nsWineURI *This)
1735 IUri_Release(This->uri);
1740 static BOOL ensure_uri_builder(nsWineURI *This)
1742 if(!This->is_mutable) {
1743 WARN("Not mutable URI\n");
1747 if(!This->uri_builder) {
1750 if(!ensure_uri(This))
1753 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1755 WARN("CreateIUriBuilder failed: %08x\n", hres);
1760 invalidate_uri(This);
1764 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1770 if(!ensure_uri(This))
1771 return NS_ERROR_UNEXPECTED;
1773 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1775 WARN("GetPropertyBSTR failed: %08x\n", hres);
1776 return NS_ERROR_UNEXPECTED;
1779 vala = heap_strdupWtoU(val);
1782 return NS_ERROR_OUT_OF_MEMORY;
1784 TRACE("ret %s\n", debugstr_a(vala));
1785 nsACString_SetData(ret, vala);
1790 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
1792 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
1795 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
1797 nsWineURI *This = impl_from_nsIFileURL(iface);
1801 if(IsEqualGUID(&IID_nsISupports, riid)) {
1802 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1803 *result = &This->nsIFileURL_iface;
1804 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1805 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1806 *result = &This->nsIFileURL_iface;
1807 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1808 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1809 *result = &This->nsIFileURL_iface;
1810 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
1811 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
1812 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
1813 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
1814 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
1815 *result = &This->nsIStandardURL_iface;
1816 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
1817 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
1818 *result = &This->nsIStandardURL_iface;
1819 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1820 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1825 nsIFileURL_AddRef(&This->nsIFileURL_iface);
1829 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1830 return NS_NOINTERFACE;
1833 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
1835 nsWineURI *This = impl_from_nsIFileURL(iface);
1836 LONG ref = InterlockedIncrement(&This->ref);
1838 TRACE("(%p) ref=%d\n", This, ref);
1843 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
1845 nsWineURI *This = impl_from_nsIFileURL(iface);
1846 LONG ref = InterlockedDecrement(&This->ref);
1848 TRACE("(%p) ref=%d\n", This, ref);
1851 if(This->window_ref)
1852 windowref_release(This->window_ref);
1854 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1856 IUri_Release(This->uri);
1857 heap_free(This->origin_charset);
1864 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
1866 nsWineURI *This = impl_from_nsIFileURL(iface);
1868 TRACE("(%p)->(%p)\n", This, aSpec);
1870 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1873 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
1875 nsWineURI *This = impl_from_nsIFileURL(iface);
1881 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1883 if(!This->is_mutable)
1884 return NS_ERROR_UNEXPECTED;
1886 nsACString_GetData(aSpec, &speca);
1887 spec = heap_strdupUtoW(speca);
1889 return NS_ERROR_OUT_OF_MEMORY;
1891 hres = CreateUri(spec, 0, 0, &uri);
1894 WARN("CreateUri failed: %08x\n", hres);
1895 return NS_ERROR_FAILURE;
1898 invalidate_uri(This);
1899 if(This->uri_builder) {
1900 IUriBuilder_Release(This->uri_builder);
1901 This->uri_builder = NULL;
1908 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
1910 nsWineURI *This = impl_from_nsIFileURL(iface);
1911 FIXME("(%p)->(%p)\n", This, aPrePath);
1912 return NS_ERROR_NOT_IMPLEMENTED;
1915 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
1917 nsWineURI *This = impl_from_nsIFileURL(iface);
1921 TRACE("(%p)->(%p)\n", This, aScheme);
1923 if(!ensure_uri(This))
1924 return NS_ERROR_UNEXPECTED;
1926 hres = IUri_GetScheme(This->uri, &scheme);
1928 WARN("GetScheme failed: %08x\n", hres);
1929 return NS_ERROR_UNEXPECTED;
1932 if(scheme == URL_SCHEME_ABOUT) {
1933 nsACString_SetData(aScheme, "wine");
1937 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1940 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
1942 nsWineURI *This = impl_from_nsIFileURL(iface);
1943 const char *schemea;
1947 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1949 if(!ensure_uri_builder(This))
1950 return NS_ERROR_UNEXPECTED;
1952 nsACString_GetData(aScheme, &schemea);
1953 scheme = heap_strdupUtoW(schemea);
1955 return NS_ERROR_OUT_OF_MEMORY;
1957 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
1960 return NS_ERROR_UNEXPECTED;
1965 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
1967 nsWineURI *This = impl_from_nsIFileURL(iface);
1971 TRACE("(%p)->(%p)\n", This, aUserPass);
1973 if(!ensure_uri(This))
1974 return NS_ERROR_UNEXPECTED;
1976 hres = IUri_GetUserName(This->uri, &user);
1978 return NS_ERROR_FAILURE;
1980 hres = IUri_GetPassword(This->uri, &pass);
1982 SysFreeString(user);
1983 return NS_ERROR_FAILURE;
1986 if(*user || *pass) {
1987 FIXME("Construct user:pass string\n");
1989 nsACString_SetData(aUserPass, "");
1992 SysFreeString(user);
1993 SysFreeString(pass);
1997 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
1999 nsWineURI *This = impl_from_nsIFileURL(iface);
2000 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
2001 const char *user_pass;
2004 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
2006 if(!ensure_uri_builder(This))
2007 return NS_ERROR_UNEXPECTED;
2009 nsACString_GetData(aUserPass, &user_pass);
2013 buf = heap_strdupUtoW(user_pass);
2015 return NS_ERROR_OUT_OF_MEMORY;
2017 ptr = strchrW(buf, ':');
2020 }else if(ptr != buf) {
2030 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2032 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2035 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2038 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2040 nsWineURI *This = impl_from_nsIFileURL(iface);
2042 TRACE("(%p)->(%p)\n", This, aUsername);
2044 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2047 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2049 nsWineURI *This = impl_from_nsIFileURL(iface);
2054 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2056 if(!ensure_uri_builder(This))
2057 return NS_ERROR_UNEXPECTED;
2059 nsACString_GetData(aUsername, &usera);
2060 user = heap_strdupUtoW(usera);
2062 return NS_ERROR_OUT_OF_MEMORY;
2064 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2067 return NS_ERROR_UNEXPECTED;
2072 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2074 nsWineURI *This = impl_from_nsIFileURL(iface);
2076 TRACE("(%p)->(%p)\n", This, aPassword);
2078 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2081 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2083 nsWineURI *This = impl_from_nsIFileURL(iface);
2088 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2090 if(!ensure_uri_builder(This))
2091 return NS_ERROR_UNEXPECTED;
2093 nsACString_GetData(aPassword, &passa);
2094 pass = heap_strdupUtoW(passa);
2096 return NS_ERROR_OUT_OF_MEMORY;
2098 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2101 return NS_ERROR_UNEXPECTED;
2106 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2108 nsWineURI *This = impl_from_nsIFileURL(iface);
2114 TRACE("(%p)->(%p)\n", This, aHostPort);
2116 if(!ensure_uri(This))
2117 return NS_ERROR_UNEXPECTED;
2119 hres = IUri_GetAuthority(This->uri, &val);
2121 WARN("GetAuthority failed: %08x\n", hres);
2122 return NS_ERROR_UNEXPECTED;
2125 ptr = strchrW(val, '@');
2129 vala = heap_strdupWtoU(ptr);
2132 return NS_ERROR_OUT_OF_MEMORY;
2134 TRACE("ret %s\n", debugstr_a(vala));
2135 nsACString_SetData(aHostPort, vala);
2140 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2142 nsWineURI *This = impl_from_nsIFileURL(iface);
2144 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2146 /* Not implemented by Gecko */
2147 return NS_ERROR_NOT_IMPLEMENTED;
2150 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2152 nsWineURI *This = impl_from_nsIFileURL(iface);
2154 TRACE("(%p)->(%p)\n", This, aHost);
2156 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2159 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2161 nsWineURI *This = impl_from_nsIFileURL(iface);
2166 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2168 if(!ensure_uri_builder(This))
2169 return NS_ERROR_UNEXPECTED;
2171 nsACString_GetData(aHost, &hosta);
2172 host = heap_strdupUtoW(hosta);
2174 return NS_ERROR_OUT_OF_MEMORY;
2176 hres = IUriBuilder_SetHost(This->uri_builder, host);
2179 return NS_ERROR_UNEXPECTED;
2184 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, PRInt32 *aPort)
2186 nsWineURI *This = impl_from_nsIFileURL(iface);
2190 TRACE("(%p)->(%p)\n", This, aPort);
2192 if(!ensure_uri(This))
2193 return NS_ERROR_UNEXPECTED;
2195 hres = IUri_GetPort(This->uri, &port);
2197 WARN("GetPort failed: %08x\n", hres);
2198 return NS_ERROR_UNEXPECTED;
2201 *aPort = port ? port : -1;
2205 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, PRInt32 aPort)
2207 nsWineURI *This = impl_from_nsIFileURL(iface);
2210 TRACE("(%p)->(%d)\n", This, aPort);
2212 if(!ensure_uri_builder(This))
2213 return NS_ERROR_UNEXPECTED;
2215 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2216 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2219 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2221 nsWineURI *This = impl_from_nsIFileURL(iface);
2223 TRACE("(%p)->(%p)\n", This, aPath);
2225 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2228 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2230 nsWineURI *This = impl_from_nsIFileURL(iface);
2235 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2237 if(!ensure_uri_builder(This))
2238 return NS_ERROR_UNEXPECTED;
2240 nsACString_GetData(aPath, &patha);
2241 path = heap_strdupUtoW(patha);
2243 return NS_ERROR_OUT_OF_MEMORY;
2245 hres = IUriBuilder_SetPath(This->uri_builder, path);
2248 return NS_ERROR_UNEXPECTED;
2253 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2255 nsWineURI *This = impl_from_nsIFileURL(iface);
2256 nsWineURI *other_obj;
2260 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2262 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2263 if(NS_FAILED(nsres)) {
2264 TRACE("Could not get nsWineURI interface\n");
2269 if(ensure_uri(This) && ensure_uri(other_obj)) {
2272 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2273 if(SUCCEEDED(hres)) {
2277 nsres = NS_ERROR_FAILURE;
2280 nsres = NS_ERROR_UNEXPECTED;
2283 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2287 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2289 nsWineURI *This = impl_from_nsIFileURL(iface);
2290 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2294 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2296 if(!ensure_uri(This))
2297 return NS_ERROR_UNEXPECTED;
2299 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2301 return NS_ERROR_UNEXPECTED;
2303 MultiByteToWideChar(CP_UTF8, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2304 *_retval = !strcmpW(scheme_name, buf);
2305 SysFreeString(scheme_name);
2309 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2311 nsWineURI *This = impl_from_nsIFileURL(iface);
2312 nsWineURI *wine_uri;
2315 TRACE("(%p)->(%p)\n", This, _retval);
2317 if(!ensure_uri(This))
2318 return NS_ERROR_UNEXPECTED;
2320 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL,
2321 This->container, This->origin_charset, &wine_uri);
2322 if(NS_FAILED(nsres)) {
2323 WARN("create_nsuri failed: %08x\n", nsres);
2327 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2331 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2332 nsACString *_retval)
2334 nsWineURI *This = impl_from_nsIFileURL(iface);
2342 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2344 if(!ensure_uri(This))
2345 return NS_ERROR_UNEXPECTED;
2347 nsACString_GetData(aRelativePath, &patha);
2348 path = heap_strdupUtoW(patha);
2350 return NS_ERROR_OUT_OF_MEMORY;
2352 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2355 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2356 return NS_ERROR_FAILURE;
2359 hres = IUri_GetDisplayUri(new_uri, &ret);
2360 IUri_Release(new_uri);
2362 return NS_ERROR_FAILURE;
2364 reta = heap_strdupWtoU(ret);
2367 return NS_ERROR_OUT_OF_MEMORY;
2369 TRACE("returning %s\n", debugstr_a(reta));
2370 nsACString_SetData(_retval, reta);
2375 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2377 nsWineURI *This = impl_from_nsIFileURL(iface);
2379 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2381 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2384 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2386 nsWineURI *This = impl_from_nsIFileURL(iface);
2388 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2390 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2393 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2395 nsWineURI *This = impl_from_nsIFileURL(iface);
2397 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2399 nsACString_SetData(aOriginCharset, This->origin_charset);
2403 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2405 nsWineURI *This = impl_from_nsIFileURL(iface);
2410 TRACE("(%p)->(%p)\n", This, aRef);
2412 if(!ensure_uri(This))
2413 return NS_ERROR_UNEXPECTED;
2415 hres = IUri_GetFragment(This->uri, &ref);
2417 return NS_ERROR_UNEXPECTED;
2419 refa = heap_strdupWtoU(ref);
2422 return NS_ERROR_OUT_OF_MEMORY;
2424 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2429 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2431 nsWineURI *This = impl_from_nsIFileURL(iface);
2436 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2438 if(!ensure_uri_builder(This))
2439 return NS_ERROR_UNEXPECTED;
2441 nsACString_GetData(aRef, &refa);
2442 ref = heap_strdupUtoW(refa);
2444 return NS_ERROR_OUT_OF_MEMORY;
2446 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2449 return NS_ERROR_UNEXPECTED;
2454 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2456 nsWineURI *This = impl_from_nsIFileURL(iface);
2457 nsWineURI *other_obj;
2460 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2462 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2463 if(NS_FAILED(nsres)) {
2464 TRACE("Could not get nsWineURI interface\n");
2469 if(ensure_uri(This) && ensure_uri(other_obj)) {
2470 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2473 nsres = NS_ERROR_UNEXPECTED;
2476 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2480 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2482 nsWineURI *This = impl_from_nsIFileURL(iface);
2483 nsWineURI *wine_uri;
2487 TRACE("(%p)->(%p)\n", This, _retval);
2489 if(!ensure_uri(This))
2490 return NS_ERROR_UNEXPECTED;
2492 uri = get_uri_nofrag(This->uri);
2494 return NS_ERROR_FAILURE;
2496 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container,
2497 This->origin_charset, &wine_uri);
2499 if(NS_FAILED(nsres)) {
2500 WARN("create_nsuri failed: %08x\n", nsres);
2504 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2508 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2510 nsWineURI *This = impl_from_nsIFileURL(iface);
2512 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2514 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2517 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2519 nsWineURI *This = impl_from_nsIFileURL(iface);
2523 TRACE("(%p)->(%p)\n", This, aHasRef);
2525 if(!ensure_uri(This))
2526 return NS_ERROR_UNEXPECTED;
2528 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2530 return NS_ERROR_FAILURE;
2536 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2538 nsWineURI *This = impl_from_nsIFileURL(iface);
2540 TRACE("(%p)->(%p)\n", This, aFilePath);
2542 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2545 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2547 nsWineURI *This = impl_from_nsIFileURL(iface);
2549 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2551 if(!This->is_mutable)
2552 return NS_ERROR_UNEXPECTED;
2554 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
2557 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
2559 nsWineURI *This = impl_from_nsIFileURL(iface);
2561 TRACE("(%p)->(%p)\n", This, aQuery);
2563 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2566 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
2568 nsWineURI *This = impl_from_nsIFileURL(iface);
2573 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2575 if(!ensure_uri_builder(This))
2576 return NS_ERROR_UNEXPECTED;
2578 nsACString_GetData(aQuery, &querya);
2579 query = heap_strdupUtoW(querya);
2581 return NS_ERROR_OUT_OF_MEMORY;
2583 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2586 return NS_ERROR_UNEXPECTED;
2591 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
2596 if(!ensure_uri(This))
2597 return NS_ERROR_UNEXPECTED;
2599 hres = IUri_GetPath(This->uri, path);
2601 return NS_ERROR_FAILURE;
2603 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
2604 if(*ptr == '/' || *ptr == '\\')
2609 ptr = strrchrW(ptr, '.');
2611 ptr = *path + SysStringLen(*path);
2618 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
2620 nsWineURI *This = impl_from_nsIFileURL(iface);
2625 TRACE("(%p)->(%p)\n", This, aDirectory);
2627 nsres = get_uri_path(This, &path, &file, NULL);
2628 if(NS_FAILED(nsres))
2631 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
2632 SysFreeString(path);
2636 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
2638 nsWineURI *This = impl_from_nsIFileURL(iface);
2640 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2642 /* Not implemented by Gecko */
2643 return NS_ERROR_NOT_IMPLEMENTED;
2646 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
2648 nsWineURI *This = impl_from_nsIFileURL(iface);
2653 TRACE("(%p)->(%p)\n", This, aFileName);
2655 nsres = get_uri_path(This, &path, &file, NULL);
2656 if(NS_FAILED(nsres))
2659 nsres = return_wstr_nsacstr(aFileName, file, -1);
2660 SysFreeString(path);
2664 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
2666 nsWineURI *This = impl_from_nsIFileURL(iface);
2667 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2668 return NS_ERROR_NOT_IMPLEMENTED;
2671 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
2673 nsWineURI *This = impl_from_nsIFileURL(iface);
2674 const WCHAR *file, *ext;
2678 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2680 nsres = get_uri_path(This, &path, &file, &ext);
2681 if(NS_FAILED(nsres))
2684 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
2685 SysFreeString(path);
2689 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
2691 nsWineURI *This = impl_from_nsIFileURL(iface);
2692 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2693 return NS_ERROR_NOT_IMPLEMENTED;
2696 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
2698 nsWineURI *This = impl_from_nsIFileURL(iface);
2700 TRACE("(%p)->(%p)\n", This, aFileExtension);
2702 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
2705 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
2707 nsWineURI *This = impl_from_nsIFileURL(iface);
2708 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2709 return NS_ERROR_NOT_IMPLEMENTED;
2712 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2714 nsWineURI *This = impl_from_nsIFileURL(iface);
2715 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2716 return NS_ERROR_NOT_IMPLEMENTED;
2719 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2721 nsWineURI *This = impl_from_nsIFileURL(iface);
2722 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2723 return NS_ERROR_NOT_IMPLEMENTED;
2726 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
2728 nsWineURI *This = impl_from_nsIFileURL(iface);
2729 WCHAR path[MAX_PATH];
2733 TRACE("(%p)->(%p)\n", This, aFile);
2735 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
2737 WARN("CoInternetParseIUri failed: %08x\n", hres);
2738 return NS_ERROR_FAILURE;
2741 return create_nsfile(path, aFile);
2744 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
2746 nsWineURI *This = impl_from_nsIFileURL(iface);
2747 FIXME("(%p)->(%p)\n", This, aFile);
2748 return NS_ERROR_NOT_IMPLEMENTED;
2751 static const nsIFileURLVtbl nsFileURLVtbl = {
2752 nsURI_QueryInterface,
2780 nsURI_GetOriginCharset,
2783 nsURI_EqualsExceptRef,
2784 nsURI_CloneIgnoreRef,
2785 nsURI_GetSpecIgnoringRef,
2795 nsURL_GetFileBaseName,
2796 nsURL_SetFileBaseName,
2797 nsURL_GetFileExtension,
2798 nsURL_SetFileExtension,
2799 nsURL_GetCommonBaseSpec,
2800 nsURL_GetRelativeSpec,
2805 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
2807 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
2810 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
2813 nsWineURI *This = impl_from_nsIStandardURL(iface);
2814 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
2817 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
2819 nsWineURI *This = impl_from_nsIStandardURL(iface);
2820 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
2823 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
2825 nsWineURI *This = impl_from_nsIStandardURL(iface);
2826 return nsIFileURL_Release(&This->nsIFileURL_iface);
2829 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
2831 nsWineURI *This = impl_from_nsIStandardURL(iface);
2833 TRACE("(%p)->(%p)\n", This, aMutable);
2835 *aMutable = This->is_mutable;
2839 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
2841 nsWineURI *This = impl_from_nsIStandardURL(iface);
2843 TRACE("(%p)->(%x)\n", This, aMutable);
2845 This->is_mutable = aMutable;
2849 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, PRUint32 aUrlType, PRInt32 aDefaultPort,
2850 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
2852 nsWineURI *This = impl_from_nsIStandardURL(iface);
2853 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
2854 return NS_ERROR_NOT_IMPLEMENTED;
2857 static const nsIStandardURLVtbl nsStandardURLVtbl = {
2858 nsStandardURL_QueryInterface,
2859 nsStandardURL_AddRef,
2860 nsStandardURL_Release,
2861 nsStandardURL_GetMutable,
2862 nsStandardURL_SetMutable,
2866 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container,
2867 const char *origin_charset, nsWineURI **_retval)
2872 ret = heap_alloc_zero(sizeof(nsWineURI));
2874 return NS_ERROR_OUT_OF_MEMORY;
2876 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
2877 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
2879 ret->is_mutable = TRUE;
2881 set_uri_nscontainer(ret, container);
2882 set_uri_window(ret, window);
2887 hres = IUri_GetScheme(iuri, &ret->scheme);
2889 ret->scheme = URL_SCHEME_UNKNOWN;
2891 if(origin_charset && *origin_charset && strcmp(origin_charset, "UTF-8")) {
2892 ret->origin_charset = heap_strdupA(origin_charset);
2893 if(!ret->origin_charset) {
2894 nsIFileURL_Release(&ret->nsIFileURL_iface);
2895 return NS_ERROR_OUT_OF_MEMORY;
2899 TRACE("retval=%p\n", ret);
2904 HRESULT create_doc_uri(HTMLOuterWindow *window, const WCHAR *url, nsWineURI **ret)
2911 hres = CreateUri(url, 0, 0, &iuri);
2915 nsres = create_nsuri(iuri, window, window->doc_obj->nscontainer, NULL, &uri);
2917 if(NS_FAILED(nsres))
2920 uri->is_doc_uri = TRUE;
2926 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2930 if(!ensure_uri(uri))
2931 return NS_ERROR_UNEXPECTED;
2933 channel = heap_alloc_zero(sizeof(nsChannel));
2935 return NS_ERROR_OUT_OF_MEMORY;
2937 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2938 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2939 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2941 channel->request_method = METHOD_GET;
2942 list_init(&channel->response_headers);
2943 list_init(&channel->request_headers);
2945 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
2952 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
2954 HTMLOuterWindow *window = NULL;
2961 hres = CreateUri(url, 0, 0, &iuri);
2965 if(orig_channel->uri->window_ref)
2966 window = orig_channel->uri->window_ref->window;
2967 nsres = create_nsuri(iuri, window, NULL, NULL, &uri);
2969 if(NS_FAILED(nsres))
2972 nsres = create_nschannel(uri, &channel);
2973 nsIFileURL_Release(&uri->nsIFileURL_iface);
2974 if(NS_FAILED(nsres))
2977 if(orig_channel->load_group) {
2978 nsILoadGroup_AddRef(orig_channel->load_group);
2979 channel->load_group = orig_channel->load_group;
2982 if(orig_channel->notif_callback) {
2983 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
2984 channel->notif_callback = orig_channel->notif_callback;
2987 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
2989 if(orig_channel->request_method == METHOD_POST)
2990 FIXME("unsupported POST method\n");
2992 if(orig_channel->original_uri) {
2993 nsIURI_AddRef(orig_channel->original_uri);
2994 channel->original_uri = orig_channel->original_uri;
2997 if(orig_channel->referrer) {
2998 nsIURI_AddRef(orig_channel->referrer);
2999 channel->referrer = orig_channel->referrer;
3007 nsIProtocolHandler nsIProtocolHandler_iface;
3011 nsIProtocolHandler *nshandler;
3012 } nsProtocolHandler;
3014 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
3016 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
3019 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3022 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3026 if(IsEqualGUID(&IID_nsISupports, riid)) {
3027 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3028 *result = &This->nsIProtocolHandler_iface;
3029 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3030 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3031 *result = &This->nsIProtocolHandler_iface;
3032 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3033 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3034 return NS_NOINTERFACE;
3038 nsISupports_AddRef((nsISupports*)*result);
3042 WARN("(%s %p)\n", debugstr_guid(riid), result);
3043 return NS_NOINTERFACE;
3046 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3048 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3049 LONG ref = InterlockedIncrement(&This->ref);
3051 TRACE("(%p) ref=%d\n", This, ref);
3056 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3058 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3059 LONG ref = InterlockedDecrement(&This->ref);
3061 TRACE("(%p) ref=%d\n", This, ref);
3065 nsIProtocolHandler_Release(This->nshandler);
3072 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3074 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3076 TRACE("(%p)->(%p)\n", This, aScheme);
3079 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3080 return NS_ERROR_NOT_IMPLEMENTED;
3083 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3084 PRInt32 *aDefaultPort)
3086 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3088 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3091 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3092 return NS_ERROR_NOT_IMPLEMENTED;
3095 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3096 PRUint32 *aProtocolFlags)
3098 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3100 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3103 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3104 return NS_ERROR_NOT_IMPLEMENTED;
3107 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3108 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3110 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3112 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3116 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3117 return NS_ERROR_NOT_IMPLEMENTED;
3120 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3121 nsIURI *aURI, nsIChannel **_retval)
3123 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3125 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3128 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3129 return NS_ERROR_NOT_IMPLEMENTED;
3132 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3133 PRInt32 port, const char *scheme, cpp_bool *_retval)
3135 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3137 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3140 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3141 return NS_ERROR_NOT_IMPLEMENTED;
3144 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3145 nsProtocolHandler_QueryInterface,
3146 nsProtocolHandler_AddRef,
3147 nsProtocolHandler_Release,
3148 nsProtocolHandler_GetScheme,
3149 nsProtocolHandler_GetDefaultPort,
3150 nsProtocolHandler_GetProtocolFlags,
3151 nsProtocolHandler_NewURI,
3152 nsProtocolHandler_NewChannel,
3153 nsProtocolHandler_AllowPort
3156 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
3158 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
3163 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
3168 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
3169 nsIProtocolHandler **_retval)
3171 nsIExternalProtocolHandler *nsexthandler;
3172 nsIProtocolHandler *nshandler;
3173 nsProtocolHandler *ret;
3176 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3178 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
3179 if(NS_FAILED(nsres)) {
3180 WARN("GetProtocolHandler failed: %08x\n", nsres);
3184 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
3185 (void**)&nsexthandler);
3186 if(NS_FAILED(nsres)) {
3187 *_retval = nshandler;
3191 nsIExternalProtocolHandler_Release(nsexthandler);
3193 ret = heap_alloc(sizeof(nsProtocolHandler));
3195 return NS_ERROR_OUT_OF_MEMORY;
3197 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3199 ret->nshandler = nshandler;
3200 *_retval = &ret->nsIProtocolHandler_iface;
3202 TRACE("return %p\n", *_retval);
3206 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
3209 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3210 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
3213 static BOOL is_gecko_special_uri(const char *spec)
3215 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3218 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3219 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3223 if(!strncasecmp(spec, "file:", 5)) {
3224 const char *ptr = spec+5;
3227 return is_gecko_path(ptr);
3233 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
3234 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3236 nsWineURI *wine_uri, *base_wine_uri = NULL;
3237 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3238 HTMLOuterWindow *window = NULL;
3239 const char *spec = NULL;
3244 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3247 nsACString_GetData(aSpec, &spec);
3248 if(is_gecko_special_uri(spec))
3249 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3251 if(!strncmp(spec, "wine:", 5))
3255 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3256 if(NS_SUCCEEDED(nsres)) {
3257 if(!ensure_uri(base_wine_uri))
3258 return NS_ERROR_UNEXPECTED;
3259 if(base_wine_uri->window_ref)
3260 window = base_wine_uri->window_ref->window;
3262 WARN("Could not get base nsWineURI: %08x\n", nsres);
3266 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3269 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
3272 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
3274 hres = CreateUri(new_spec, 0, 0, &urlmon_uri);
3276 WARN("CreateUri failed: %08x\n", hres);
3280 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3282 nsres = create_nsuri(urlmon_uri, window, NULL, NULL, &wine_uri);
3283 IUri_Release(urlmon_uri);
3285 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3286 if(NS_FAILED(nsres))
3289 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3293 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
3296 TRACE("(%p %p)\n", aFile, _retval);
3297 return nsIIOService_NewFileURI(nsio, aFile, _retval);
3300 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
3301 nsIChannel **_retval)
3303 nsWineURI *wine_uri;
3307 TRACE("(%p %p)\n", aURI, _retval);
3309 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3310 if(NS_FAILED(nsres)) {
3311 TRACE("Could not get nsWineURI: %08x\n", nsres);
3312 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
3315 nsres = create_nschannel(wine_uri, &ret);
3316 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3317 if(NS_FAILED(nsres))
3320 nsIURI_AddRef(aURI);
3321 ret->original_uri = aURI;
3323 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3327 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
3328 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
3330 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
3331 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3334 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, cpp_bool *aOffline)
3336 TRACE("(%p)\n", aOffline);
3337 return nsIIOService_GetOffline(nsio, aOffline);
3340 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, cpp_bool aOffline)
3342 TRACE("(%x)\n", aOffline);
3343 return nsIIOService_SetOffline(nsio, aOffline);
3346 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
3347 const char *aScheme, cpp_bool *_retval)
3349 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
3350 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
3353 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
3354 nsACString * _retval)
3356 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
3357 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
3360 static const nsIIOServiceVtbl nsIOServiceVtbl = {
3361 nsIOService_QueryInterface,
3363 nsIOService_Release,
3364 nsIOService_GetProtocolHandler,
3365 nsIOService_GetProtocolFlags,
3367 nsIOService_NewFileURI,
3368 nsIOService_NewChannelFromURI,
3369 nsIOService_NewChannel,
3370 nsIOService_GetOffline,
3371 nsIOService_SetOffline,
3372 nsIOService_AllowPort,
3373 nsIOService_ExtractScheme
3376 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3378 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3381 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3384 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3389 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3394 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3395 nsACString *aCharset, cpp_bool *aHadCharset, nsACString *aContentType)
3397 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3399 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3402 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, cpp_bool *_retval)
3406 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3409 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, cpp_bool *_retval)
3411 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3413 if(aFlags == (1<<11)) {
3418 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3421 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3423 TRACE("(%p %p)\n", aURI, _retval);
3425 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3428 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3430 TRACE("(%p %p)\n", aURI, _retval);
3432 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3435 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3436 PRUint32 aEscapeType, nsACString *_retval)
3438 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3440 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3443 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
3444 nsACString *_retval)
3446 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3448 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3451 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3452 PRUint32 aFlags, nsACString *_retval)
3454 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3456 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3459 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3460 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, cpp_bool *_retval)
3462 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3463 aCharsetEnd, _retval);
3465 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3468 static const nsINetUtilVtbl nsNetUtilVtbl = {
3469 nsNetUtil_QueryInterface,
3472 nsNetUtil_ParseContentType,
3473 nsNetUtil_ProtocolHasFlags,
3474 nsNetUtil_URIChainHasFlags,
3475 nsNetUtil_ToImmutableURI,
3476 nsNetUtil_NewSimpleNestedURI,
3477 nsNetUtil_EscapeString,
3478 nsNetUtil_EscapeURL,
3479 nsNetUtil_UnescapeString,
3480 nsNetUtil_ExtractCharsetFromContentType
3483 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3485 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3490 if(IsEqualGUID(&IID_nsISupports, riid))
3491 *result = &nsIOService;
3492 else if(IsEqualGUID(&IID_nsIIOService, riid))
3493 *result = &nsIOService;
3494 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3495 *result = &nsNetUtil;
3498 nsISupports_AddRef((nsISupports*)*result);
3502 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3503 return NS_NOINTERFACE;
3506 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3511 if(IsEqualGUID(&IID_nsISupports, riid)) {
3512 TRACE("(IID_nsISupports %p)\n", result);
3514 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3515 TRACE("(IID_nsIFactory %p)\n", result);
3520 nsIFactory_AddRef(iface);
3524 WARN("(%s %p)\n", debugstr_guid(riid), result);
3525 return NS_NOINTERFACE;
3528 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3533 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3538 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3539 nsISupports *aOuter, const nsIID *iid, void **result)
3541 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3544 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
3546 WARN("(%x)\n", lock);
3550 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3551 nsIOServiceFactory_QueryInterface,
3552 nsIOServiceFactory_AddRef,
3553 nsIOServiceFactory_Release,
3554 nsIOServiceFactory_CreateInstance,
3555 nsIOServiceFactory_LockFactory
3558 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3560 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3562 OLECHAR *new_url = NULL;
3567 if(!doc->hostui || !ensure_uri(uri))
3570 hres = IUri_GetDisplayUri(uri->uri, &url);
3574 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3575 if(hres == S_OK && new_url) {
3576 if(strcmpW(url, new_url)) {
3577 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3580 CoTaskMemFree(new_url);
3587 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
3589 nsWineURI *wine_uri;
3594 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3595 if(NS_FAILED(nsres)) {
3596 WARN("Could not get nsWineURI: %08x\n", nsres);
3597 return NS_ERROR_NOT_IMPLEMENTED;
3600 if(!wine_uri->is_doc_uri) {
3601 wine_uri->is_doc_uri = TRUE;
3603 if(!wine_uri->container) {
3604 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3605 wine_uri->container = nscontainer;
3608 if(nscontainer->doc)
3609 *_retval = translate_url(nscontainer->doc, wine_uri);
3612 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3616 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3618 nsIFactory *old_factory = NULL;
3621 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3622 &IID_nsIFactory, (void**)&old_factory);
3623 if(NS_FAILED(nsres)) {
3624 ERR("Could not get factory: %08x\n", nsres);
3628 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3629 if(NS_FAILED(nsres)) {
3630 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3631 nsIFactory_Release(old_factory);
3635 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3636 if(NS_FAILED(nsres)) {
3637 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3638 nsIIOService_Release(nsio);
3642 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3643 nsIFactory_Release(old_factory);
3644 if(NS_FAILED(nsres))
3645 ERR("UnregisterFactory failed: %08x\n", nsres);
3647 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3648 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3649 if(NS_FAILED(nsres))
3650 ERR("RegisterFactory failed: %08x\n", nsres);
3653 void release_nsio(void)
3656 nsINetUtil_Release(net_util);
3661 nsIIOService_Release(nsio);