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 WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
55 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
64 NSContainer *container;
65 windowref_t *window_ref;
66 nsChannelBSC *channel_bsc;
68 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 static IUri *get_uri_nofrag(IUri *uri)
91 IUriBuilder *uri_builder;
96 hres = IUri_HasProperty(uri, Uri_PROPERTY_FRAGMENT, &b);
97 if(SUCCEEDED(hres) && !b) {
102 hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
106 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_FRAGMENT);
108 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &ret);
109 IUriBuilder_Release(uri_builder);
116 BOOL compare_ignoring_frag(IUri *uri1, IUri *uri2)
118 IUri *uri_nofrag1, *uri_nofrag2;
121 uri_nofrag1 = get_uri_nofrag(uri1);
125 uri_nofrag2 = get_uri_nofrag(uri2);
127 IUri_IsEqual(uri_nofrag1, uri_nofrag2, &ret);
128 IUri_Release(uri_nofrag2);
131 IUri_Release(uri_nofrag1);
135 static nsresult create_nsuri(IUri*,nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
137 static const char *debugstr_nsacstr(const nsACString *nsstr)
141 nsACString_GetData(nsstr, &data);
142 return debugstr_a(data);
145 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
147 const WCHAR *ptr = nsuri;
149 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
151 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
152 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
154 if(*ptr || ret_empty) {
155 *ret = SysAllocString(ptr);
157 return E_OUTOFMEMORY;
162 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
166 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
168 IOleCommandTarget *cmdtrg = NULL;
171 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
172 if(SUCCEEDED(hres)) {
173 VARIANT varUrl, varRes;
175 V_VT(&varUrl) = VT_BSTR;
176 V_BSTR(&varUrl) = url;
177 V_VT(&varRes) = VT_BOOL;
179 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
181 IOleCommandTarget_Release(cmdtrg);
183 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
184 TRACE("got VARIANT_FALSE, do not load\n");
192 static nsresult before_async_open(nsChannel *channel, NSContainer *container, BOOL *cancel)
194 HTMLDocumentObj *doc = container->doc;
200 NSContainer *container_iter = container;
202 hlnf = HLNF_OPENINNEWWINDOW;
203 while(!container_iter->doc)
204 container_iter = container_iter->parent;
205 doc = container_iter->doc;
213 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
215 return NS_ERROR_FAILURE;
220 b = !exec_shldocvw_67(doc, display_uri);
222 SysFreeString(display_uri);
228 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, hlnf, cancel);
229 SysFreeString(display_uri);
235 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
237 nsIWebNavigation *web_navigation;
238 nsIDocShell *doc_shell;
239 HTMLDocumentNode *doc;
242 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
243 if(NS_FAILED(nsres)) {
244 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
248 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
249 nsIWebNavigation_Release(web_navigation);
250 if(NS_FAILED(nsres)) {
251 ERR("Could not get nsIDocShell: %08x\n", nsres);
255 uri->channel_bsc = channelbsc;
257 doc->skip_mutation_notif = TRUE;
258 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIURL_iface, NULL, flags, FALSE);
259 if(doc == window->doc)
260 doc->skip_mutation_notif = FALSE;
261 uri->channel_bsc = NULL;
262 nsIDocShell_Release(doc_shell);
263 if(NS_FAILED(nsres)) {
264 WARN("LoadURI failed: %08x\n", nsres);
271 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
273 if(This->container) {
274 if(This->container == nscontainer)
276 TRACE("Changing %p -> %p\n", This->container, nscontainer);
277 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
281 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
282 This->container = nscontainer;
285 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
287 if(This->window_ref) {
288 if(This->window_ref->window == window)
290 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
291 windowref_release(This->window_ref);
295 windowref_addref(window->window_ref);
296 This->window_ref = window->window_ref;
299 set_uri_nscontainer(This, window->doc_obj->nscontainer);
301 This->window_ref = NULL;
305 static inline BOOL is_http_channel(nsChannel *This)
307 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTPS;
310 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
314 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
315 if(!strcmpiW(iter->header, name))
322 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
325 const char *header_namea;
326 http_header_t *header;
330 nsACString_GetData(header_name_str, &header_namea);
331 header_name = heap_strdupAtoW(header_namea);
333 return NS_ERROR_UNEXPECTED;
335 header = find_http_header(headers, header_name, strlenW(header_name));
336 heap_free(header_name);
338 return NS_ERROR_NOT_AVAILABLE;
340 data = heap_strdupWtoA(header->data);
342 return NS_ERROR_UNEXPECTED;
344 nsACString_SetData(_retval, data);
349 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
350 const WCHAR *value, int value_len)
352 http_header_t *header;
354 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
356 header = find_http_header(headers, name, name_len);
360 new_data = heap_strndupW(value, value_len);
362 return E_OUTOFMEMORY;
364 heap_free(header->data);
365 header->data = new_data;
367 header = heap_alloc(sizeof(http_header_t));
369 return E_OUTOFMEMORY;
371 header->header = heap_strndupW(name, name_len);
372 header->data = heap_strndupW(value, value_len);
373 if(!header->header || !header->data) {
374 heap_free(header->header);
375 heap_free(header->data);
377 return E_OUTOFMEMORY;
380 list_add_tail(headers, &header->entry);
386 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
387 const nsACString *value_str)
389 const char *namea, *valuea;
393 nsACString_GetData(name_str, &namea);
394 name = heap_strdupAtoW(namea);
396 return NS_ERROR_UNEXPECTED;
398 nsACString_GetData(value_str, &valuea);
399 value = heap_strdupAtoW(valuea);
402 return NS_ERROR_UNEXPECTED;
405 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
409 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
412 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
414 nsACString header_str, value_str;
415 char *header, *value;
419 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
420 header = heap_strdupWtoA(iter->header);
422 return NS_ERROR_OUT_OF_MEMORY;
424 value = heap_strdupWtoA(iter->data);
427 return NS_ERROR_OUT_OF_MEMORY;
430 nsACString_InitDepend(&header_str, header);
431 nsACString_InitDepend(&value_str, value);
432 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
433 nsACString_Finish(&header_str);
434 nsACString_Finish(&value_str);
444 static void free_http_headers(struct list *list)
446 http_header_t *iter, *iter_next;
448 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
449 list_remove(&iter->entry);
450 heap_free(iter->header);
451 heap_free(iter->data);
456 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
458 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
461 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
463 nsChannel *This = impl_from_nsIHttpChannel(iface);
465 if(IsEqualGUID(&IID_nsISupports, riid)) {
466 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
467 *result = &This->nsIHttpChannel_iface;
468 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
469 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
470 *result = &This->nsIHttpChannel_iface;
471 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
472 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
473 *result = &This->nsIHttpChannel_iface;
474 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
475 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
476 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
477 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
478 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
479 *result = &This->nsIUploadChannel_iface;
480 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
481 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
482 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
484 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
489 nsIChannel_AddRef(&This->nsIHttpChannel_iface);
493 return NS_NOINTERFACE;
496 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
498 nsChannel *This = impl_from_nsIHttpChannel(iface);
499 nsrefcnt ref = InterlockedIncrement(&This->ref);
501 TRACE("(%p) ref=%d\n", This, ref);
506 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
508 nsChannel *This = impl_from_nsIHttpChannel(iface);
509 LONG ref = InterlockedDecrement(&This->ref);
512 nsIURI_Release(&This->uri->nsIURL_iface);
514 nsISupports_Release(This->owner);
515 if(This->post_data_stream)
516 nsIInputStream_Release(This->post_data_stream);
518 nsILoadGroup_Release(This->load_group);
519 if(This->notif_callback)
520 nsIInterfaceRequestor_Release(This->notif_callback);
521 if(This->original_uri)
522 nsIURI_Release(This->original_uri);
524 nsIURI_Release(This->referrer);
526 free_http_headers(&This->response_headers);
527 free_http_headers(&This->request_headers);
529 heap_free(This->content_type);
530 heap_free(This->charset);
537 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
539 nsChannel *This = impl_from_nsIHttpChannel(iface);
541 TRACE("(%p)->(%p)\n", This, aName);
543 return nsIURI_GetSpec(&This->uri->nsIURL_iface, aName);
546 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
548 nsChannel *This = impl_from_nsIHttpChannel(iface);
550 FIXME("(%p)->(%p)\n", This, _retval);
552 return NS_ERROR_NOT_IMPLEMENTED;
555 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
557 nsChannel *This = impl_from_nsIHttpChannel(iface);
559 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
561 return *aStatus = NS_OK;
564 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
566 nsChannel *This = impl_from_nsIHttpChannel(iface);
568 FIXME("(%p)->(%08x)\n", This, aStatus);
570 return NS_ERROR_NOT_IMPLEMENTED;
573 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
575 nsChannel *This = impl_from_nsIHttpChannel(iface);
577 FIXME("(%p)\n", This);
579 return NS_ERROR_NOT_IMPLEMENTED;
582 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
584 nsChannel *This = impl_from_nsIHttpChannel(iface);
586 FIXME("(%p)\n", This);
588 return NS_ERROR_NOT_IMPLEMENTED;
591 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
593 nsChannel *This = impl_from_nsIHttpChannel(iface);
595 TRACE("(%p)->(%p)\n", This, aLoadGroup);
598 nsILoadGroup_AddRef(This->load_group);
600 *aLoadGroup = This->load_group;
604 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
606 nsChannel *This = impl_from_nsIHttpChannel(iface);
608 TRACE("(%p)->(%p)\n", This, aLoadGroup);
611 nsILoadGroup_Release(This->load_group);
613 nsILoadGroup_AddRef(aLoadGroup);
614 This->load_group = aLoadGroup;
619 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
621 nsChannel *This = impl_from_nsIHttpChannel(iface);
623 TRACE("(%p)->(%p)\n", This, aLoadFlags);
625 *aLoadFlags = This->load_flags;
629 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
631 nsChannel *This = impl_from_nsIHttpChannel(iface);
633 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
635 This->load_flags = aLoadFlags;
639 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
641 nsChannel *This = impl_from_nsIHttpChannel(iface);
643 TRACE("(%p)->(%p)\n", This, aOriginalURI);
645 if(This->original_uri)
646 nsIURI_AddRef(This->original_uri);
648 *aOriginalURI = This->original_uri;
652 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
654 nsChannel *This = impl_from_nsIHttpChannel(iface);
656 TRACE("(%p)->(%p)\n", This, aOriginalURI);
658 if(This->original_uri)
659 nsIURI_Release(This->original_uri);
661 nsIURI_AddRef(aOriginalURI);
662 This->original_uri = aOriginalURI;
666 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
668 nsChannel *This = impl_from_nsIHttpChannel(iface);
670 TRACE("(%p)->(%p)\n", This, aURI);
672 nsIURI_AddRef(&This->uri->nsIURL_iface);
673 *aURI = (nsIURI*)This->uri;
678 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
680 nsChannel *This = impl_from_nsIHttpChannel(iface);
682 TRACE("(%p)->(%p)\n", This, aOwner);
685 nsISupports_AddRef(This->owner);
686 *aOwner = This->owner;
691 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
693 nsChannel *This = impl_from_nsIHttpChannel(iface);
695 TRACE("(%p)->(%p)\n", This, aOwner);
698 nsISupports_AddRef(aOwner);
700 nsISupports_Release(This->owner);
701 This->owner = aOwner;
706 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
707 nsIInterfaceRequestor **aNotificationCallbacks)
709 nsChannel *This = impl_from_nsIHttpChannel(iface);
711 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
713 if(This->notif_callback)
714 nsIInterfaceRequestor_AddRef(This->notif_callback);
715 *aNotificationCallbacks = This->notif_callback;
720 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
721 nsIInterfaceRequestor *aNotificationCallbacks)
723 nsChannel *This = impl_from_nsIHttpChannel(iface);
725 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
727 if(This->notif_callback)
728 nsIInterfaceRequestor_Release(This->notif_callback);
729 if(aNotificationCallbacks)
730 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
732 This->notif_callback = aNotificationCallbacks;
737 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
739 nsChannel *This = impl_from_nsIHttpChannel(iface);
741 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
743 return NS_ERROR_NOT_IMPLEMENTED;
746 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
748 nsChannel *This = impl_from_nsIHttpChannel(iface);
750 TRACE("(%p)->(%p)\n", This, aContentType);
752 if(This->content_type) {
753 nsACString_SetData(aContentType, This->content_type);
757 WARN("unknown type\n");
758 return NS_ERROR_FAILURE;
761 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
762 const nsACString *aContentType)
764 nsChannel *This = impl_from_nsIHttpChannel(iface);
765 const char *content_type;
767 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
769 nsACString_GetData(aContentType, &content_type);
770 heap_free(This->content_type);
771 This->content_type = heap_strdupA(content_type);
776 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
777 nsACString *aContentCharset)
779 nsChannel *This = impl_from_nsIHttpChannel(iface);
781 TRACE("(%p)->(%p)\n", This, aContentCharset);
784 nsACString_SetData(aContentCharset, This->charset);
788 nsACString_SetData(aContentCharset, "");
792 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
793 const nsACString *aContentCharset)
795 nsChannel *This = impl_from_nsIHttpChannel(iface);
797 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
799 return NS_ERROR_NOT_IMPLEMENTED;
802 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
804 nsChannel *This = impl_from_nsIHttpChannel(iface);
806 FIXME("(%p)->(%p)\n", This, aContentLength);
808 return NS_ERROR_NOT_IMPLEMENTED;
811 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
813 nsChannel *This = impl_from_nsIHttpChannel(iface);
815 FIXME("(%p)->(%d)\n", This, aContentLength);
817 return NS_ERROR_NOT_IMPLEMENTED;
820 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
822 nsChannel *This = impl_from_nsIHttpChannel(iface);
824 FIXME("(%p)->(%p)\n", This, _retval);
826 return NS_ERROR_NOT_IMPLEMENTED;
829 static HTMLWindow *get_window_from_load_group(nsChannel *This)
838 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
839 if(NS_FAILED(nsres)) {
840 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
847 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
848 nsIRequest_Release(req);
849 if(NS_FAILED(nsres)) {
850 WARN("Could not get nsIChannel interface: %08x\n", nsres);
854 nsres = nsIChannel_GetURI(channel, &uri);
855 nsIChannel_Release(channel);
856 if(NS_FAILED(nsres)) {
857 ERR("GetURI failed: %08x\n", nsres);
861 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
863 if(NS_FAILED(nsres)) {
864 TRACE("Could not get nsWineURI: %08x\n", nsres);
868 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
870 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
871 nsIURI_Release(&wine_uri->nsIURL_iface);
876 static HTMLWindow *get_channel_window(nsChannel *This)
878 nsIWebProgress *web_progress;
879 nsIDOMWindow *nswindow;
883 if(This->load_group) {
884 nsIRequestObserver *req_observer;
886 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
887 if(NS_FAILED(nsres) || !req_observer) {
888 ERR("GetGroupObserver failed: %08x\n", nsres);
892 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
893 nsIRequestObserver_Release(req_observer);
894 if(NS_FAILED(nsres)) {
895 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
898 }else if(This->notif_callback) {
899 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
900 if(NS_FAILED(nsres)) {
901 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
905 ERR("no load group nor notif callback\n");
909 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
910 nsIWebProgress_Release(web_progress);
911 if(NS_FAILED(nsres) || !nswindow) {
912 ERR("GetDOMWindow failed: %08x\n", nsres);
916 window = nswindow_to_window(nswindow);
917 nsIDOMWindow_Release(nswindow);
920 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
922 FIXME("NULL window for %p\n", nswindow);
928 HTMLDocumentNode *doc;
929 nsChannelBSC *bscallback;
930 } start_binding_task_t;
932 static void start_binding_proc(task_t *_task)
934 start_binding_task_t *task = (start_binding_task_t*)_task;
936 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
939 static void start_binding_task_destr(task_t *_task)
941 start_binding_task_t *task = (start_binding_task_t*)_task;
943 IBindStatusCallback_Release(&task->bscallback->bsc.IBindStatusCallback_iface);
947 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
948 nsISupports *context)
950 nsChannelBSC *bscallback;
951 IMoniker *mon = NULL;
954 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
956 WARN("CreateURLMoniker failed: %08x\n", hres);
957 return NS_ERROR_UNEXPECTED;
961 set_current_mon(window, mon);
963 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
964 IMoniker_Release(mon);
966 return NS_ERROR_UNEXPECTED;
968 channelbsc_set_channel(bscallback, This, listener, context);
971 set_window_bscallback(window, bscallback);
972 async_start_doc_binding(window, bscallback);
973 IUnknown_Release((IUnknown*)bscallback);
975 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
977 task->doc = window->doc;
978 task->bscallback = bscallback;
979 push_task(&task->header, start_binding_proc, start_binding_task_destr, window->doc->basedoc.task_magic);
985 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
986 nsISupports *aContext)
988 nsChannel *This = impl_from_nsIHttpChannel(iface);
989 HTMLWindow *window = NULL;
991 nsresult nsres = NS_OK;
993 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
995 if(!ensure_uri(This->uri))
996 return NS_ERROR_FAILURE;
998 if(TRACE_ON(mshtml)) {
1000 IUri_GetDisplayUri(This->uri->uri, &uri_str);
1001 TRACE("opening %s\n", debugstr_w(uri_str));
1002 SysFreeString(uri_str);
1005 if(This->uri->is_doc_uri) {
1006 window = get_channel_window(This);
1008 set_uri_window(This->uri, window);
1009 }else if(This->uri->container) {
1012 /* nscontainer->doc should be NULL which means navigation to a new window */
1013 if(This->uri->container->doc)
1014 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
1016 nsres = before_async_open(This, This->uri->container, &b);
1017 if(NS_FAILED(nsres))
1020 FIXME("Navigation not cancelled\n");
1021 return NS_ERROR_UNEXPECTED;
1026 if(This->uri->window_ref && This->uri->window_ref->window) {
1027 window = This->uri->window_ref->window;
1028 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
1030 /* FIXME: Analyze removing get_window_from_load_group call */
1031 if(This->load_group)
1032 window = get_window_from_load_group(This);
1034 window = get_channel_window(This);
1036 set_uri_window(This->uri, window);
1041 ERR("window = NULL\n");
1042 return NS_ERROR_UNEXPECTED;
1045 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1046 if(This->uri->channel_bsc) {
1047 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1049 if(window->doc_obj->mime) {
1050 heap_free(This->content_type);
1051 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1056 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
1057 if(NS_SUCCEEDED(nsres) && cancel) {
1058 TRACE("canceled\n");
1059 nsres = NS_BINDING_ABORTED;
1065 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1067 if(NS_SUCCEEDED(nsres) && This->load_group) {
1068 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1070 if(NS_FAILED(nsres))
1071 ERR("AddRequest failed: %08x\n", nsres);
1074 IHTMLWindow2_Release(&window->IHTMLWindow2_iface);
1078 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1080 nsChannel *This = impl_from_nsIHttpChannel(iface);
1082 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1084 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1088 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1089 const nsACString *aRequestMethod)
1091 nsChannel *This = impl_from_nsIHttpChannel(iface);
1095 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1097 nsACString_GetData(aRequestMethod, &method);
1098 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1099 if(!strcasecmp(method, request_method_strings[i])) {
1100 This->request_method = i;
1105 ERR("Invalid method %s\n", debugstr_a(method));
1106 return NS_ERROR_UNEXPECTED;
1109 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1111 nsChannel *This = impl_from_nsIHttpChannel(iface);
1113 TRACE("(%p)->(%p)\n", This, aReferrer);
1116 nsIURI_AddRef(This->referrer);
1117 *aReferrer = This->referrer;
1121 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1123 nsChannel *This = impl_from_nsIHttpChannel(iface);
1125 TRACE("(%p)->(%p)\n", This, aReferrer);
1128 nsIURI_AddRef(aReferrer);
1130 nsIURI_Release(This->referrer);
1131 This->referrer = aReferrer;
1135 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1136 const nsACString *aHeader, nsACString *_retval)
1138 nsChannel *This = impl_from_nsIHttpChannel(iface);
1140 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1142 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1145 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1146 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
1148 nsChannel *This = impl_from_nsIHttpChannel(iface);
1150 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1153 FIXME("aMerge not supported\n");
1155 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1158 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1159 nsIHttpHeaderVisitor *aVisitor)
1161 nsChannel *This = impl_from_nsIHttpChannel(iface);
1163 FIXME("(%p)->(%p)\n", This, aVisitor);
1165 return NS_ERROR_NOT_IMPLEMENTED;
1168 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1170 nsChannel *This = impl_from_nsIHttpChannel(iface);
1172 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1174 return NS_ERROR_NOT_IMPLEMENTED;
1177 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1179 nsChannel *This = impl_from_nsIHttpChannel(iface);
1181 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1183 return NS_ERROR_NOT_IMPLEMENTED;
1186 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1188 nsChannel *This = impl_from_nsIHttpChannel(iface);
1190 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1192 return NS_ERROR_NOT_IMPLEMENTED;
1195 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1197 nsChannel *This = impl_from_nsIHttpChannel(iface);
1199 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1201 return NS_ERROR_NOT_IMPLEMENTED;
1204 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1206 nsChannel *This = impl_from_nsIHttpChannel(iface);
1208 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1210 if(This->response_status) {
1211 *aResponseStatus = This->response_status;
1215 WARN("No response status\n");
1216 return NS_ERROR_UNEXPECTED;
1219 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1220 nsACString *aResponseStatusText)
1222 nsChannel *This = impl_from_nsIHttpChannel(iface);
1224 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1226 return NS_ERROR_NOT_IMPLEMENTED;
1229 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1230 PRBool *aRequestSucceeded)
1232 nsChannel *This = impl_from_nsIHttpChannel(iface);
1234 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1236 if(!This->response_status)
1237 return NS_ERROR_NOT_AVAILABLE;
1239 *aRequestSucceeded = This->response_status/100 == 2;
1244 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1245 const nsACString *header, nsACString *_retval)
1247 nsChannel *This = impl_from_nsIHttpChannel(iface);
1249 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1251 return get_channel_http_header(&This->response_headers, header, _retval);
1254 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1255 const nsACString *header, const nsACString *value, PRBool merge)
1257 nsChannel *This = impl_from_nsIHttpChannel(iface);
1259 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1261 return NS_ERROR_NOT_IMPLEMENTED;
1264 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1265 nsIHttpHeaderVisitor *aVisitor)
1267 nsChannel *This = impl_from_nsIHttpChannel(iface);
1269 TRACE("(%p)->(%p)\n", This, aVisitor);
1271 return visit_http_headers(&This->response_headers, aVisitor);
1274 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1276 nsChannel *This = impl_from_nsIHttpChannel(iface);
1277 http_header_t *header;
1279 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1280 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1282 TRACE("(%p)->(%p)\n", This, _retval);
1284 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1285 *_retval = header && !strcmpiW(header->data, no_storeW);
1289 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1291 nsChannel *This = impl_from_nsIHttpChannel(iface);
1293 FIXME("(%p)->(%p)\n", This, _retval);
1295 return NS_ERROR_NOT_IMPLEMENTED;
1298 static const nsIHttpChannelVtbl nsChannelVtbl = {
1299 nsChannel_QueryInterface,
1303 nsChannel_IsPending,
1304 nsChannel_GetStatus,
1308 nsChannel_GetLoadGroup,
1309 nsChannel_SetLoadGroup,
1310 nsChannel_GetLoadFlags,
1311 nsChannel_SetLoadFlags,
1312 nsChannel_GetOriginalURI,
1313 nsChannel_SetOriginalURI,
1317 nsChannel_GetNotificationCallbacks,
1318 nsChannel_SetNotificationCallbacks,
1319 nsChannel_GetSecurityInfo,
1320 nsChannel_GetContentType,
1321 nsChannel_SetContentType,
1322 nsChannel_GetContentCharset,
1323 nsChannel_SetContentCharset,
1324 nsChannel_GetContentLength,
1325 nsChannel_SetContentLength,
1327 nsChannel_AsyncOpen,
1328 nsChannel_GetRequestMethod,
1329 nsChannel_SetRequestMethod,
1330 nsChannel_GetReferrer,
1331 nsChannel_SetReferrer,
1332 nsChannel_GetRequestHeader,
1333 nsChannel_SetRequestHeader,
1334 nsChannel_VisitRequestHeaders,
1335 nsChannel_GetAllowPipelining,
1336 nsChannel_SetAllowPipelining,
1337 nsChannel_GetRedirectionLimit,
1338 nsChannel_SetRedirectionLimit,
1339 nsChannel_GetResponseStatus,
1340 nsChannel_GetResponseStatusText,
1341 nsChannel_GetRequestSucceeded,
1342 nsChannel_GetResponseHeader,
1343 nsChannel_SetResponseHeader,
1344 nsChannel_VisitResponseHeaders,
1345 nsChannel_IsNoStoreResponse,
1346 nsChannel_IsNoCacheResponse
1349 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1351 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1354 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1357 nsChannel *This = impl_from_nsIUploadChannel(iface);
1358 return nsIChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1361 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1363 nsChannel *This = impl_from_nsIUploadChannel(iface);
1364 return nsIChannel_AddRef(&This->nsIHttpChannel_iface);
1367 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1369 nsChannel *This = impl_from_nsIUploadChannel(iface);
1370 return nsIChannel_Release(&This->nsIHttpChannel_iface);
1373 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1374 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1376 nsChannel *This = impl_from_nsIUploadChannel(iface);
1377 const char *content_type;
1379 static const WCHAR content_typeW[] =
1380 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1382 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1384 This->post_data_contains_headers = TRUE;
1387 nsACString_GetData(aContentType, &content_type);
1391 ct = heap_strdupAtoW(content_type);
1393 return NS_ERROR_UNEXPECTED;
1395 set_http_header(&This->request_headers, content_typeW,
1396 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1398 This->post_data_contains_headers = FALSE;
1402 if(This->post_data_stream)
1403 nsIInputStream_Release(This->post_data_stream);
1405 if(aContentLength != -1)
1406 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1408 if(This->post_data_stream)
1409 nsIInputStream_Release(This->post_data_stream);
1410 This->post_data_stream = aStream;
1412 nsIInputStream_AddRef(aStream);
1414 This->request_method = METHOD_POST;
1418 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1419 nsIInputStream **aUploadStream)
1421 nsChannel *This = impl_from_nsIUploadChannel(iface);
1423 TRACE("(%p)->(%p)\n", This, aUploadStream);
1425 if(This->post_data_stream)
1426 nsIInputStream_AddRef(This->post_data_stream);
1428 *aUploadStream = This->post_data_stream;
1432 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1433 nsUploadChannel_QueryInterface,
1434 nsUploadChannel_AddRef,
1435 nsUploadChannel_Release,
1436 nsUploadChannel_SetUploadStream,
1437 nsUploadChannel_GetUploadStream
1440 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1442 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1445 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1448 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1449 return nsIChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1452 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1454 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1455 return nsIChannel_AddRef(&This->nsIHttpChannel_iface);
1458 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1460 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1461 return nsIChannel_Release(&This->nsIHttpChannel_iface);
1464 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1466 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1468 FIXME("(%p)->()\n", This);
1470 return NS_ERROR_NOT_IMPLEMENTED;
1473 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1475 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1477 FIXME("(%p)->()\n", This);
1479 return NS_ERROR_NOT_IMPLEMENTED;
1482 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1484 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1486 FIXME("(%p)->()\n", This);
1488 return NS_ERROR_NOT_IMPLEMENTED;
1491 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1493 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1495 FIXME("(%p)->()\n", This);
1497 return NS_ERROR_NOT_IMPLEMENTED;
1500 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1502 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1504 FIXME("(%p)->()\n", This);
1506 return NS_ERROR_NOT_IMPLEMENTED;
1509 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1511 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1513 FIXME("(%p)->()\n", This);
1515 return NS_ERROR_NOT_IMPLEMENTED;
1518 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1520 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1522 FIXME("(%p)->()\n", This);
1524 return NS_ERROR_NOT_IMPLEMENTED;
1527 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1529 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1531 FIXME("(%p)->()\n", This);
1533 return NS_ERROR_NOT_IMPLEMENTED;
1536 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, PRBool *aCanceled)
1538 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1540 FIXME("(%p)->(%p)\n", This, aCanceled);
1542 return NS_ERROR_NOT_IMPLEMENTED;
1545 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, PRBool *aCanceled)
1547 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1549 FIXME("(%p)->(%p)\n", This, aCanceled);
1551 return NS_ERROR_NOT_IMPLEMENTED;
1554 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, PRBool aCanceled)
1556 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1558 FIXME("(%p)->(%x)\n", This, aCanceled);
1560 return NS_ERROR_NOT_IMPLEMENTED;
1563 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1565 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1567 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1569 return NS_ERROR_NOT_IMPLEMENTED;
1572 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, PRInt32 *aLocalPort)
1574 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1576 FIXME("(%p)->(%p)\n", This, aLocalPort);
1578 return NS_ERROR_NOT_IMPLEMENTED;
1581 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1583 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1585 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1587 return NS_ERROR_NOT_IMPLEMENTED;
1590 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, PRInt32 *aRemotePort)
1592 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1594 FIXME("(%p)->(%p)\n", This, aRemotePort);
1596 return NS_ERROR_NOT_IMPLEMENTED;
1599 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1601 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1603 FIXME("(%p)->(%p)\n", This, cacheKeys);
1605 return NS_ERROR_NOT_IMPLEMENTED;
1608 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1609 nsHttpChannelInternal_QueryInterface,
1610 nsHttpChannelInternal_AddRef,
1611 nsHttpChannelInternal_Release,
1612 nsHttpChannelInternal_GetDocumentURI,
1613 nsHttpChannelInternal_SetDocumentURI,
1614 nsHttpChannelInternal_GetRequestVersion,
1615 nsHttpChannelInternal_GetResponseVersion,
1616 nsHttpChannelInternal_SetCookie,
1617 nsHttpChannelInternal_SetupFallbackChannel,
1618 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1619 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1620 nsHttpChannelInternal_GetCanceled,
1621 nsHttpChannelInternal_GetChannelIsForDownload,
1622 nsHttpChannelInternal_SetChannelIsForDownload,
1623 nsHttpChannelInternal_GetLocalAddress,
1624 nsHttpChannelInternal_GetLocalPort,
1625 nsHttpChannelInternal_GetRemoteAddress,
1626 nsHttpChannelInternal_GetRemotePort,
1627 nsHttpChannelInternal_SetCacheKeysRedirectChain
1631 static void invalidate_uri(nsWineURI *This)
1634 IUri_Release(This->uri);
1639 static BOOL ensure_uri_builder(nsWineURI *This)
1641 if(!This->uri_builder) {
1644 if(!ensure_uri(This))
1647 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1649 WARN("CreateIUriBuilder failed: %08x\n", hres);
1654 invalidate_uri(This);
1658 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1664 if(!ensure_uri(This))
1665 return NS_ERROR_UNEXPECTED;
1667 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1669 WARN("GetPropertyBSTR failed: %08x\n", hres);
1670 return NS_ERROR_UNEXPECTED;
1673 vala = heap_strdupWtoA(val);
1676 return NS_ERROR_OUT_OF_MEMORY;
1678 TRACE("ret %s\n", debugstr_a(vala));
1679 nsACString_SetData(ret, vala);
1684 static inline nsWineURI *impl_from_nsIURL(nsIURL *iface)
1686 return CONTAINING_RECORD(iface, nsWineURI, nsIURL_iface);
1689 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, void **result)
1691 nsWineURI *This = impl_from_nsIURL(iface);
1695 if(IsEqualGUID(&IID_nsISupports, riid)) {
1696 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1697 *result = &This->nsIURL_iface;
1698 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1699 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1700 *result = &This->nsIURL_iface;
1701 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1702 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1703 *result = &This->nsIURL_iface;
1704 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1705 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1710 nsIURI_AddRef(&This->nsIURL_iface);
1714 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1715 return This->nsuri ? nsIURI_QueryInterface(This->nsuri, riid, result) : NS_NOINTERFACE;
1718 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1720 nsWineURI *This = impl_from_nsIURL(iface);
1721 LONG ref = InterlockedIncrement(&This->ref);
1723 TRACE("(%p) ref=%d\n", This, ref);
1728 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1730 nsWineURI *This = impl_from_nsIURL(iface);
1731 LONG ref = InterlockedDecrement(&This->ref);
1733 TRACE("(%p) ref=%d\n", This, ref);
1736 if(This->window_ref)
1737 windowref_release(This->window_ref);
1739 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1741 nsIURL_Release(This->nsurl);
1743 nsIURI_Release(This->nsuri);
1745 IUri_Release(This->uri);
1752 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1754 nsWineURI *This = impl_from_nsIURL(iface);
1756 TRACE("(%p)->(%p)\n", This, aSpec);
1758 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1761 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1763 nsWineURI *This = impl_from_nsIURL(iface);
1769 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1771 nsACString_GetData(aSpec, &speca);
1772 spec = heap_strdupAtoW(speca);
1774 return NS_ERROR_OUT_OF_MEMORY;
1776 hres = CreateUri(spec, 0, 0, &uri);
1779 WARN("CreateUri failed: %08x\n", hres);
1780 return NS_ERROR_FAILURE;
1783 invalidate_uri(This);
1784 if(This->uri_builder) {
1785 IUriBuilder_Release(This->uri_builder);
1786 This->uri_builder = NULL;
1793 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1795 nsWineURI *This = impl_from_nsIURL(iface);
1797 TRACE("(%p)->(%p)\n", This, aPrePath);
1800 return nsIURI_GetPrePath(This->nsuri, aPrePath);
1802 FIXME("default action not implemented\n");
1803 return NS_ERROR_NOT_IMPLEMENTED;
1806 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1808 nsWineURI *This = impl_from_nsIURL(iface);
1812 TRACE("(%p)->(%p)\n", This, aScheme);
1814 if(!ensure_uri(This))
1815 return NS_ERROR_UNEXPECTED;
1817 hres = IUri_GetScheme(This->uri, &scheme);
1819 WARN("GetScheme failed: %08x\n", hres);
1820 return NS_ERROR_UNEXPECTED;
1823 if(scheme == URL_SCHEME_ABOUT) {
1824 nsACString_SetData(aScheme, "wine");
1828 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1831 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1833 nsWineURI *This = impl_from_nsIURL(iface);
1834 const char *schemea;
1838 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1840 if(!ensure_uri_builder(This))
1841 return NS_ERROR_UNEXPECTED;
1843 nsACString_GetData(aScheme, &schemea);
1844 scheme = heap_strdupAtoW(schemea);
1846 return NS_ERROR_OUT_OF_MEMORY;
1848 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
1851 return NS_ERROR_UNEXPECTED;
1856 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1858 nsWineURI *This = impl_from_nsIURL(iface);
1862 TRACE("(%p)->(%p)\n", This, aUserPass);
1864 if(!ensure_uri(This))
1865 return NS_ERROR_UNEXPECTED;
1867 hres = IUri_GetUserName(This->uri, &user);
1869 return NS_ERROR_FAILURE;
1871 hres = IUri_GetPassword(This->uri, &pass);
1873 SysFreeString(user);
1874 return NS_ERROR_FAILURE;
1877 if(*user || *pass) {
1878 FIXME("Construct user:pass string\n");
1880 nsACString_SetData(aUserPass, "");
1883 SysFreeString(user);
1884 SysFreeString(pass);
1888 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1890 nsWineURI *This = impl_from_nsIURL(iface);
1891 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
1892 const char *user_pass;
1895 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
1897 if(!ensure_uri_builder(This))
1898 return NS_ERROR_UNEXPECTED;
1900 nsACString_GetData(aUserPass, &user_pass);
1904 buf = heap_strdupAtoW(user_pass);
1906 return NS_ERROR_OUT_OF_MEMORY;
1908 ptr = strchrW(buf, ':');
1911 }else if(ptr != buf) {
1921 hres = IUriBuilder_SetUserName(This->uri_builder, user);
1923 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
1926 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
1929 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1931 nsWineURI *This = impl_from_nsIURL(iface);
1933 TRACE("(%p)->(%p)\n", This, aUsername);
1935 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
1938 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1940 nsWineURI *This = impl_from_nsIURL(iface);
1945 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
1947 if(!ensure_uri_builder(This))
1948 return NS_ERROR_UNEXPECTED;
1950 nsACString_GetData(aUsername, &usera);
1951 user = heap_strdupAtoW(usera);
1953 return NS_ERROR_OUT_OF_MEMORY;
1955 hres = IUriBuilder_SetUserName(This->uri_builder, user);
1958 return NS_ERROR_UNEXPECTED;
1963 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1965 nsWineURI *This = impl_from_nsIURL(iface);
1967 TRACE("(%p)->(%p)\n", This, aPassword);
1969 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
1972 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1974 nsWineURI *This = impl_from_nsIURL(iface);
1979 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
1981 if(!ensure_uri_builder(This))
1982 return NS_ERROR_UNEXPECTED;
1984 nsACString_GetData(aPassword, &passa);
1985 pass = heap_strdupAtoW(passa);
1987 return NS_ERROR_OUT_OF_MEMORY;
1989 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
1992 return NS_ERROR_UNEXPECTED;
1997 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1999 nsWineURI *This = impl_from_nsIURL(iface);
2005 TRACE("(%p)->(%p)\n", This, aHostPort);
2007 if(!ensure_uri(This))
2008 return NS_ERROR_UNEXPECTED;
2010 hres = IUri_GetAuthority(This->uri, &val);
2012 WARN("GetAuthority failed: %08x\n", hres);
2013 return NS_ERROR_UNEXPECTED;
2016 ptr = strchrW(val, '@');
2020 vala = heap_strdupWtoA(ptr);
2023 return NS_ERROR_OUT_OF_MEMORY;
2025 TRACE("ret %s\n", debugstr_a(vala));
2026 nsACString_SetData(aHostPort, vala);
2031 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
2033 nsWineURI *This = impl_from_nsIURL(iface);
2035 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2037 /* Not implemented by Gecko */
2038 return NS_ERROR_NOT_IMPLEMENTED;
2041 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
2043 nsWineURI *This = impl_from_nsIURL(iface);
2045 TRACE("(%p)->(%p)\n", This, aHost);
2047 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2050 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
2052 nsWineURI *This = impl_from_nsIURL(iface);
2057 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2059 if(!ensure_uri_builder(This))
2060 return NS_ERROR_UNEXPECTED;
2062 nsACString_GetData(aHost, &hosta);
2063 host = heap_strdupAtoW(hosta);
2065 return NS_ERROR_OUT_OF_MEMORY;
2067 hres = IUriBuilder_SetHost(This->uri_builder, host);
2070 return NS_ERROR_UNEXPECTED;
2075 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
2077 nsWineURI *This = impl_from_nsIURL(iface);
2081 TRACE("(%p)->(%p)\n", This, aPort);
2083 if(!ensure_uri(This))
2084 return NS_ERROR_UNEXPECTED;
2086 hres = IUri_GetPort(This->uri, &port);
2088 WARN("GetPort failed: %08x\n", hres);
2089 return NS_ERROR_UNEXPECTED;
2092 *aPort = port ? port : -1;
2096 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
2098 nsWineURI *This = impl_from_nsIURL(iface);
2101 TRACE("(%p)->(%d)\n", This, aPort);
2103 if(!ensure_uri_builder(This))
2104 return NS_ERROR_UNEXPECTED;
2106 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2107 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2110 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
2112 nsWineURI *This = impl_from_nsIURL(iface);
2114 TRACE("(%p)->(%p)\n", This, aPath);
2116 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2119 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
2121 nsWineURI *This = impl_from_nsIURL(iface);
2126 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2128 if(!ensure_uri_builder(This))
2129 return NS_ERROR_UNEXPECTED;
2131 nsACString_GetData(aPath, &patha);
2132 path = heap_strdupAtoW(patha);
2134 return NS_ERROR_OUT_OF_MEMORY;
2136 hres = IUriBuilder_SetPath(This->uri_builder, path);
2139 return NS_ERROR_UNEXPECTED;
2144 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
2146 nsWineURI *This = impl_from_nsIURL(iface);
2151 TRACE("(%p)->(%p)\n", This, aRef);
2153 if(!ensure_uri(This))
2154 return NS_ERROR_UNEXPECTED;
2156 hres = IUri_GetFragment(This->uri, &ref);
2158 return NS_ERROR_UNEXPECTED;
2160 refa = heap_strdupWtoA(ref);
2163 return NS_ERROR_OUT_OF_MEMORY;
2165 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2170 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
2172 nsWineURI *This = impl_from_nsIURL(iface);
2177 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2179 if(!ensure_uri_builder(This))
2180 return NS_ERROR_UNEXPECTED;
2182 nsACString_GetData(aRef, &refa);
2183 ref = heap_strdupAtoW(refa);
2185 return NS_ERROR_OUT_OF_MEMORY;
2187 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2190 return NS_ERROR_UNEXPECTED;
2195 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
2197 nsWineURI *This = impl_from_nsIURL(iface);
2198 nsWineURI *other_obj;
2202 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2204 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2205 if(NS_FAILED(nsres)) {
2206 TRACE("Could not get nsWineURI interface\n");
2211 if(ensure_uri(This) && ensure_uri(other_obj)) {
2212 hres = IUri_IsEqual(This->uri, other_obj->uri, _retval);
2213 nsres = SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2215 nsres = NS_ERROR_UNEXPECTED;
2218 nsIURI_Release(&other_obj->nsIURL_iface);
2222 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
2224 nsWineURI *This = impl_from_nsIURL(iface);
2225 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2229 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2231 if(!ensure_uri(This))
2232 return NS_ERROR_UNEXPECTED;
2234 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2236 return NS_ERROR_UNEXPECTED;
2238 MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2239 *_retval = !strcmpW(scheme_name, buf);
2240 SysFreeString(scheme_name);
2244 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
2246 nsWineURI *This = impl_from_nsIURL(iface);
2247 nsIURI *nsuri = NULL;
2248 nsWineURI *wine_uri;
2251 TRACE("(%p)->(%p)\n", This, _retval);
2253 if(!ensure_uri(This))
2254 return NS_ERROR_UNEXPECTED;
2257 nsres = nsIURI_Clone(This->nsuri, &nsuri);
2258 if(NS_FAILED(nsres)) {
2259 WARN("Clone failed: %08x\n", nsres);
2264 nsres = create_nsuri(This->uri, nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2265 if(NS_FAILED(nsres)) {
2266 WARN("create_nsuri failed: %08x\n", nsres);
2270 *_retval = (nsIURI*)&wine_uri->nsIURL_iface;
2274 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *aRelativePath,
2275 nsACString *_retval)
2277 nsWineURI *This = impl_from_nsIURL(iface);
2285 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2287 if(!ensure_uri(This))
2288 return NS_ERROR_UNEXPECTED;
2290 nsACString_GetData(aRelativePath, &patha);
2291 path = heap_strdupAtoW(patha);
2293 return NS_ERROR_OUT_OF_MEMORY;
2295 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2298 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2299 return NS_ERROR_FAILURE;
2302 hres = IUri_GetDisplayUri(new_uri, &ret);
2303 IUri_Release(new_uri);
2305 return NS_ERROR_FAILURE;
2307 reta = heap_strdupWtoA(ret);
2310 return NS_ERROR_OUT_OF_MEMORY;
2312 TRACE("returning %s\n", debugstr_a(reta));
2313 nsACString_SetData(_retval, reta);
2318 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
2320 nsWineURI *This = impl_from_nsIURL(iface);
2322 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2324 return nsIURI_GetSpec(&This->nsIURL_iface, aAsciiSpec);
2327 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
2329 nsWineURI *This = impl_from_nsIURL(iface);
2331 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2333 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2336 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
2338 nsWineURI *This = impl_from_nsIURL(iface);
2340 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2343 return nsIURI_GetOriginCharset(This->nsuri, aOriginCharset);
2345 FIXME("default action not implemented\n");
2346 return NS_ERROR_NOT_IMPLEMENTED;
2349 static nsresult NSAPI nsURI_EqualsExceptRef(nsIURL *iface, nsIURI *other, PRBool *_retval)
2351 nsWineURI *This = impl_from_nsIURL(iface);
2352 nsWineURI *other_obj;
2355 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2357 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2358 if(NS_FAILED(nsres)) {
2359 TRACE("Could not get nsWineURI interface\n");
2364 if(ensure_uri(This) && ensure_uri(other_obj)) {
2365 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2368 nsres = NS_ERROR_UNEXPECTED;
2371 nsIURI_Release(&other_obj->nsIURL_iface);
2375 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIURL *iface, nsIURI **_retval)
2377 nsWineURI *This = impl_from_nsIURL(iface);
2378 nsWineURI *wine_uri;
2382 TRACE("(%p)->(%p)\n", This, _retval);
2384 if(!ensure_uri(This))
2385 return NS_ERROR_UNEXPECTED;
2387 uri = get_uri_nofrag(This->uri);
2389 return NS_ERROR_FAILURE;
2391 nsres = create_nsuri(uri, NULL, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2393 if(NS_FAILED(nsres)) {
2394 WARN("create_nsuri failed: %08x\n", nsres);
2398 *_retval = (nsIURI*)&wine_uri->nsIURL_iface;
2402 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIURL *iface, nsACString *aSpecIgnoringRef)
2404 nsWineURI *This = impl_from_nsIURL(iface);
2406 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2408 return nsIURL_GetSpec(&This->nsIURL_iface, aSpecIgnoringRef);
2411 static nsresult NSAPI nsURI_GetHasRef(nsIURL *iface, PRBool *aHasRef)
2413 nsWineURI *This = impl_from_nsIURL(iface);
2417 TRACE("(%p)->(%p)\n", This, aHasRef);
2419 if(!ensure_uri(This))
2420 return NS_ERROR_UNEXPECTED;
2422 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2424 return NS_ERROR_FAILURE;
2430 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
2432 nsWineURI *This = impl_from_nsIURL(iface);
2434 TRACE("(%p)->(%p)\n", This, aFilePath);
2436 return nsIURL_GetPath(&This->nsIURL_iface, aFilePath);
2439 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
2441 nsWineURI *This = impl_from_nsIURL(iface);
2443 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2445 return nsIURL_SetPath(&This->nsIURL_iface, aFilePath);
2448 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
2450 nsWineURI *This = impl_from_nsIURL(iface);
2452 WARN("(%p)->(%p)\n", This, aParam);
2454 /* This is a leftover of ';' special handling in URLs. It will be removed from Gecko soon */
2455 nsACString_SetData(aParam, "");
2459 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
2461 nsWineURI *This = impl_from_nsIURL(iface);
2463 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
2465 /* Not implemented by Gecko */
2466 return NS_ERROR_NOT_IMPLEMENTED;
2469 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
2471 nsWineURI *This = impl_from_nsIURL(iface);
2473 TRACE("(%p)->(%p)\n", This, aQuery);
2475 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2478 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
2480 nsWineURI *This = impl_from_nsIURL(iface);
2485 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2487 if(!ensure_uri_builder(This))
2488 return NS_ERROR_UNEXPECTED;
2490 nsACString_GetData(aQuery, &querya);
2491 query = heap_strdupAtoW(querya);
2493 return NS_ERROR_OUT_OF_MEMORY;
2495 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2498 return NS_ERROR_UNEXPECTED;
2503 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
2505 nsWineURI *This = impl_from_nsIURL(iface);
2511 TRACE("(%p)->(%p)\n", This, aDirectory);
2513 if(!ensure_uri(This))
2514 return NS_ERROR_UNEXPECTED;
2516 hres = IUri_GetPath(This->uri, &path);
2518 return NS_ERROR_FAILURE;
2520 ptr = strrchrW(path, '/');
2524 dir = heap_strdupWtoA(path);
2526 SysFreeString(path);
2527 return NS_ERROR_OUT_OF_MEMORY;
2531 SysFreeString(path);
2532 TRACE("ret %s\n", debugstr_a(dir));
2533 nsACString_SetData(aDirectory, dir ? dir : "");
2538 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2540 nsWineURI *This = impl_from_nsIURL(iface);
2542 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2544 /* Not implemented by Gecko */
2545 return NS_ERROR_NOT_IMPLEMENTED;
2548 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2550 nsWineURI *This = impl_from_nsIURL(iface);
2552 TRACE("(%p)->(%p)\n", This, aFileName);
2555 return nsIURL_GetFileName(This->nsurl, aFileName);
2557 FIXME("default action not implemented\n");
2558 return NS_ERROR_NOT_IMPLEMENTED;
2561 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2563 nsWineURI *This = impl_from_nsIURL(iface);
2565 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2568 invalidate_uri(This);
2569 return nsIURL_SetFileName(This->nsurl, aFileName);
2572 FIXME("default action not implemented\n");
2573 return NS_ERROR_NOT_IMPLEMENTED;
2576 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2578 nsWineURI *This = impl_from_nsIURL(iface);
2580 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2583 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2585 FIXME("default action not implemented\n");
2586 return NS_ERROR_NOT_IMPLEMENTED;
2589 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2591 nsWineURI *This = impl_from_nsIURL(iface);
2593 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2596 invalidate_uri(This);
2597 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2600 FIXME("default action not implemented\n");
2601 return NS_ERROR_NOT_IMPLEMENTED;
2604 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2606 nsWineURI *This = impl_from_nsIURL(iface);
2608 TRACE("(%p)->(%p)\n", This, aFileExtension);
2610 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
2613 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2615 nsWineURI *This = impl_from_nsIURL(iface);
2617 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2620 invalidate_uri(This);
2621 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2624 FIXME("default action not implemented\n");
2625 return NS_ERROR_NOT_IMPLEMENTED;
2628 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2630 nsWineURI *This = impl_from_nsIURL(iface);
2632 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2635 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2637 FIXME("default action not implemented\n");
2638 return NS_ERROR_NOT_IMPLEMENTED;
2641 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2643 nsWineURI *This = impl_from_nsIURL(iface);
2645 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2648 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2650 FIXME("default action not implemented\n");
2651 return NS_ERROR_NOT_IMPLEMENTED;
2654 static const nsIURLVtbl nsURLVtbl = {
2655 nsURI_QueryInterface,
2683 nsURI_GetOriginCharset,
2686 nsURI_EqualsExceptRef,
2687 nsURI_CloneIgnoreRef,
2688 nsURI_GetSpecIgnoringRef,
2700 nsURL_GetFileBaseName,
2701 nsURL_SetFileBaseName,
2702 nsURL_GetFileExtension,
2703 nsURL_SetFileExtension,
2704 nsURL_GetCommonBaseSpec,
2705 nsURL_GetRelativeSpec
2708 static nsresult create_nsuri(IUri *iuri, nsIURI *nsuri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2710 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2712 ret->nsIURL_iface.lpVtbl = &nsURLVtbl;
2716 set_uri_nscontainer(ret, container);
2717 set_uri_window(ret, window);
2723 nsIURI_QueryInterface(nsuri, &IID_nsIURL, (void**)&ret->nsurl);
2725 TRACE("retval=%p\n", ret);
2730 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2737 hres = CreateUri(url, 0, 0, &iuri);
2741 nsres = create_nsuri(iuri, NULL, window, window->doc_obj->nscontainer, &uri);
2743 if(NS_FAILED(nsres))
2746 uri->is_doc_uri = TRUE;
2752 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2757 if(!ensure_uri(uri))
2758 return NS_ERROR_UNEXPECTED;
2760 channel = heap_alloc_zero(sizeof(nsChannel));
2762 return NS_ERROR_OUT_OF_MEMORY;
2764 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2765 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2766 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2768 channel->request_method = METHOD_GET;
2769 list_init(&channel->response_headers);
2770 list_init(&channel->request_headers);
2772 nsIURL_AddRef(&uri->nsIURL_iface);
2775 hres = IUri_GetScheme(uri->uri, &channel->url_scheme);
2777 channel->url_scheme = URL_SCHEME_UNKNOWN;
2783 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
2785 HTMLWindow *window = NULL;
2792 hres = CreateUri(url, 0, 0, &iuri);
2796 if(orig_channel->uri->window_ref)
2797 window = orig_channel->uri->window_ref->window;
2798 nsres = create_nsuri(iuri, NULL, window, NULL, &uri);
2800 if(NS_FAILED(nsres))
2803 nsres = create_nschannel(uri, &channel);
2804 nsIURL_Release(&uri->nsIURL_iface);
2805 if(NS_FAILED(nsres))
2808 if(orig_channel->load_group) {
2809 nsILoadGroup_AddRef(orig_channel->load_group);
2810 channel->load_group = orig_channel->load_group;
2813 if(orig_channel->notif_callback) {
2814 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
2815 channel->notif_callback = orig_channel->notif_callback;
2818 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
2820 if(orig_channel->request_method == METHOD_POST)
2821 FIXME("unsupported POST method\n");
2823 if(orig_channel->original_uri) {
2824 nsIURI_AddRef(orig_channel->original_uri);
2825 channel->original_uri = orig_channel->original_uri;
2828 if(orig_channel->referrer) {
2829 nsIURI_AddRef(orig_channel->referrer);
2830 channel->referrer = orig_channel->referrer;
2838 nsIProtocolHandler nsIProtocolHandler_iface;
2842 nsIProtocolHandler *nshandler;
2843 } nsProtocolHandler;
2845 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
2847 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
2850 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2853 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2857 if(IsEqualGUID(&IID_nsISupports, riid)) {
2858 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2859 *result = &This->nsIProtocolHandler_iface;
2860 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2861 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2862 *result = &This->nsIProtocolHandler_iface;
2863 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2864 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2865 return NS_NOINTERFACE;
2869 nsISupports_AddRef((nsISupports*)*result);
2873 WARN("(%s %p)\n", debugstr_guid(riid), result);
2874 return NS_NOINTERFACE;
2877 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2879 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2880 LONG ref = InterlockedIncrement(&This->ref);
2882 TRACE("(%p) ref=%d\n", This, ref);
2887 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2889 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2890 LONG ref = InterlockedDecrement(&This->ref);
2892 TRACE("(%p) ref=%d\n", This, ref);
2896 nsIProtocolHandler_Release(This->nshandler);
2903 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2905 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2907 TRACE("(%p)->(%p)\n", This, aScheme);
2910 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2911 return NS_ERROR_NOT_IMPLEMENTED;
2914 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2915 PRInt32 *aDefaultPort)
2917 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2919 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2922 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2923 return NS_ERROR_NOT_IMPLEMENTED;
2926 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2927 PRUint32 *aProtocolFlags)
2929 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2931 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2934 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2935 return NS_ERROR_NOT_IMPLEMENTED;
2938 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2939 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2941 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2943 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2947 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2948 return NS_ERROR_NOT_IMPLEMENTED;
2951 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2952 nsIURI *aURI, nsIChannel **_retval)
2954 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2956 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2959 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2960 return NS_ERROR_NOT_IMPLEMENTED;
2963 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2964 PRInt32 port, const char *scheme, PRBool *_retval)
2966 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2968 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2971 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2972 return NS_ERROR_NOT_IMPLEMENTED;
2975 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2976 nsProtocolHandler_QueryInterface,
2977 nsProtocolHandler_AddRef,
2978 nsProtocolHandler_Release,
2979 nsProtocolHandler_GetScheme,
2980 nsProtocolHandler_GetDefaultPort,
2981 nsProtocolHandler_GetProtocolFlags,
2982 nsProtocolHandler_NewURI,
2983 nsProtocolHandler_NewChannel,
2984 nsProtocolHandler_AllowPort
2987 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2989 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2991 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
2993 ret->nshandler = nshandler;
2995 return &ret->nsIProtocolHandler_iface;
2998 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
3000 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
3005 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
3010 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
3011 nsIProtocolHandler **_retval)
3013 nsIExternalProtocolHandler *nsexthandler;
3014 nsIProtocolHandler *nshandler;
3017 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3019 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
3020 if(NS_FAILED(nsres)) {
3021 WARN("GetProtocolHandler failed: %08x\n", nsres);
3025 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
3026 (void**)&nsexthandler);
3027 if(NS_FAILED(nsres)) {
3028 *_retval = nshandler;
3032 nsIExternalProtocolHandler_Release(nsexthandler);
3033 *_retval = create_protocol_handler(nshandler);
3034 TRACE("return %p\n", *_retval);
3038 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
3041 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3042 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
3045 static BOOL is_gecko_special_uri(const char *spec)
3047 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3050 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3051 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3055 if(!strncasecmp(spec, "file:", 5)) {
3056 const char *ptr = spec+5;
3059 return is_gecko_path(ptr);
3065 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
3066 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3068 nsWineURI *wine_uri, *base_wine_uri = NULL;
3069 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3070 HTMLWindow *window = NULL;
3071 const char *spec = NULL;
3077 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3080 nsACString_GetData(aSpec, &spec);
3081 if(is_gecko_special_uri(spec))
3082 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3084 if(!strncmp(spec, "wine:", 5))
3088 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3089 if(NS_SUCCEEDED(nsres)) {
3090 if(!ensure_uri(base_wine_uri))
3091 return NS_ERROR_UNEXPECTED;
3092 if(base_wine_uri->window_ref)
3093 window = base_wine_uri->window_ref->window;
3095 WARN("Could not get base nsWineURI: %08x\n", nsres);
3099 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3102 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
3105 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
3107 hres = CreateUri(new_spec, 0, 0, &urlmon_uri);
3109 WARN("CreateUri failed: %08x\n", hres);
3112 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
3113 if(NS_FAILED(nsres))
3114 TRACE("NewURI failed: %08x\n", nsres);
3121 nsres = create_nsuri(urlmon_uri, uri, window, NULL, &wine_uri);
3122 IUri_Release(urlmon_uri);
3124 nsIURI_Release(&base_wine_uri->nsIURL_iface);
3125 if(NS_FAILED(nsres))
3128 *_retval = (nsIURI*)&wine_uri->nsIURL_iface;
3132 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
3135 TRACE("(%p %p)\n", aFile, _retval);
3136 return nsIIOService_NewFileURI(nsio, aFile, _retval);
3139 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
3140 nsIChannel **_retval)
3142 nsWineURI *wine_uri;
3146 TRACE("(%p %p)\n", aURI, _retval);
3148 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3149 if(NS_FAILED(nsres)) {
3150 TRACE("Could not get nsWineURI: %08x\n", nsres);
3151 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
3154 nsres = create_nschannel(wine_uri, &ret);
3155 nsIURL_Release(&wine_uri->nsIURL_iface);
3156 if(NS_FAILED(nsres))
3159 nsIURI_AddRef(aURI);
3160 ret->original_uri = aURI;
3162 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3166 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
3167 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
3169 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
3170 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3173 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
3175 TRACE("(%p)\n", aOffline);
3176 return nsIIOService_GetOffline(nsio, aOffline);
3179 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
3181 TRACE("(%x)\n", aOffline);
3182 return nsIIOService_SetOffline(nsio, aOffline);
3185 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
3186 const char *aScheme, PRBool *_retval)
3188 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
3189 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
3192 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
3193 nsACString * _retval)
3195 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
3196 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
3199 static const nsIIOServiceVtbl nsIOServiceVtbl = {
3200 nsIOService_QueryInterface,
3202 nsIOService_Release,
3203 nsIOService_GetProtocolHandler,
3204 nsIOService_GetProtocolFlags,
3206 nsIOService_NewFileURI,
3207 nsIOService_NewChannelFromURI,
3208 nsIOService_NewChannel,
3209 nsIOService_GetOffline,
3210 nsIOService_SetOffline,
3211 nsIOService_AllowPort,
3212 nsIOService_ExtractScheme
3215 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3217 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3220 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3223 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3228 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3233 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3234 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
3236 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3238 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3241 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
3245 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3248 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
3250 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3252 if(aFlags == (1<<11)) {
3257 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3260 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3262 TRACE("(%p %p)\n", aURI, _retval);
3264 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3267 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3269 TRACE("(%p %p)\n", aURI, _retval);
3271 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3274 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3275 PRUint32 aEscapeType, nsACString *_retval)
3277 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3279 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3282 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
3283 nsACString *_retval)
3285 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3287 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3290 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3291 PRUint32 aFlags, nsACString *_retval)
3293 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3295 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3298 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3299 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
3301 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3302 aCharsetEnd, _retval);
3304 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3307 static const nsINetUtilVtbl nsNetUtilVtbl = {
3308 nsNetUtil_QueryInterface,
3311 nsNetUtil_ParseContentType,
3312 nsNetUtil_ProtocolHasFlags,
3313 nsNetUtil_URIChainHasFlags,
3314 nsNetUtil_ToImmutableURI,
3315 nsNetUtil_NewSimpleNestedURI,
3316 nsNetUtil_EscapeString,
3317 nsNetUtil_EscapeURL,
3318 nsNetUtil_UnescapeString,
3319 nsNetUtil_ExtractCharsetFromContentType
3322 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3324 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3329 if(IsEqualGUID(&IID_nsISupports, riid))
3330 *result = &nsIOService;
3331 else if(IsEqualGUID(&IID_nsIIOService, riid))
3332 *result = &nsIOService;
3333 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3334 *result = &nsNetUtil;
3337 nsISupports_AddRef((nsISupports*)*result);
3341 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3342 return NS_NOINTERFACE;
3345 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3350 if(IsEqualGUID(&IID_nsISupports, riid)) {
3351 TRACE("(IID_nsISupports %p)\n", result);
3353 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3354 TRACE("(IID_nsIFactory %p)\n", result);
3359 nsIFactory_AddRef(iface);
3363 WARN("(%s %p)\n", debugstr_guid(riid), result);
3364 return NS_NOINTERFACE;
3367 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3372 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3377 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3378 nsISupports *aOuter, const nsIID *iid, void **result)
3380 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3383 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
3385 WARN("(%x)\n", lock);
3389 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3390 nsIOServiceFactory_QueryInterface,
3391 nsIOServiceFactory_AddRef,
3392 nsIOServiceFactory_Release,
3393 nsIOServiceFactory_CreateInstance,
3394 nsIOServiceFactory_LockFactory
3397 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3399 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3401 OLECHAR *new_url = NULL;
3406 if(!doc->hostui || !ensure_uri(uri))
3409 hres = IUri_GetDisplayUri(uri->uri, &url);
3413 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3414 if(hres == S_OK && new_url) {
3415 if(strcmpW(url, new_url)) {
3416 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3419 CoTaskMemFree(new_url);
3426 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
3428 nsWineURI *wine_uri;
3433 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3434 if(NS_FAILED(nsres)) {
3435 WARN("Could not get nsWineURI: %08x\n", nsres);
3436 return NS_ERROR_NOT_IMPLEMENTED;
3439 if(!wine_uri->is_doc_uri) {
3440 wine_uri->is_doc_uri = TRUE;
3442 if(!wine_uri->container) {
3443 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3444 wine_uri->container = nscontainer;
3447 if(nscontainer->doc)
3448 *_retval = translate_url(nscontainer->doc, wine_uri);
3451 nsIURI_Release(&wine_uri->nsIURL_iface);
3455 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3457 nsIFactory *old_factory = NULL;
3460 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3461 &IID_nsIFactory, (void**)&old_factory);
3462 if(NS_FAILED(nsres)) {
3463 ERR("Could not get factory: %08x\n", nsres);
3467 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3468 if(NS_FAILED(nsres)) {
3469 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3470 nsIFactory_Release(old_factory);
3474 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3475 if(NS_FAILED(nsres)) {
3476 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3477 nsIIOService_Release(nsio);
3481 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3482 nsIFactory_Release(old_factory);
3483 if(NS_FAILED(nsres))
3484 ERR("UnregisterFactory failed: %08x\n", nsres);
3486 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3487 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3488 if(NS_FAILED(nsres))
3489 ERR("RegisterFactory failed: %08x\n", nsres);
3492 void release_nsio(void)
3495 nsINetUtil_Release(net_util);
3500 nsIIOService_Release(nsio);