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"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
43 #define NS_IOSERVICE_CLASSNAME "nsIOService"
44 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
46 static const IID NS_IOSERVICE_CID =
47 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
48 static const IID IID_nsWineURI =
49 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
51 static nsIIOService *nsio = NULL;
52 static nsINetUtil *net_util;
54 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
56 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
65 NSContainer *container;
66 windowref_t *window_ref;
67 nsChannelBSC *channel_bsc;
69 IUriBuilder *uri_builder;
73 static BOOL ensure_uri(nsWineURI *This)
77 assert(This->uri || This->uri_builder);
80 hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
82 WARN("CreateUriSimple failed: %08x\n", hres);
90 static nsresult create_nsuri(IUri*,nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
92 static const char *debugstr_nsacstr(const nsACString *nsstr)
96 nsACString_GetData(nsstr, &data);
97 return debugstr_a(data);
100 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
102 const WCHAR *ptr = nsuri;
104 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
106 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
107 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
109 if(*ptr || ret_empty) {
110 *ret = SysAllocString(ptr);
112 return E_OUTOFMEMORY;
117 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
121 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
123 IOleCommandTarget *cmdtrg = NULL;
126 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
127 if(SUCCEEDED(hres)) {
128 VARIANT varUrl, varRes;
130 V_VT(&varUrl) = VT_BSTR;
131 V_BSTR(&varUrl) = url;
132 V_VT(&varRes) = VT_BOOL;
134 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
136 IOleCommandTarget_Release(cmdtrg);
138 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
139 TRACE("got VARIANT_FALSE, do not load\n");
147 static nsresult before_async_open(nsChannel *channel, NSContainer *container, BOOL *cancel)
149 HTMLDocumentObj *doc = container->doc;
155 NSContainer *container_iter = container;
157 hlnf = HLNF_OPENINNEWWINDOW;
158 while(!container_iter->doc)
159 container_iter = container_iter->parent;
160 doc = container_iter->doc;
168 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
170 return NS_ERROR_FAILURE;
175 b = !exec_shldocvw_67(doc, display_uri);
177 SysFreeString(display_uri);
183 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, hlnf, cancel);
184 SysFreeString(display_uri);
190 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
192 nsIWebNavigation *web_navigation;
193 nsIDocShell *doc_shell;
194 HTMLDocumentNode *doc;
197 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
198 if(NS_FAILED(nsres)) {
199 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
203 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
204 nsIWebNavigation_Release(web_navigation);
205 if(NS_FAILED(nsres)) {
206 ERR("Could not get nsIDocShell: %08x\n", nsres);
210 uri->channel_bsc = channelbsc;
212 doc->skip_mutation_notif = TRUE;
213 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIURL_iface, NULL, flags, FALSE);
214 if(doc == window->doc)
215 doc->skip_mutation_notif = FALSE;
216 uri->channel_bsc = NULL;
217 nsIDocShell_Release(doc_shell);
218 if(NS_FAILED(nsres)) {
219 WARN("LoadURI failed: %08x\n", nsres);
226 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
228 if(This->container) {
229 if(This->container == nscontainer)
231 TRACE("Changing %p -> %p\n", This->container, nscontainer);
232 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
236 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
237 This->container = nscontainer;
240 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
242 if(This->window_ref) {
243 if(This->window_ref->window == window)
245 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
246 windowref_release(This->window_ref);
250 windowref_addref(window->window_ref);
251 This->window_ref = window->window_ref;
254 set_uri_nscontainer(This, window->doc_obj->nscontainer);
256 This->window_ref = NULL;
260 static inline BOOL is_http_channel(nsChannel *This)
262 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTPS;
265 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
269 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
270 if(!strcmpiW(iter->header, name))
277 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
280 const char *header_namea;
281 http_header_t *header;
285 nsACString_GetData(header_name_str, &header_namea);
286 header_name = heap_strdupAtoW(header_namea);
288 return NS_ERROR_UNEXPECTED;
290 header = find_http_header(headers, header_name, strlenW(header_name));
291 heap_free(header_name);
293 return NS_ERROR_NOT_AVAILABLE;
295 data = heap_strdupWtoA(header->data);
297 return NS_ERROR_UNEXPECTED;
299 nsACString_SetData(_retval, data);
304 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
305 const WCHAR *value, int value_len)
307 http_header_t *header;
309 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
311 header = find_http_header(headers, name, name_len);
315 new_data = heap_strndupW(value, value_len);
317 return E_OUTOFMEMORY;
319 heap_free(header->data);
320 header->data = new_data;
322 header = heap_alloc(sizeof(http_header_t));
324 return E_OUTOFMEMORY;
326 header->header = heap_strndupW(name, name_len);
327 header->data = heap_strndupW(value, value_len);
328 if(!header->header || !header->data) {
329 heap_free(header->header);
330 heap_free(header->data);
332 return E_OUTOFMEMORY;
335 list_add_tail(headers, &header->entry);
341 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
342 const nsACString *value_str)
344 const char *namea, *valuea;
348 nsACString_GetData(name_str, &namea);
349 name = heap_strdupAtoW(namea);
351 return NS_ERROR_UNEXPECTED;
353 nsACString_GetData(value_str, &valuea);
354 value = heap_strdupAtoW(valuea);
357 return NS_ERROR_UNEXPECTED;
360 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
364 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
367 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
369 nsACString header_str, value_str;
370 char *header, *value;
374 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
375 header = heap_strdupWtoA(iter->header);
377 return NS_ERROR_OUT_OF_MEMORY;
379 value = heap_strdupWtoA(iter->data);
382 return NS_ERROR_OUT_OF_MEMORY;
385 nsACString_InitDepend(&header_str, header);
386 nsACString_InitDepend(&value_str, value);
387 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
388 nsACString_Finish(&header_str);
389 nsACString_Finish(&value_str);
399 static void free_http_headers(struct list *list)
401 http_header_t *iter, *iter_next;
403 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
404 list_remove(&iter->entry);
405 heap_free(iter->header);
406 heap_free(iter->data);
411 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
413 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
416 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
418 nsChannel *This = impl_from_nsIHttpChannel(iface);
420 if(IsEqualGUID(&IID_nsISupports, riid)) {
421 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
422 *result = &This->nsIHttpChannel_iface;
423 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
424 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
425 *result = &This->nsIHttpChannel_iface;
426 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
427 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
428 *result = &This->nsIHttpChannel_iface;
429 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
430 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
431 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
432 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
433 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
434 *result = &This->nsIUploadChannel_iface;
435 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
436 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
437 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
439 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
444 nsIChannel_AddRef(&This->nsIHttpChannel_iface);
448 return NS_NOINTERFACE;
451 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
453 nsChannel *This = impl_from_nsIHttpChannel(iface);
454 nsrefcnt ref = InterlockedIncrement(&This->ref);
456 TRACE("(%p) ref=%d\n", This, ref);
461 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
463 nsChannel *This = impl_from_nsIHttpChannel(iface);
464 LONG ref = InterlockedDecrement(&This->ref);
467 nsIURI_Release(&This->uri->nsIURL_iface);
469 nsISupports_Release(This->owner);
470 if(This->post_data_stream)
471 nsIInputStream_Release(This->post_data_stream);
473 nsILoadGroup_Release(This->load_group);
474 if(This->notif_callback)
475 nsIInterfaceRequestor_Release(This->notif_callback);
476 if(This->original_uri)
477 nsIURI_Release(This->original_uri);
479 nsIURI_Release(This->referrer);
481 free_http_headers(&This->response_headers);
482 free_http_headers(&This->request_headers);
484 heap_free(This->content_type);
485 heap_free(This->charset);
492 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
494 nsChannel *This = impl_from_nsIHttpChannel(iface);
496 TRACE("(%p)->(%p)\n", This, aName);
498 return nsIURI_GetSpec(&This->uri->nsIURL_iface, aName);
501 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
503 nsChannel *This = impl_from_nsIHttpChannel(iface);
505 FIXME("(%p)->(%p)\n", This, _retval);
507 return NS_ERROR_NOT_IMPLEMENTED;
510 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
512 nsChannel *This = impl_from_nsIHttpChannel(iface);
514 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
516 return *aStatus = NS_OK;
519 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
521 nsChannel *This = impl_from_nsIHttpChannel(iface);
523 FIXME("(%p)->(%08x)\n", This, aStatus);
525 return NS_ERROR_NOT_IMPLEMENTED;
528 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
530 nsChannel *This = impl_from_nsIHttpChannel(iface);
532 FIXME("(%p)\n", This);
534 return NS_ERROR_NOT_IMPLEMENTED;
537 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
539 nsChannel *This = impl_from_nsIHttpChannel(iface);
541 FIXME("(%p)\n", This);
543 return NS_ERROR_NOT_IMPLEMENTED;
546 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
548 nsChannel *This = impl_from_nsIHttpChannel(iface);
550 TRACE("(%p)->(%p)\n", This, aLoadGroup);
553 nsILoadGroup_AddRef(This->load_group);
555 *aLoadGroup = This->load_group;
559 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
561 nsChannel *This = impl_from_nsIHttpChannel(iface);
563 TRACE("(%p)->(%p)\n", This, aLoadGroup);
566 nsILoadGroup_Release(This->load_group);
568 nsILoadGroup_AddRef(aLoadGroup);
569 This->load_group = aLoadGroup;
574 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
576 nsChannel *This = impl_from_nsIHttpChannel(iface);
578 TRACE("(%p)->(%p)\n", This, aLoadFlags);
580 *aLoadFlags = This->load_flags;
584 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
586 nsChannel *This = impl_from_nsIHttpChannel(iface);
588 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
590 This->load_flags = aLoadFlags;
594 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
596 nsChannel *This = impl_from_nsIHttpChannel(iface);
598 TRACE("(%p)->(%p)\n", This, aOriginalURI);
600 if(This->original_uri)
601 nsIURI_AddRef(This->original_uri);
603 *aOriginalURI = This->original_uri;
607 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
609 nsChannel *This = impl_from_nsIHttpChannel(iface);
611 TRACE("(%p)->(%p)\n", This, aOriginalURI);
613 if(This->original_uri)
614 nsIURI_Release(This->original_uri);
616 nsIURI_AddRef(aOriginalURI);
617 This->original_uri = aOriginalURI;
621 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
623 nsChannel *This = impl_from_nsIHttpChannel(iface);
625 TRACE("(%p)->(%p)\n", This, aURI);
627 nsIURI_AddRef(&This->uri->nsIURL_iface);
628 *aURI = (nsIURI*)This->uri;
633 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
635 nsChannel *This = impl_from_nsIHttpChannel(iface);
637 TRACE("(%p)->(%p)\n", This, aOwner);
640 nsISupports_AddRef(This->owner);
641 *aOwner = This->owner;
646 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
648 nsChannel *This = impl_from_nsIHttpChannel(iface);
650 TRACE("(%p)->(%p)\n", This, aOwner);
653 nsISupports_AddRef(aOwner);
655 nsISupports_Release(This->owner);
656 This->owner = aOwner;
661 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
662 nsIInterfaceRequestor **aNotificationCallbacks)
664 nsChannel *This = impl_from_nsIHttpChannel(iface);
666 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
668 if(This->notif_callback)
669 nsIInterfaceRequestor_AddRef(This->notif_callback);
670 *aNotificationCallbacks = This->notif_callback;
675 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
676 nsIInterfaceRequestor *aNotificationCallbacks)
678 nsChannel *This = impl_from_nsIHttpChannel(iface);
680 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
682 if(This->notif_callback)
683 nsIInterfaceRequestor_Release(This->notif_callback);
684 if(aNotificationCallbacks)
685 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
687 This->notif_callback = aNotificationCallbacks;
692 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
694 nsChannel *This = impl_from_nsIHttpChannel(iface);
696 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
698 return NS_ERROR_NOT_IMPLEMENTED;
701 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
703 nsChannel *This = impl_from_nsIHttpChannel(iface);
705 TRACE("(%p)->(%p)\n", This, aContentType);
707 if(This->content_type) {
708 nsACString_SetData(aContentType, This->content_type);
712 WARN("unknown type\n");
713 return NS_ERROR_FAILURE;
716 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
717 const nsACString *aContentType)
719 nsChannel *This = impl_from_nsIHttpChannel(iface);
720 const char *content_type;
722 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
724 nsACString_GetData(aContentType, &content_type);
725 heap_free(This->content_type);
726 This->content_type = heap_strdupA(content_type);
731 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
732 nsACString *aContentCharset)
734 nsChannel *This = impl_from_nsIHttpChannel(iface);
736 TRACE("(%p)->(%p)\n", This, aContentCharset);
739 nsACString_SetData(aContentCharset, This->charset);
743 nsACString_SetData(aContentCharset, "");
747 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
748 const nsACString *aContentCharset)
750 nsChannel *This = impl_from_nsIHttpChannel(iface);
752 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
754 return NS_ERROR_NOT_IMPLEMENTED;
757 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
759 nsChannel *This = impl_from_nsIHttpChannel(iface);
761 FIXME("(%p)->(%p)\n", This, aContentLength);
763 return NS_ERROR_NOT_IMPLEMENTED;
766 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
768 nsChannel *This = impl_from_nsIHttpChannel(iface);
770 FIXME("(%p)->(%d)\n", This, aContentLength);
772 return NS_ERROR_NOT_IMPLEMENTED;
775 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
777 nsChannel *This = impl_from_nsIHttpChannel(iface);
779 FIXME("(%p)->(%p)\n", This, _retval);
781 return NS_ERROR_NOT_IMPLEMENTED;
784 static HTMLWindow *get_window_from_load_group(nsChannel *This)
793 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
794 if(NS_FAILED(nsres)) {
795 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
802 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
803 nsIRequest_Release(req);
804 if(NS_FAILED(nsres)) {
805 WARN("Could not get nsIChannel interface: %08x\n", nsres);
809 nsres = nsIChannel_GetURI(channel, &uri);
810 nsIChannel_Release(channel);
811 if(NS_FAILED(nsres)) {
812 ERR("GetURI failed: %08x\n", nsres);
816 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
818 if(NS_FAILED(nsres)) {
819 TRACE("Could not get nsWineURI: %08x\n", nsres);
823 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
825 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
826 nsIURI_Release(&wine_uri->nsIURL_iface);
831 static HTMLWindow *get_channel_window(nsChannel *This)
833 nsIWebProgress *web_progress;
834 nsIDOMWindow *nswindow;
838 if(This->load_group) {
839 nsIRequestObserver *req_observer;
841 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
842 if(NS_FAILED(nsres) || !req_observer) {
843 ERR("GetGroupObserver failed: %08x\n", nsres);
847 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
848 nsIRequestObserver_Release(req_observer);
849 if(NS_FAILED(nsres)) {
850 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
853 }else if(This->notif_callback) {
854 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
855 if(NS_FAILED(nsres)) {
856 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
860 ERR("no load group nor notif callback\n");
864 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
865 nsIWebProgress_Release(web_progress);
866 if(NS_FAILED(nsres) || !nswindow) {
867 ERR("GetDOMWindow failed: %08x\n", nsres);
871 window = nswindow_to_window(nswindow);
872 nsIDOMWindow_Release(nswindow);
875 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
877 FIXME("NULL window for %p\n", nswindow);
883 HTMLDocumentNode *doc;
884 nsChannelBSC *bscallback;
885 } start_binding_task_t;
887 static void start_binding_proc(task_t *_task)
889 start_binding_task_t *task = (start_binding_task_t*)_task;
891 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
893 IUnknown_Release((IUnknown*)task->bscallback);
896 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
897 nsISupports *context)
899 nsChannelBSC *bscallback;
900 IMoniker *mon = NULL;
903 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
905 WARN("CreateURLMoniker failed: %08x\n", hres);
906 return NS_ERROR_UNEXPECTED;
910 set_current_mon(window, mon);
912 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
913 IMoniker_Release(mon);
915 return NS_ERROR_UNEXPECTED;
917 channelbsc_set_channel(bscallback, This, listener, context);
920 set_window_bscallback(window, bscallback);
921 async_start_doc_binding(window, bscallback);
922 IUnknown_Release((IUnknown*)bscallback);
924 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
926 task->doc = window->doc;
927 task->bscallback = bscallback;
928 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
934 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
935 nsISupports *aContext)
937 nsChannel *This = impl_from_nsIHttpChannel(iface);
938 HTMLWindow *window = NULL;
940 nsresult nsres = NS_OK;
942 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
944 if(!ensure_uri(This->uri))
945 return NS_ERROR_FAILURE;
947 if(This->uri->is_doc_uri) {
948 window = get_channel_window(This);
950 set_uri_window(This->uri, window);
951 }else if(This->uri->container) {
954 /* nscontainer->doc should be NULL which means navigation to a new window */
955 if(This->uri->container->doc)
956 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
958 nsres = before_async_open(This, This->uri->container, &b);
962 FIXME("Navigation not cancelled\n");
963 return NS_ERROR_UNEXPECTED;
968 if(This->uri->window_ref && This->uri->window_ref->window) {
969 window = This->uri->window_ref->window;
970 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
972 /* FIXME: Analyze removing get_window_from_load_group call */
974 window = get_window_from_load_group(This);
976 window = get_channel_window(This);
978 set_uri_window(This->uri, window);
983 ERR("window = NULL\n");
984 return NS_ERROR_UNEXPECTED;
987 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
988 if(This->uri->channel_bsc) {
989 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
991 if(window->doc_obj->mime) {
992 heap_free(This->content_type);
993 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
998 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
999 if(NS_SUCCEEDED(nsres) && cancel) {
1000 TRACE("canceled\n");
1001 nsres = NS_BINDING_ABORTED;
1007 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1009 if(NS_SUCCEEDED(nsres) && This->load_group) {
1010 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1012 if(NS_FAILED(nsres))
1013 ERR("AddRequest failed: %08x\n", nsres);
1016 IHTMLWindow2_Release(&window->IHTMLWindow2_iface);
1020 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1022 nsChannel *This = impl_from_nsIHttpChannel(iface);
1024 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1026 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1030 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1031 const nsACString *aRequestMethod)
1033 nsChannel *This = impl_from_nsIHttpChannel(iface);
1037 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1039 nsACString_GetData(aRequestMethod, &method);
1040 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1041 if(!strcasecmp(method, request_method_strings[i])) {
1042 This->request_method = i;
1047 ERR("Invalid method %s\n", debugstr_a(method));
1048 return NS_ERROR_UNEXPECTED;
1051 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1053 nsChannel *This = impl_from_nsIHttpChannel(iface);
1055 TRACE("(%p)->(%p)\n", This, aReferrer);
1058 nsIURI_AddRef(This->referrer);
1059 *aReferrer = This->referrer;
1063 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1065 nsChannel *This = impl_from_nsIHttpChannel(iface);
1067 TRACE("(%p)->(%p)\n", This, aReferrer);
1070 nsIURI_AddRef(aReferrer);
1072 nsIURI_Release(This->referrer);
1073 This->referrer = aReferrer;
1077 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1078 const nsACString *aHeader, nsACString *_retval)
1080 nsChannel *This = impl_from_nsIHttpChannel(iface);
1082 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1084 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1087 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1088 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
1090 nsChannel *This = impl_from_nsIHttpChannel(iface);
1092 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1095 FIXME("aMerge not supported\n");
1097 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1100 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1101 nsIHttpHeaderVisitor *aVisitor)
1103 nsChannel *This = impl_from_nsIHttpChannel(iface);
1105 FIXME("(%p)->(%p)\n", This, aVisitor);
1107 return NS_ERROR_NOT_IMPLEMENTED;
1110 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1112 nsChannel *This = impl_from_nsIHttpChannel(iface);
1114 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1116 return NS_ERROR_NOT_IMPLEMENTED;
1119 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1121 nsChannel *This = impl_from_nsIHttpChannel(iface);
1123 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1125 return NS_ERROR_NOT_IMPLEMENTED;
1128 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1130 nsChannel *This = impl_from_nsIHttpChannel(iface);
1132 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1134 return NS_ERROR_NOT_IMPLEMENTED;
1137 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1139 nsChannel *This = impl_from_nsIHttpChannel(iface);
1141 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1143 return NS_ERROR_NOT_IMPLEMENTED;
1146 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1148 nsChannel *This = impl_from_nsIHttpChannel(iface);
1150 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1152 if(This->response_status) {
1153 *aResponseStatus = This->response_status;
1157 WARN("No response status\n");
1158 return NS_ERROR_UNEXPECTED;
1161 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1162 nsACString *aResponseStatusText)
1164 nsChannel *This = impl_from_nsIHttpChannel(iface);
1166 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1168 return NS_ERROR_NOT_IMPLEMENTED;
1171 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1172 PRBool *aRequestSucceeded)
1174 nsChannel *This = impl_from_nsIHttpChannel(iface);
1176 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1178 if(!This->response_status)
1179 return NS_ERROR_NOT_AVAILABLE;
1181 *aRequestSucceeded = This->response_status/100 == 2;
1186 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1187 const nsACString *header, nsACString *_retval)
1189 nsChannel *This = impl_from_nsIHttpChannel(iface);
1191 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1193 return get_channel_http_header(&This->response_headers, header, _retval);
1196 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1197 const nsACString *header, const nsACString *value, PRBool merge)
1199 nsChannel *This = impl_from_nsIHttpChannel(iface);
1201 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1203 return NS_ERROR_NOT_IMPLEMENTED;
1206 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1207 nsIHttpHeaderVisitor *aVisitor)
1209 nsChannel *This = impl_from_nsIHttpChannel(iface);
1211 TRACE("(%p)->(%p)\n", This, aVisitor);
1213 return visit_http_headers(&This->response_headers, aVisitor);
1216 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1218 nsChannel *This = impl_from_nsIHttpChannel(iface);
1219 http_header_t *header;
1221 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1222 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1224 TRACE("(%p)->(%p)\n", This, _retval);
1226 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1227 *_retval = header && !strcmpiW(header->data, no_storeW);
1231 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1233 nsChannel *This = impl_from_nsIHttpChannel(iface);
1235 FIXME("(%p)->(%p)\n", This, _retval);
1237 return NS_ERROR_NOT_IMPLEMENTED;
1240 static const nsIHttpChannelVtbl nsChannelVtbl = {
1241 nsChannel_QueryInterface,
1245 nsChannel_IsPending,
1246 nsChannel_GetStatus,
1250 nsChannel_GetLoadGroup,
1251 nsChannel_SetLoadGroup,
1252 nsChannel_GetLoadFlags,
1253 nsChannel_SetLoadFlags,
1254 nsChannel_GetOriginalURI,
1255 nsChannel_SetOriginalURI,
1259 nsChannel_GetNotificationCallbacks,
1260 nsChannel_SetNotificationCallbacks,
1261 nsChannel_GetSecurityInfo,
1262 nsChannel_GetContentType,
1263 nsChannel_SetContentType,
1264 nsChannel_GetContentCharset,
1265 nsChannel_SetContentCharset,
1266 nsChannel_GetContentLength,
1267 nsChannel_SetContentLength,
1269 nsChannel_AsyncOpen,
1270 nsChannel_GetRequestMethod,
1271 nsChannel_SetRequestMethod,
1272 nsChannel_GetReferrer,
1273 nsChannel_SetReferrer,
1274 nsChannel_GetRequestHeader,
1275 nsChannel_SetRequestHeader,
1276 nsChannel_VisitRequestHeaders,
1277 nsChannel_GetAllowPipelining,
1278 nsChannel_SetAllowPipelining,
1279 nsChannel_GetRedirectionLimit,
1280 nsChannel_SetRedirectionLimit,
1281 nsChannel_GetResponseStatus,
1282 nsChannel_GetResponseStatusText,
1283 nsChannel_GetRequestSucceeded,
1284 nsChannel_GetResponseHeader,
1285 nsChannel_SetResponseHeader,
1286 nsChannel_VisitResponseHeaders,
1287 nsChannel_IsNoStoreResponse,
1288 nsChannel_IsNoCacheResponse
1291 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1293 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1296 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1299 nsChannel *This = impl_from_nsIUploadChannel(iface);
1300 return nsIChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1303 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1305 nsChannel *This = impl_from_nsIUploadChannel(iface);
1306 return nsIChannel_AddRef(&This->nsIHttpChannel_iface);
1309 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1311 nsChannel *This = impl_from_nsIUploadChannel(iface);
1312 return nsIChannel_Release(&This->nsIHttpChannel_iface);
1315 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1316 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1318 nsChannel *This = impl_from_nsIUploadChannel(iface);
1319 const char *content_type;
1321 static const WCHAR content_typeW[] =
1322 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1324 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1326 This->post_data_contains_headers = TRUE;
1329 nsACString_GetData(aContentType, &content_type);
1333 ct = heap_strdupAtoW(content_type);
1335 return NS_ERROR_UNEXPECTED;
1337 set_http_header(&This->request_headers, content_typeW,
1338 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1340 This->post_data_contains_headers = FALSE;
1344 if(This->post_data_stream)
1345 nsIInputStream_Release(This->post_data_stream);
1347 if(aContentLength != -1)
1348 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1350 if(This->post_data_stream)
1351 nsIInputStream_Release(This->post_data_stream);
1352 This->post_data_stream = aStream;
1354 nsIInputStream_AddRef(aStream);
1356 This->request_method = METHOD_POST;
1360 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1361 nsIInputStream **aUploadStream)
1363 nsChannel *This = impl_from_nsIUploadChannel(iface);
1365 TRACE("(%p)->(%p)\n", This, aUploadStream);
1367 if(This->post_data_stream)
1368 nsIInputStream_AddRef(This->post_data_stream);
1370 *aUploadStream = This->post_data_stream;
1374 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1375 nsUploadChannel_QueryInterface,
1376 nsUploadChannel_AddRef,
1377 nsUploadChannel_Release,
1378 nsUploadChannel_SetUploadStream,
1379 nsUploadChannel_GetUploadStream
1382 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1384 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1387 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1390 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1391 return nsIChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1394 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1396 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1397 return nsIChannel_AddRef(&This->nsIHttpChannel_iface);
1400 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1402 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1403 return nsIChannel_Release(&This->nsIHttpChannel_iface);
1406 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1408 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1410 FIXME("(%p)->()\n", This);
1412 return NS_ERROR_NOT_IMPLEMENTED;
1415 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1417 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1419 FIXME("(%p)->()\n", This);
1421 return NS_ERROR_NOT_IMPLEMENTED;
1424 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1426 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1428 FIXME("(%p)->()\n", This);
1430 return NS_ERROR_NOT_IMPLEMENTED;
1433 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1435 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1437 FIXME("(%p)->()\n", This);
1439 return NS_ERROR_NOT_IMPLEMENTED;
1442 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1444 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1446 FIXME("(%p)->()\n", This);
1448 return NS_ERROR_NOT_IMPLEMENTED;
1451 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1453 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1455 FIXME("(%p)->()\n", This);
1457 return NS_ERROR_NOT_IMPLEMENTED;
1460 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1462 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1464 FIXME("(%p)->()\n", This);
1466 return NS_ERROR_NOT_IMPLEMENTED;
1469 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1471 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1473 FIXME("(%p)->()\n", This);
1475 return NS_ERROR_NOT_IMPLEMENTED;
1478 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, PRBool *aCanceled)
1480 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1482 FIXME("(%p)->(%p)\n", This, aCanceled);
1484 return NS_ERROR_NOT_IMPLEMENTED;
1487 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, PRBool *aCanceled)
1489 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1491 FIXME("(%p)->(%p)\n", This, aCanceled);
1493 return NS_ERROR_NOT_IMPLEMENTED;
1496 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, PRBool aCanceled)
1498 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1500 FIXME("(%p)->(%x)\n", This, aCanceled);
1502 return NS_ERROR_NOT_IMPLEMENTED;
1505 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1506 nsHttpChannelInternal_QueryInterface,
1507 nsHttpChannelInternal_AddRef,
1508 nsHttpChannelInternal_Release,
1509 nsHttpChannelInternal_GetDocumentURI,
1510 nsHttpChannelInternal_SetDocumentURI,
1511 nsHttpChannelInternal_GetRequestVersion,
1512 nsHttpChannelInternal_GetResponseVersion,
1513 nsHttpChannelInternal_SetCookie,
1514 nsHttpChannelInternal_SetupFallbackChannel,
1515 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1516 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1517 nsHttpChannelInternal_GetCanceled,
1518 nsHttpChannelInternal_GetChannelIsForDownload,
1519 nsHttpChannelInternal_SetChannelIsForDownload
1523 static void invalidate_uri(nsWineURI *This)
1526 IUri_Release(This->uri);
1531 static BOOL ensure_uri_builder(nsWineURI *This)
1533 if(!This->uri_builder) {
1536 if(!ensure_uri(This))
1539 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1541 WARN("CreateIUriBulder failed: %08x\n", hres);
1546 invalidate_uri(This);
1550 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1556 if(!ensure_uri(This))
1557 return NS_ERROR_UNEXPECTED;
1559 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1561 WARN("GetPropertyBSTR failed: %08x\n", hres);
1562 return NS_ERROR_UNEXPECTED;
1565 vala = heap_strdupWtoA(val);
1568 return NS_ERROR_OUT_OF_MEMORY;
1570 TRACE("ret %s\n", debugstr_a(vala));
1571 nsACString_SetData(ret, vala);
1576 static inline nsWineURI *impl_from_nsIURL(nsIURL *iface)
1578 return CONTAINING_RECORD(iface, nsWineURI, nsIURL_iface);
1581 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, void **result)
1583 nsWineURI *This = impl_from_nsIURL(iface);
1587 if(IsEqualGUID(&IID_nsISupports, riid)) {
1588 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1589 *result = &This->nsIURL_iface;
1590 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1591 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1592 *result = &This->nsIURL_iface;
1593 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1594 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1595 *result = &This->nsIURL_iface;
1596 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1597 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1602 nsIURI_AddRef(&This->nsIURL_iface);
1606 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1607 return This->nsuri ? nsIURI_QueryInterface(This->nsuri, riid, result) : NS_NOINTERFACE;
1610 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1612 nsWineURI *This = impl_from_nsIURL(iface);
1613 LONG ref = InterlockedIncrement(&This->ref);
1615 TRACE("(%p) ref=%d\n", This, ref);
1620 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1622 nsWineURI *This = impl_from_nsIURL(iface);
1623 LONG ref = InterlockedDecrement(&This->ref);
1625 TRACE("(%p) ref=%d\n", This, ref);
1628 if(This->window_ref)
1629 windowref_release(This->window_ref);
1631 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1633 nsIURL_Release(This->nsurl);
1635 nsIURI_Release(This->nsuri);
1637 IUri_Release(This->uri);
1644 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1646 nsWineURI *This = impl_from_nsIURL(iface);
1648 TRACE("(%p)->(%p)\n", This, aSpec);
1650 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1653 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1655 nsWineURI *This = impl_from_nsIURL(iface);
1661 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1663 nsACString_GetData(aSpec, &speca);
1664 spec = heap_strdupAtoW(speca);
1666 return NS_ERROR_OUT_OF_MEMORY;
1668 hres = CreateUri(spec, 0, 0, &uri);
1671 WARN("CreateUri failed: %08x\n", hres);
1672 return NS_ERROR_FAILURE;
1675 invalidate_uri(This);
1676 if(This->uri_builder) {
1677 IUriBuilder_Release(This->uri_builder);
1678 This->uri_builder = NULL;
1685 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1687 nsWineURI *This = impl_from_nsIURL(iface);
1689 TRACE("(%p)->(%p)\n", This, aPrePath);
1692 return nsIURI_GetPrePath(This->nsuri, aPrePath);
1694 FIXME("default action not implemented\n");
1695 return NS_ERROR_NOT_IMPLEMENTED;
1698 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1700 nsWineURI *This = impl_from_nsIURL(iface);
1704 TRACE("(%p)->(%p)\n", This, aScheme);
1706 if(!ensure_uri(This))
1707 return NS_ERROR_UNEXPECTED;
1709 hres = IUri_GetScheme(This->uri, &scheme);
1711 WARN("GetScheme failed: %08x\n", hres);
1712 return NS_ERROR_UNEXPECTED;
1715 if(scheme == URL_SCHEME_ABOUT) {
1716 nsACString_SetData(aScheme, "wine");
1720 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1723 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1725 nsWineURI *This = impl_from_nsIURL(iface);
1726 const char *schemea;
1730 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1732 if(!ensure_uri_builder(This))
1733 return NS_ERROR_UNEXPECTED;
1735 nsACString_GetData(aScheme, &schemea);
1736 scheme = heap_strdupAtoW(schemea);
1738 return NS_ERROR_OUT_OF_MEMORY;
1740 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
1743 return NS_ERROR_UNEXPECTED;
1748 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1750 nsWineURI *This = impl_from_nsIURL(iface);
1754 TRACE("(%p)->(%p)\n", This, aUserPass);
1756 if(!ensure_uri(This))
1757 return NS_ERROR_UNEXPECTED;
1759 hres = IUri_GetUserName(This->uri, &user);
1761 return NS_ERROR_FAILURE;
1763 hres = IUri_GetPassword(This->uri, &pass);
1765 SysFreeString(user);
1766 return NS_ERROR_FAILURE;
1769 if(*user || *pass) {
1770 FIXME("Construct user:pass string\n");
1772 nsACString_SetData(aUserPass, "");
1775 SysFreeString(user);
1776 SysFreeString(pass);
1780 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1782 nsWineURI *This = impl_from_nsIURL(iface);
1783 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
1784 const char *user_pass;
1787 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
1789 if(!ensure_uri_builder(This))
1790 return NS_ERROR_UNEXPECTED;
1792 nsACString_GetData(aUserPass, &user_pass);
1796 buf = heap_strdupAtoW(user_pass);
1798 return NS_ERROR_OUT_OF_MEMORY;
1800 ptr = strchrW(buf, ':');
1803 }else if(ptr != buf) {
1813 hres = IUriBuilder_SetUserName(This->uri_builder, user);
1815 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
1818 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
1821 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1823 nsWineURI *This = impl_from_nsIURL(iface);
1825 TRACE("(%p)->(%p)\n", This, aUsername);
1827 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
1830 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1832 nsWineURI *This = impl_from_nsIURL(iface);
1837 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
1839 if(!ensure_uri_builder(This))
1840 return NS_ERROR_UNEXPECTED;
1842 nsACString_GetData(aUsername, &usera);
1843 user = heap_strdupAtoW(usera);
1845 return NS_ERROR_OUT_OF_MEMORY;
1847 hres = IUriBuilder_SetUserName(This->uri_builder, user);
1850 return NS_ERROR_UNEXPECTED;
1855 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1857 nsWineURI *This = impl_from_nsIURL(iface);
1859 TRACE("(%p)->(%p)\n", This, aPassword);
1861 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
1864 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1866 nsWineURI *This = impl_from_nsIURL(iface);
1871 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
1873 if(!ensure_uri_builder(This))
1874 return NS_ERROR_UNEXPECTED;
1876 nsACString_GetData(aPassword, &passa);
1877 pass = heap_strdupAtoW(passa);
1879 return NS_ERROR_OUT_OF_MEMORY;
1881 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
1884 return NS_ERROR_UNEXPECTED;
1889 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1891 nsWineURI *This = impl_from_nsIURL(iface);
1897 TRACE("(%p)->(%p)\n", This, aHostPort);
1899 if(!ensure_uri(This))
1900 return NS_ERROR_UNEXPECTED;
1902 hres = IUri_GetAuthority(This->uri, &val);
1904 WARN("GetAuthority failed: %08x\n", hres);
1905 return NS_ERROR_UNEXPECTED;
1908 ptr = strchrW(val, '@');
1912 vala = heap_strdupWtoA(ptr);
1915 return NS_ERROR_OUT_OF_MEMORY;
1917 TRACE("ret %s\n", debugstr_a(vala));
1918 nsACString_SetData(aHostPort, vala);
1923 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1925 nsWineURI *This = impl_from_nsIURL(iface);
1927 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
1929 /* Not implemented by Gecko */
1930 return NS_ERROR_NOT_IMPLEMENTED;
1933 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1935 nsWineURI *This = impl_from_nsIURL(iface);
1937 TRACE("(%p)->(%p)\n", This, aHost);
1939 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
1942 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1944 nsWineURI *This = impl_from_nsIURL(iface);
1949 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
1951 if(!ensure_uri_builder(This))
1952 return NS_ERROR_UNEXPECTED;
1954 nsACString_GetData(aHost, &hosta);
1955 host = heap_strdupAtoW(hosta);
1957 return NS_ERROR_OUT_OF_MEMORY;
1959 hres = IUriBuilder_SetHost(This->uri_builder, host);
1962 return NS_ERROR_UNEXPECTED;
1967 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1969 nsWineURI *This = impl_from_nsIURL(iface);
1973 TRACE("(%p)->(%p)\n", This, aPort);
1975 if(!ensure_uri(This))
1976 return NS_ERROR_UNEXPECTED;
1978 hres = IUri_GetPort(This->uri, &port);
1980 WARN("GetPort failed: %08x\n", hres);
1981 return NS_ERROR_UNEXPECTED;
1984 *aPort = port ? port : -1;
1988 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1990 nsWineURI *This = impl_from_nsIURL(iface);
1993 TRACE("(%p)->(%d)\n", This, aPort);
1995 if(!ensure_uri_builder(This))
1996 return NS_ERROR_UNEXPECTED;
1998 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
1999 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2002 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
2004 nsWineURI *This = impl_from_nsIURL(iface);
2006 TRACE("(%p)->(%p)\n", This, aPath);
2008 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2011 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
2013 nsWineURI *This = impl_from_nsIURL(iface);
2018 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2020 if(!ensure_uri_builder(This))
2021 return NS_ERROR_UNEXPECTED;
2023 nsACString_GetData(aPath, &patha);
2024 path = heap_strdupAtoW(patha);
2026 return NS_ERROR_OUT_OF_MEMORY;
2028 hres = IUriBuilder_SetPath(This->uri_builder, path);
2031 return NS_ERROR_UNEXPECTED;
2036 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
2038 nsWineURI *This = impl_from_nsIURL(iface);
2039 nsWineURI *other_obj;
2043 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2045 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2046 if(NS_FAILED(nsres)) {
2047 TRACE("Could not get nsWineURI interface\n");
2052 if(ensure_uri(This) && ensure_uri(other_obj)) {
2053 hres = IUri_IsEqual(This->uri, other_obj->uri, _retval);
2054 nsres = SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2056 nsres = NS_ERROR_UNEXPECTED;
2059 nsIURI_Release(&other_obj->nsIURL_iface);
2063 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
2065 nsWineURI *This = impl_from_nsIURL(iface);
2066 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2070 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2072 if(!ensure_uri(This))
2073 return NS_ERROR_UNEXPECTED;
2075 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2077 return NS_ERROR_UNEXPECTED;
2079 MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2080 *_retval = !strcmpW(scheme_name, buf);
2081 SysFreeString(scheme_name);
2085 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
2087 nsWineURI *This = impl_from_nsIURL(iface);
2088 nsIURI *nsuri = NULL;
2089 nsWineURI *wine_uri;
2092 TRACE("(%p)->(%p)\n", This, _retval);
2094 if(!ensure_uri(This))
2095 return NS_ERROR_UNEXPECTED;
2098 nsres = nsIURI_Clone(This->nsuri, &nsuri);
2099 if(NS_FAILED(nsres)) {
2100 WARN("Clone failed: %08x\n", nsres);
2105 nsres = create_nsuri(This->uri, nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
2106 if(NS_FAILED(nsres)) {
2107 WARN("create_nsuri failed: %08x\n", nsres);
2111 *_retval = (nsIURI*)&wine_uri->nsIURL_iface;
2115 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *aRelativePath,
2116 nsACString *_retval)
2118 nsWineURI *This = impl_from_nsIURL(iface);
2126 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2128 if(!ensure_uri(This))
2129 return NS_ERROR_UNEXPECTED;
2131 nsACString_GetData(aRelativePath, &patha);
2132 path = heap_strdupAtoW(patha);
2134 return NS_ERROR_OUT_OF_MEMORY;
2136 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2139 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2140 return NS_ERROR_FAILURE;
2143 hres = IUri_GetDisplayUri(new_uri, &ret);
2144 IUri_Release(new_uri);
2146 return NS_ERROR_FAILURE;
2148 reta = heap_strdupWtoA(ret);
2151 return NS_ERROR_OUT_OF_MEMORY;
2153 TRACE("returning %s\n", debugstr_a(reta));
2154 nsACString_SetData(_retval, reta);
2159 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
2161 nsWineURI *This = impl_from_nsIURL(iface);
2163 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2165 return nsIURI_GetSpec(&This->nsIURL_iface, aAsciiSpec);
2168 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
2170 nsWineURI *This = impl_from_nsIURL(iface);
2172 TRACE("(%p)->(%p)\n", This, aAsciiHost);
2175 return nsIURI_GetAsciiHost(This->nsuri, aAsciiHost);
2177 WARN("Use Uri_PUNYCODE_IDN_HOST flag\n");
2178 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2181 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
2183 nsWineURI *This = impl_from_nsIURL(iface);
2185 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2188 return nsIURI_GetOriginCharset(This->nsuri, aOriginCharset);
2190 FIXME("default action not implemented\n");
2191 return NS_ERROR_NOT_IMPLEMENTED;
2194 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
2196 nsWineURI *This = impl_from_nsIURL(iface);
2198 TRACE("(%p)->(%p)\n", This, aFilePath);
2200 return nsIURL_GetPath(&This->nsIURL_iface, aFilePath);
2203 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
2205 nsWineURI *This = impl_from_nsIURL(iface);
2207 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2209 return nsIURL_SetPath(&This->nsIURL_iface, aFilePath);
2212 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
2214 nsWineURI *This = impl_from_nsIURL(iface);
2216 TRACE("(%p)->(%p)\n", This, aParam);
2219 return nsIURL_GetParam(This->nsurl, aParam);
2221 FIXME("default action not implemented\n");
2222 return NS_ERROR_NOT_IMPLEMENTED;
2225 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
2227 nsWineURI *This = impl_from_nsIURL(iface);
2229 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
2231 /* Not implemented by Gecko */
2232 return NS_ERROR_NOT_IMPLEMENTED;
2235 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
2237 nsWineURI *This = impl_from_nsIURL(iface);
2239 TRACE("(%p)->(%p)\n", This, aQuery);
2241 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2244 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
2246 nsWineURI *This = impl_from_nsIURL(iface);
2251 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2253 if(!ensure_uri_builder(This))
2254 return NS_ERROR_UNEXPECTED;
2256 nsACString_GetData(aQuery, &querya);
2257 query = heap_strdupAtoW(querya);
2259 return NS_ERROR_OUT_OF_MEMORY;
2261 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2264 return NS_ERROR_UNEXPECTED;
2269 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
2271 nsWineURI *This = impl_from_nsIURL(iface);
2276 TRACE("(%p)->(%p)\n", This, aRef);
2278 if(!ensure_uri(This))
2279 return NS_ERROR_UNEXPECTED;
2281 hres = IUri_GetFragment(This->uri, &ref);
2283 return NS_ERROR_UNEXPECTED;
2285 refa = heap_strdupWtoA(ref);
2288 return NS_ERROR_OUT_OF_MEMORY;
2290 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2295 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
2297 nsWineURI *This = impl_from_nsIURL(iface);
2302 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2304 if(!ensure_uri_builder(This))
2305 return NS_ERROR_UNEXPECTED;
2307 nsACString_GetData(aRef, &refa);
2308 ref = heap_strdupAtoW(refa);
2310 return NS_ERROR_OUT_OF_MEMORY;
2312 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2315 return NS_ERROR_UNEXPECTED;
2320 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
2322 nsWineURI *This = impl_from_nsIURL(iface);
2324 TRACE("(%p)->(%p)\n", This, aDirectory);
2327 return nsIURL_GetDirectory(This->nsurl, aDirectory);
2329 FIXME("default action not implemented\n");
2330 return NS_ERROR_NOT_IMPLEMENTED;
2333 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2335 nsWineURI *This = impl_from_nsIURL(iface);
2337 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2339 /* Not implemented by Gecko */
2340 return NS_ERROR_NOT_IMPLEMENTED;
2343 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2345 nsWineURI *This = impl_from_nsIURL(iface);
2347 TRACE("(%p)->(%p)\n", This, aFileName);
2350 return nsIURL_GetFileName(This->nsurl, aFileName);
2352 FIXME("default action not implemented\n");
2353 return NS_ERROR_NOT_IMPLEMENTED;
2356 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2358 nsWineURI *This = impl_from_nsIURL(iface);
2360 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2363 invalidate_uri(This);
2364 return nsIURL_SetFileName(This->nsurl, aFileName);
2367 FIXME("default action not implemented\n");
2368 return NS_ERROR_NOT_IMPLEMENTED;
2371 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2373 nsWineURI *This = impl_from_nsIURL(iface);
2375 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2378 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2380 FIXME("default action not implemented\n");
2381 return NS_ERROR_NOT_IMPLEMENTED;
2384 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2386 nsWineURI *This = impl_from_nsIURL(iface);
2388 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2391 invalidate_uri(This);
2392 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2395 FIXME("default action not implemented\n");
2396 return NS_ERROR_NOT_IMPLEMENTED;
2399 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2401 nsWineURI *This = impl_from_nsIURL(iface);
2403 TRACE("(%p)->(%p)\n", This, aFileExtension);
2406 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2408 FIXME("default action not implemented\n");
2409 return NS_ERROR_NOT_IMPLEMENTED;
2412 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2414 nsWineURI *This = impl_from_nsIURL(iface);
2416 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2419 invalidate_uri(This);
2420 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2423 FIXME("default action not implemented\n");
2424 return NS_ERROR_NOT_IMPLEMENTED;
2427 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2429 nsWineURI *This = impl_from_nsIURL(iface);
2431 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2434 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2436 FIXME("default action not implemented\n");
2437 return NS_ERROR_NOT_IMPLEMENTED;
2440 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2442 nsWineURI *This = impl_from_nsIURL(iface);
2444 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2447 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2449 FIXME("default action not implemented\n");
2450 return NS_ERROR_NOT_IMPLEMENTED;
2453 static const nsIURLVtbl nsURLVtbl = {
2454 nsURI_QueryInterface,
2482 nsURI_GetOriginCharset,
2495 nsURL_GetFileBaseName,
2496 nsURL_SetFileBaseName,
2497 nsURL_GetFileExtension,
2498 nsURL_SetFileExtension,
2499 nsURL_GetCommonBaseSpec,
2500 nsURL_GetRelativeSpec
2503 static nsresult create_nsuri(IUri *iuri, nsIURI *nsuri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2505 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2507 ret->nsIURL_iface.lpVtbl = &nsURLVtbl;
2511 set_uri_nscontainer(ret, container);
2512 set_uri_window(ret, window);
2518 nsIURI_QueryInterface(nsuri, &IID_nsIURL, (void**)&ret->nsurl);
2520 TRACE("retval=%p\n", ret);
2525 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2532 hres = CreateUri(url, 0, 0, &iuri);
2536 nsres = create_nsuri(iuri, NULL, window, window->doc_obj->nscontainer, &uri);
2538 if(NS_FAILED(nsres))
2541 uri->is_doc_uri = TRUE;
2547 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2552 if(!ensure_uri(uri))
2553 return NS_ERROR_UNEXPECTED;
2555 channel = heap_alloc_zero(sizeof(nsChannel));
2557 return NS_ERROR_OUT_OF_MEMORY;
2559 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2560 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2561 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2563 channel->request_method = METHOD_GET;
2564 list_init(&channel->response_headers);
2565 list_init(&channel->request_headers);
2567 nsIURL_AddRef(&uri->nsIURL_iface);
2570 hres = IUri_GetScheme(uri->uri, &channel->url_scheme);
2572 channel->url_scheme = URL_SCHEME_UNKNOWN;
2578 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
2580 HTMLWindow *window = NULL;
2587 hres = CreateUri(url, 0, 0, &iuri);
2591 if(orig_channel->uri->window_ref)
2592 window = orig_channel->uri->window_ref->window;
2593 nsres = create_nsuri(iuri, NULL, window, NULL, &uri);
2595 if(NS_FAILED(nsres))
2598 nsres = create_nschannel(uri, &channel);
2599 nsIURL_Release(&uri->nsIURL_iface);
2600 if(NS_FAILED(nsres))
2603 if(orig_channel->load_group) {
2604 nsILoadGroup_AddRef(orig_channel->load_group);
2605 channel->load_group = orig_channel->load_group;
2608 if(orig_channel->notif_callback) {
2609 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
2610 channel->notif_callback = orig_channel->notif_callback;
2613 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
2615 if(orig_channel->request_method == METHOD_POST)
2616 FIXME("unsupported POST method\n");
2618 if(orig_channel->original_uri) {
2619 nsIURI_AddRef(orig_channel->original_uri);
2620 channel->original_uri = orig_channel->original_uri;
2623 if(orig_channel->referrer) {
2624 nsIURI_AddRef(orig_channel->referrer);
2625 channel->referrer = orig_channel->referrer;
2633 nsIProtocolHandler nsIProtocolHandler_iface;
2637 nsIProtocolHandler *nshandler;
2638 } nsProtocolHandler;
2640 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
2642 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
2645 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2648 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2652 if(IsEqualGUID(&IID_nsISupports, riid)) {
2653 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2654 *result = &This->nsIProtocolHandler_iface;
2655 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2656 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2657 *result = &This->nsIProtocolHandler_iface;
2658 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2659 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2660 return NS_NOINTERFACE;
2664 nsISupports_AddRef((nsISupports*)*result);
2668 WARN("(%s %p)\n", debugstr_guid(riid), result);
2669 return NS_NOINTERFACE;
2672 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2674 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2675 LONG ref = InterlockedIncrement(&This->ref);
2677 TRACE("(%p) ref=%d\n", This, ref);
2682 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2684 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2685 LONG ref = InterlockedDecrement(&This->ref);
2687 TRACE("(%p) ref=%d\n", This, ref);
2691 nsIProtocolHandler_Release(This->nshandler);
2698 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2700 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2702 TRACE("(%p)->(%p)\n", This, aScheme);
2705 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2706 return NS_ERROR_NOT_IMPLEMENTED;
2709 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2710 PRInt32 *aDefaultPort)
2712 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2714 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2717 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2718 return NS_ERROR_NOT_IMPLEMENTED;
2721 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2722 PRUint32 *aProtocolFlags)
2724 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2726 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2729 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2730 return NS_ERROR_NOT_IMPLEMENTED;
2733 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2734 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2736 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2738 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2742 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2743 return NS_ERROR_NOT_IMPLEMENTED;
2746 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2747 nsIURI *aURI, nsIChannel **_retval)
2749 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2751 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2754 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2755 return NS_ERROR_NOT_IMPLEMENTED;
2758 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2759 PRInt32 port, const char *scheme, PRBool *_retval)
2761 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
2763 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2766 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2767 return NS_ERROR_NOT_IMPLEMENTED;
2770 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2771 nsProtocolHandler_QueryInterface,
2772 nsProtocolHandler_AddRef,
2773 nsProtocolHandler_Release,
2774 nsProtocolHandler_GetScheme,
2775 nsProtocolHandler_GetDefaultPort,
2776 nsProtocolHandler_GetProtocolFlags,
2777 nsProtocolHandler_NewURI,
2778 nsProtocolHandler_NewChannel,
2779 nsProtocolHandler_AllowPort
2782 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2784 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2786 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
2788 ret->nshandler = nshandler;
2790 return &ret->nsIProtocolHandler_iface;
2793 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
2795 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2800 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2805 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2806 nsIProtocolHandler **_retval)
2808 nsIExternalProtocolHandler *nsexthandler;
2809 nsIProtocolHandler *nshandler;
2812 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2814 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2815 if(NS_FAILED(nsres)) {
2816 WARN("GetProtocolHandler failed: %08x\n", nsres);
2820 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2821 (void**)&nsexthandler);
2822 if(NS_FAILED(nsres)) {
2823 *_retval = nshandler;
2827 nsIExternalProtocolHandler_Release(nsexthandler);
2828 *_retval = create_protocol_handler(nshandler);
2829 TRACE("return %p\n", *_retval);
2833 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2836 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2837 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2840 static BOOL is_gecko_special_uri(const char *spec)
2842 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
2845 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2846 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2850 if(!strncasecmp(spec, "file:", 5)) {
2851 const char *ptr = spec+5;
2854 return is_gecko_path(ptr);
2860 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2861 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2863 nsWineURI *wine_uri, *base_wine_uri = NULL;
2864 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
2865 HTMLWindow *window = NULL;
2866 const char *spec = NULL;
2872 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2875 nsACString_GetData(aSpec, &spec);
2876 if(is_gecko_special_uri(spec))
2877 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2879 if(!strncmp(spec, "wine:", 5))
2883 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
2884 if(NS_SUCCEEDED(nsres)) {
2885 if(!ensure_uri(base_wine_uri))
2886 return NS_ERROR_UNEXPECTED;
2887 if(base_wine_uri->window_ref)
2888 window = base_wine_uri->window_ref->window;
2890 WARN("Could not get base nsWineURI: %08x\n", nsres);
2894 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
2897 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2900 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
2902 hres = CreateUri(new_spec, 0, 0, &urlmon_uri);
2904 WARN("CreateUri failed: %08x\n", hres);
2907 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2908 if(NS_FAILED(nsres))
2909 TRACE("NewURI failed: %08x\n", nsres);
2916 nsres = create_nsuri(urlmon_uri, uri, window, NULL, &wine_uri);
2917 IUri_Release(urlmon_uri);
2919 nsIURI_Release(&base_wine_uri->nsIURL_iface);
2920 if(NS_FAILED(nsres))
2923 *_retval = (nsIURI*)&wine_uri->nsIURL_iface;
2927 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2930 TRACE("(%p %p)\n", aFile, _retval);
2931 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2934 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2935 nsIChannel **_retval)
2937 nsWineURI *wine_uri;
2941 TRACE("(%p %p)\n", aURI, _retval);
2943 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2944 if(NS_FAILED(nsres)) {
2945 TRACE("Could not get nsWineURI: %08x\n", nsres);
2946 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2949 nsres = create_nschannel(wine_uri, &ret);
2950 nsIURL_Release(&wine_uri->nsIURL_iface);
2951 if(NS_FAILED(nsres))
2954 nsIURI_AddRef(aURI);
2955 ret->original_uri = aURI;
2957 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
2961 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2962 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2964 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
2965 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2968 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2970 TRACE("(%p)\n", aOffline);
2971 return nsIIOService_GetOffline(nsio, aOffline);
2974 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2976 TRACE("(%x)\n", aOffline);
2977 return nsIIOService_SetOffline(nsio, aOffline);
2980 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2981 const char *aScheme, PRBool *_retval)
2983 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2984 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2987 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2988 nsACString * _retval)
2990 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
2991 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2994 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2995 nsIOService_QueryInterface,
2997 nsIOService_Release,
2998 nsIOService_GetProtocolHandler,
2999 nsIOService_GetProtocolFlags,
3001 nsIOService_NewFileURI,
3002 nsIOService_NewChannelFromURI,
3003 nsIOService_NewChannel,
3004 nsIOService_GetOffline,
3005 nsIOService_SetOffline,
3006 nsIOService_AllowPort,
3007 nsIOService_ExtractScheme
3010 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3012 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3015 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3018 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3023 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3028 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3029 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
3031 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3033 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3036 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
3040 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3043 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
3045 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3047 if(aFlags == (1<<11)) {
3052 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3055 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3057 TRACE("(%p %p)\n", aURI, _retval);
3059 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3062 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3064 TRACE("(%p %p)\n", aURI, _retval);
3066 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3069 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3070 PRUint32 aEscapeType, nsACString *_retval)
3072 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3074 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3077 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
3078 nsACString *_retval)
3080 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3082 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3085 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3086 PRUint32 aFlags, nsACString *_retval)
3088 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3090 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3093 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3094 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
3096 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3097 aCharsetEnd, _retval);
3099 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3102 static const nsINetUtilVtbl nsNetUtilVtbl = {
3103 nsNetUtil_QueryInterface,
3106 nsNetUtil_ParseContentType,
3107 nsNetUtil_ProtocolHasFlags,
3108 nsNetUtil_URIChainHasFlags,
3109 nsNetUtil_ToImmutableURI,
3110 nsNetUtil_NewSimpleNestedURI,
3111 nsNetUtil_EscapeString,
3112 nsNetUtil_EscapeURL,
3113 nsNetUtil_UnescapeString,
3114 nsNetUtil_ExtractCharsetFromContentType
3117 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3119 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3124 if(IsEqualGUID(&IID_nsISupports, riid))
3125 *result = &nsIOService;
3126 else if(IsEqualGUID(&IID_nsIIOService, riid))
3127 *result = &nsIOService;
3128 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3129 *result = &nsNetUtil;
3132 nsISupports_AddRef((nsISupports*)*result);
3136 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3137 return NS_NOINTERFACE;
3140 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3145 if(IsEqualGUID(&IID_nsISupports, riid)) {
3146 TRACE("(IID_nsISupports %p)\n", result);
3148 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3149 TRACE("(IID_nsIFactory %p)\n", result);
3154 nsIFactory_AddRef(iface);
3158 WARN("(%s %p)\n", debugstr_guid(riid), result);
3159 return NS_NOINTERFACE;
3162 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3167 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3172 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3173 nsISupports *aOuter, const nsIID *iid, void **result)
3175 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3178 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
3180 WARN("(%x)\n", lock);
3184 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3185 nsIOServiceFactory_QueryInterface,
3186 nsIOServiceFactory_AddRef,
3187 nsIOServiceFactory_Release,
3188 nsIOServiceFactory_CreateInstance,
3189 nsIOServiceFactory_LockFactory
3192 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3194 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3196 OLECHAR *new_url = NULL;
3201 if(!doc->hostui || !ensure_uri(uri))
3204 hres = IUri_GetDisplayUri(uri->uri, &url);
3208 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3209 if(hres == S_OK && new_url) {
3210 if(strcmpW(url, new_url)) {
3211 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3214 CoTaskMemFree(new_url);
3221 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
3223 nsWineURI *wine_uri;
3228 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3229 if(NS_FAILED(nsres)) {
3230 WARN("Could not get nsWineURI: %08x\n", nsres);
3231 return NS_ERROR_NOT_IMPLEMENTED;
3234 if(!wine_uri->is_doc_uri) {
3235 wine_uri->is_doc_uri = TRUE;
3237 if(!wine_uri->container) {
3238 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3239 wine_uri->container = nscontainer;
3242 if(nscontainer->doc)
3243 *_retval = translate_url(nscontainer->doc, wine_uri);
3246 nsIURI_Release(&wine_uri->nsIURL_iface);
3250 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3252 nsIFactory *old_factory = NULL;
3255 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3256 &IID_nsIFactory, (void**)&old_factory);
3257 if(NS_FAILED(nsres)) {
3258 ERR("Could not get factory: %08x\n", nsres);
3262 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3263 if(NS_FAILED(nsres)) {
3264 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3265 nsIFactory_Release(old_factory);
3269 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3270 if(NS_FAILED(nsres)) {
3271 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3272 nsIIOService_Release(nsio);
3276 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3277 nsIFactory_Release(old_factory);
3278 if(NS_FAILED(nsres))
3279 ERR("UnregisterFactory failed: %08x\n", nsres);
3281 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3282 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3283 if(NS_FAILED(nsres))
3284 ERR("RegisterFactory failed: %08x\n", nsres);
3287 void release_nsio(void)
3290 nsINetUtil_Release(net_util);
3295 nsIIOService_Release(nsio);