wininet: Only accept proxy and proxy bypass if type is INTERNET_OPEN_TYPE_PROXY.
[wine.git] / dlls / mshtml / nsio.c
blobc631cbbc049f96d06886798e7935279083a2a46f
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <assert.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "ole2.h"
31 #include "shlguid.h"
32 #include "wininet.h"
33 #include "shlwapi.h"
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
38 #include "binding.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 #define NS_IOSERVICE_CLASSNAME "nsIOService"
43 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
45 static const IID NS_IOSERVICE_CID =
46 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 static const IID IID_nsWineURI =
48 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
50 static nsIIOService *nsio = NULL;
51 static nsINetUtil *net_util;
53 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
55 struct nsWineURI {
56 nsIFileURL nsIFileURL_iface; /* For non-file URL objects, it's just nsIURL */
57 nsIStandardURL nsIStandardURL_iface;
59 LONG ref;
61 NSContainer *container;
62 windowref_t *window_ref;
63 nsChannelBSC *channel_bsc;
64 IUri *uri;
65 IUriBuilder *uri_builder;
66 char *origin_charset;
67 BOOL is_doc_uri;
68 BOOL is_mutable;
69 DWORD scheme;
72 static BOOL ensure_uri(nsWineURI *This)
74 HRESULT hres;
76 assert(This->uri || This->uri_builder);
78 if(!This->uri) {
79 hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
80 if(FAILED(hres)) {
81 WARN("CreateUriSimple failed: %08x\n", hres);
82 return FALSE;
86 return TRUE;
89 IUri *nsuri_get_uri(nsWineURI *nsuri)
91 if(!ensure_uri(nsuri))
92 return NULL;
94 IUri_AddRef(nsuri->uri);
95 return nsuri->uri;
98 IUri *get_uri_nofrag(IUri *uri)
100 IUriBuilder *uri_builder;
101 IUri *ret;
102 BOOL b;
103 HRESULT hres;
105 hres = IUri_HasProperty(uri, Uri_PROPERTY_FRAGMENT, &b);
106 if(SUCCEEDED(hres) && !b) {
107 IUri_AddRef(uri);
108 return uri;
111 hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
112 if(FAILED(hres))
113 return NULL;
115 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_FRAGMENT);
116 if(SUCCEEDED(hres))
117 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &ret);
118 IUriBuilder_Release(uri_builder);
119 if(FAILED(hres))
120 return NULL;
122 return ret;
125 static BOOL compare_ignoring_frag(IUri *uri1, IUri *uri2)
127 IUri *uri_nofrag1, *uri_nofrag2;
128 BOOL ret = FALSE;
130 uri_nofrag1 = get_uri_nofrag(uri1);
131 if(!uri_nofrag1)
132 return FALSE;
134 uri_nofrag2 = get_uri_nofrag(uri2);
135 if(uri_nofrag2) {
136 IUri_IsEqual(uri_nofrag1, uri_nofrag2, &ret);
137 IUri_Release(uri_nofrag2);
140 IUri_Release(uri_nofrag1);
141 return ret;
144 static nsresult create_nsuri(IUri*,HTMLOuterWindow*,NSContainer*,const char*,nsWineURI**);
146 static const char *debugstr_nsacstr(const nsACString *nsstr)
148 const char *data;
150 nsACString_GetData(nsstr, &data);
151 return debugstr_a(data);
154 static nsresult return_wstr_nsacstr(nsACString *ret_str, const WCHAR *str, int len)
156 char *stra;
157 int lena;
159 TRACE("returning %s\n", debugstr_wn(str, len));
161 if(!*str) {
162 nsACString_SetData(ret_str, "");
163 return NS_OK;
166 lena = WideCharToMultiByte(CP_UTF8, 0, str, len, NULL, 0, NULL, NULL);
167 stra = heap_alloc(lena+1);
168 if(!stra)
169 return NS_ERROR_OUT_OF_MEMORY;
171 WideCharToMultiByte(CP_UTF8, 0, str, len, stra, lena, NULL, NULL);
172 stra[lena] = 0;
174 nsACString_SetData(ret_str, stra);
175 heap_free(stra);
176 return NS_OK;
179 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
181 const WCHAR *ptr = nsuri;
183 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
185 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
186 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
188 if(*ptr || ret_empty) {
189 *ret = SysAllocString(ptr);
190 if(!*ret)
191 return E_OUTOFMEMORY;
192 }else {
193 *ret = NULL;
196 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
197 return S_OK;
200 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
202 IOleCommandTarget *cmdtrg = NULL;
203 HRESULT hres;
205 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
206 if(SUCCEEDED(hres)) {
207 VARIANT varUrl, varRes;
209 V_VT(&varUrl) = VT_BSTR;
210 V_BSTR(&varUrl) = url;
211 V_VT(&varRes) = VT_BOOL;
213 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
215 IOleCommandTarget_Release(cmdtrg);
217 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
218 TRACE("got VARIANT_FALSE, do not load\n");
219 return FALSE;
223 return TRUE;
226 static nsresult before_async_open(nsChannel *channel, NSContainer *container, BOOL *cancel)
228 HTMLDocumentObj *doc = container->doc;
229 BSTR display_uri;
230 HRESULT hres;
232 if(!doc->client) {
233 *cancel = TRUE;
234 return NS_OK;
237 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
238 if(FAILED(hres))
239 return NS_ERROR_FAILURE;
241 if(!exec_shldocvw_67(doc, display_uri)) {
242 SysFreeString(display_uri);
243 *cancel = FALSE;
244 return NS_OK;
247 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, 0, cancel);
248 SysFreeString(display_uri);
249 if(FAILED(hres))
250 *cancel = TRUE;
251 return NS_OK;
254 HRESULT load_nsuri(HTMLOuterWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
256 nsIWebNavigation *web_navigation;
257 nsIDocShell *doc_shell;
258 HTMLDocumentNode *doc;
259 nsresult nsres;
261 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
262 if(NS_FAILED(nsres)) {
263 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
264 return E_FAIL;
267 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
268 nsIWebNavigation_Release(web_navigation);
269 if(NS_FAILED(nsres)) {
270 ERR("Could not get nsIDocShell: %08x\n", nsres);
271 return E_FAIL;
274 uri->channel_bsc = channelbsc;
275 doc = window->base.inner_window->doc;
276 doc->skip_mutation_notif = TRUE;
277 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIFileURL_iface, NULL, flags, FALSE);
278 if(doc == window->base.inner_window->doc)
279 doc->skip_mutation_notif = FALSE;
280 uri->channel_bsc = NULL;
281 nsIDocShell_Release(doc_shell);
282 if(NS_FAILED(nsres)) {
283 WARN("LoadURI failed: %08x\n", nsres);
284 return E_FAIL;
287 return S_OK;
290 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
292 if(This->container) {
293 if(This->container == nscontainer)
294 return;
295 TRACE("Changing %p -> %p\n", This->container, nscontainer);
296 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
299 if(nscontainer)
300 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
301 This->container = nscontainer;
304 static void set_uri_window(nsWineURI *This, HTMLOuterWindow *window)
306 if(This->window_ref) {
307 if(This->window_ref->window == window)
308 return;
309 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
310 windowref_release(This->window_ref);
313 if(window) {
314 windowref_addref(window->window_ref);
315 This->window_ref = window->window_ref;
317 if(window->doc_obj)
318 set_uri_nscontainer(This, window->doc_obj->nscontainer);
319 }else {
320 This->window_ref = NULL;
324 static inline BOOL is_http_channel(nsChannel *This)
326 return This->uri->scheme == URL_SCHEME_HTTP || This->uri->scheme == URL_SCHEME_HTTPS;
329 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
331 http_header_t *iter;
333 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
334 if(!strcmpiW(iter->header, name))
335 return iter;
338 return NULL;
341 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
342 nsACString *_retval)
344 const char *header_namea;
345 http_header_t *header;
346 WCHAR *header_name;
347 char *data;
349 nsACString_GetData(header_name_str, &header_namea);
350 header_name = heap_strdupAtoW(header_namea);
351 if(!header_name)
352 return NS_ERROR_UNEXPECTED;
354 header = find_http_header(headers, header_name, strlenW(header_name));
355 heap_free(header_name);
356 if(!header)
357 return NS_ERROR_NOT_AVAILABLE;
359 data = heap_strdupWtoA(header->data);
360 if(!data)
361 return NS_ERROR_UNEXPECTED;
363 TRACE("%s -> %s\n", debugstr_a(header_namea), debugstr_a(data));
364 nsACString_SetData(_retval, data);
365 heap_free(data);
366 return NS_OK;
369 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
370 const WCHAR *value, int value_len)
372 http_header_t *header;
374 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
376 header = find_http_header(headers, name, name_len);
377 if(header) {
378 WCHAR *new_data;
380 new_data = heap_strndupW(value, value_len);
381 if(!new_data)
382 return E_OUTOFMEMORY;
384 heap_free(header->data);
385 header->data = new_data;
386 }else {
387 header = heap_alloc(sizeof(http_header_t));
388 if(!header)
389 return E_OUTOFMEMORY;
391 header->header = heap_strndupW(name, name_len);
392 header->data = heap_strndupW(value, value_len);
393 if(!header->header || !header->data) {
394 heap_free(header->header);
395 heap_free(header->data);
396 heap_free(header);
397 return E_OUTOFMEMORY;
400 list_add_tail(headers, &header->entry);
403 return S_OK;
406 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
407 const nsACString *value_str)
409 const char *namea, *valuea;
410 WCHAR *name, *value;
411 HRESULT hres;
413 nsACString_GetData(name_str, &namea);
414 name = heap_strdupAtoW(namea);
415 if(!name)
416 return NS_ERROR_UNEXPECTED;
418 nsACString_GetData(value_str, &valuea);
419 value = heap_strdupAtoW(valuea);
420 if(!value) {
421 heap_free(name);
422 return NS_ERROR_UNEXPECTED;
425 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
427 heap_free(name);
428 heap_free(value);
429 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
432 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
434 nsACString header_str, value_str;
435 char *header, *value;
436 http_header_t *iter;
437 nsresult nsres;
439 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
440 header = heap_strdupWtoA(iter->header);
441 if(!header)
442 return NS_ERROR_OUT_OF_MEMORY;
444 value = heap_strdupWtoA(iter->data);
445 if(!value) {
446 heap_free(header);
447 return NS_ERROR_OUT_OF_MEMORY;
450 nsACString_InitDepend(&header_str, header);
451 nsACString_InitDepend(&value_str, value);
452 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
453 nsACString_Finish(&header_str);
454 nsACString_Finish(&value_str);
455 heap_free(header);
456 heap_free(value);
457 if(NS_FAILED(nsres))
458 break;
461 return NS_OK;
464 static void free_http_headers(struct list *list)
466 http_header_t *iter, *iter_next;
468 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
469 list_remove(&iter->entry);
470 heap_free(iter->header);
471 heap_free(iter->data);
472 heap_free(iter);
476 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
478 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
481 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
483 nsChannel *This = impl_from_nsIHttpChannel(iface);
485 if(IsEqualGUID(&IID_nsISupports, riid)) {
486 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
487 *result = &This->nsIHttpChannel_iface;
488 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
489 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
490 *result = &This->nsIHttpChannel_iface;
491 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
492 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
493 *result = &This->nsIHttpChannel_iface;
494 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
495 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
496 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
497 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
498 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
499 *result = &This->nsIUploadChannel_iface;
500 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
501 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
502 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
503 }else {
504 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
505 *result = NULL;
508 if(*result) {
509 nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
510 return NS_OK;
513 return NS_NOINTERFACE;
516 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
518 nsChannel *This = impl_from_nsIHttpChannel(iface);
519 nsrefcnt ref = InterlockedIncrement(&This->ref);
521 TRACE("(%p) ref=%d\n", This, ref);
523 return ref;
526 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
528 nsChannel *This = impl_from_nsIHttpChannel(iface);
529 LONG ref = InterlockedDecrement(&This->ref);
531 if(!ref) {
532 nsIFileURL_Release(&This->uri->nsIFileURL_iface);
533 if(This->owner)
534 nsISupports_Release(This->owner);
535 if(This->post_data_stream)
536 nsIInputStream_Release(This->post_data_stream);
537 if(This->load_group)
538 nsILoadGroup_Release(This->load_group);
539 if(This->notif_callback)
540 nsIInterfaceRequestor_Release(This->notif_callback);
541 if(This->original_uri)
542 nsIURI_Release(This->original_uri);
543 if(This->referrer)
544 nsIURI_Release(This->referrer);
546 free_http_headers(&This->response_headers);
547 free_http_headers(&This->request_headers);
549 heap_free(This->content_type);
550 heap_free(This->charset);
551 heap_free(This);
554 return ref;
557 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
559 nsChannel *This = impl_from_nsIHttpChannel(iface);
561 TRACE("(%p)->(%p)\n", This, aName);
563 return nsIFileURL_GetSpec(&This->uri->nsIFileURL_iface, aName);
566 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, cpp_bool *_retval)
568 nsChannel *This = impl_from_nsIHttpChannel(iface);
570 FIXME("(%p)->(%p)\n", This, _retval);
572 return NS_ERROR_NOT_IMPLEMENTED;
575 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
577 nsChannel *This = impl_from_nsIHttpChannel(iface);
579 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
581 return *aStatus = NS_OK;
584 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
586 nsChannel *This = impl_from_nsIHttpChannel(iface);
588 FIXME("(%p)->(%08x)\n", This, aStatus);
590 return NS_ERROR_NOT_IMPLEMENTED;
593 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
595 nsChannel *This = impl_from_nsIHttpChannel(iface);
597 FIXME("(%p)\n", This);
599 return NS_ERROR_NOT_IMPLEMENTED;
602 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
604 nsChannel *This = impl_from_nsIHttpChannel(iface);
606 FIXME("(%p)\n", This);
608 return NS_ERROR_NOT_IMPLEMENTED;
611 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
613 nsChannel *This = impl_from_nsIHttpChannel(iface);
615 TRACE("(%p)->(%p)\n", This, aLoadGroup);
617 if(This->load_group)
618 nsILoadGroup_AddRef(This->load_group);
620 *aLoadGroup = This->load_group;
621 return NS_OK;
624 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
626 nsChannel *This = impl_from_nsIHttpChannel(iface);
628 TRACE("(%p)->(%p)\n", This, aLoadGroup);
630 if(This->load_group)
631 nsILoadGroup_Release(This->load_group);
632 if(aLoadGroup)
633 nsILoadGroup_AddRef(aLoadGroup);
634 This->load_group = aLoadGroup;
636 return NS_OK;
639 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
641 nsChannel *This = impl_from_nsIHttpChannel(iface);
643 TRACE("(%p)->(%p)\n", This, aLoadFlags);
645 *aLoadFlags = This->load_flags;
646 return NS_OK;
649 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
651 nsChannel *This = impl_from_nsIHttpChannel(iface);
653 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
655 This->load_flags = aLoadFlags;
656 return NS_OK;
659 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
661 nsChannel *This = impl_from_nsIHttpChannel(iface);
663 TRACE("(%p)->(%p)\n", This, aOriginalURI);
665 if(This->original_uri)
666 nsIURI_AddRef(This->original_uri);
668 *aOriginalURI = This->original_uri;
669 return NS_OK;
672 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
674 nsChannel *This = impl_from_nsIHttpChannel(iface);
676 TRACE("(%p)->(%p)\n", This, aOriginalURI);
678 if(This->original_uri)
679 nsIURI_Release(This->original_uri);
681 nsIURI_AddRef(aOriginalURI);
682 This->original_uri = aOriginalURI;
683 return NS_OK;
686 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
688 nsChannel *This = impl_from_nsIHttpChannel(iface);
690 TRACE("(%p)->(%p)\n", This, aURI);
692 nsIFileURL_AddRef(&This->uri->nsIFileURL_iface);
693 *aURI = (nsIURI*)This->uri;
695 return NS_OK;
698 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
700 nsChannel *This = impl_from_nsIHttpChannel(iface);
702 TRACE("(%p)->(%p)\n", This, aOwner);
704 if(This->owner)
705 nsISupports_AddRef(This->owner);
706 *aOwner = This->owner;
708 return NS_OK;
711 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
713 nsChannel *This = impl_from_nsIHttpChannel(iface);
715 TRACE("(%p)->(%p)\n", This, aOwner);
717 if(aOwner)
718 nsISupports_AddRef(aOwner);
719 if(This->owner)
720 nsISupports_Release(This->owner);
721 This->owner = aOwner;
723 return NS_OK;
726 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
727 nsIInterfaceRequestor **aNotificationCallbacks)
729 nsChannel *This = impl_from_nsIHttpChannel(iface);
731 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
733 if(This->notif_callback)
734 nsIInterfaceRequestor_AddRef(This->notif_callback);
735 *aNotificationCallbacks = This->notif_callback;
737 return NS_OK;
740 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
741 nsIInterfaceRequestor *aNotificationCallbacks)
743 nsChannel *This = impl_from_nsIHttpChannel(iface);
745 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
747 if(This->notif_callback)
748 nsIInterfaceRequestor_Release(This->notif_callback);
749 if(aNotificationCallbacks)
750 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
752 This->notif_callback = aNotificationCallbacks;
754 return NS_OK;
757 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
759 nsChannel *This = impl_from_nsIHttpChannel(iface);
761 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
763 return NS_ERROR_NOT_IMPLEMENTED;
766 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
768 nsChannel *This = impl_from_nsIHttpChannel(iface);
770 TRACE("(%p)->(%p)\n", This, aContentType);
772 if(This->content_type) {
773 nsACString_SetData(aContentType, This->content_type);
774 return S_OK;
777 if(This->uri->is_doc_uri) {
778 WARN("Document channel with no MIME set. Assuming text/html\n");
779 nsACString_SetData(aContentType, "text/html");
780 return S_OK;
783 WARN("unknown type\n");
784 return NS_ERROR_FAILURE;
787 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
788 const nsACString *aContentType)
790 nsChannel *This = impl_from_nsIHttpChannel(iface);
791 const char *content_type;
793 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
795 nsACString_GetData(aContentType, &content_type);
796 heap_free(This->content_type);
797 This->content_type = heap_strdupA(content_type);
799 return NS_OK;
802 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
803 nsACString *aContentCharset)
805 nsChannel *This = impl_from_nsIHttpChannel(iface);
807 TRACE("(%p)->(%p)\n", This, aContentCharset);
809 if(This->charset) {
810 nsACString_SetData(aContentCharset, This->charset);
811 return NS_OK;
814 nsACString_SetData(aContentCharset, "");
815 return NS_OK;
818 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
819 const nsACString *aContentCharset)
821 nsChannel *This = impl_from_nsIHttpChannel(iface);
822 const char *data;
823 char *charset;
825 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
827 nsACString_GetData(aContentCharset, &data);
828 charset = heap_strdupA(data);
829 if(!charset)
830 return NS_ERROR_OUT_OF_MEMORY;
832 heap_free(This->charset);
833 This->charset = charset;
834 return NS_OK;
837 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, LONG *aContentLength)
839 nsChannel *This = impl_from_nsIHttpChannel(iface);
841 FIXME("(%p)->(%p)\n", This, aContentLength);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, LONG aContentLength)
848 nsChannel *This = impl_from_nsIHttpChannel(iface);
850 FIXME("(%p)->(%d)\n", This, aContentLength);
852 return NS_ERROR_NOT_IMPLEMENTED;
855 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
857 nsChannel *This = impl_from_nsIHttpChannel(iface);
859 FIXME("(%p)->(%p)\n", This, _retval);
861 return NS_ERROR_NOT_IMPLEMENTED;
864 static HTMLOuterWindow *get_window_from_load_group(nsChannel *This)
866 HTMLOuterWindow *window;
867 nsIChannel *channel;
868 nsIRequest *req;
869 nsWineURI *wine_uri;
870 nsIURI *uri;
871 nsresult nsres;
873 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
874 if(NS_FAILED(nsres)) {
875 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
876 return NULL;
879 if(!req)
880 return NULL;
882 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
883 nsIRequest_Release(req);
884 if(NS_FAILED(nsres)) {
885 WARN("Could not get nsIChannel interface: %08x\n", nsres);
886 return NULL;
889 nsres = nsIChannel_GetURI(channel, &uri);
890 nsIChannel_Release(channel);
891 if(NS_FAILED(nsres)) {
892 ERR("GetURI failed: %08x\n", nsres);
893 return NULL;
896 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
897 nsIURI_Release(uri);
898 if(NS_FAILED(nsres)) {
899 TRACE("Could not get nsWineURI: %08x\n", nsres);
900 return NULL;
903 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
904 if(window)
905 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
906 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
908 return window;
911 static HTMLOuterWindow *get_channel_window(nsChannel *This)
913 nsIWebProgress *web_progress;
914 nsIDOMWindow *nswindow;
915 HTMLOuterWindow *window;
916 nsresult nsres;
918 if(This->load_group) {
919 nsIRequestObserver *req_observer;
921 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
922 if(NS_FAILED(nsres) || !req_observer) {
923 ERR("GetGroupObserver failed: %08x\n", nsres);
924 return NULL;
927 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
928 nsIRequestObserver_Release(req_observer);
929 if(NS_FAILED(nsres)) {
930 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
931 return NULL;
933 }else if(This->notif_callback) {
934 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
935 if(NS_FAILED(nsres)) {
936 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
937 return NULL;
939 }else {
940 ERR("no load group nor notif callback\n");
941 return NULL;
944 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
945 nsIWebProgress_Release(web_progress);
946 if(NS_FAILED(nsres) || !nswindow) {
947 ERR("GetDOMWindow failed: %08x\n", nsres);
948 return NULL;
951 window = nswindow_to_window(nswindow);
952 nsIDOMWindow_Release(nswindow);
954 if(window)
955 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
956 else
957 FIXME("NULL window for %p\n", nswindow);
958 return window;
961 typedef struct {
962 task_t header;
963 HTMLInnerWindow *window;
964 nsChannelBSC *bscallback;
965 } start_binding_task_t;
967 static void start_binding_proc(task_t *_task)
969 start_binding_task_t *task = (start_binding_task_t*)_task;
971 start_binding(task->window, (BSCallback*)task->bscallback, NULL);
974 static void start_binding_task_destr(task_t *_task)
976 start_binding_task_t *task = (start_binding_task_t*)_task;
978 IBindStatusCallback_Release(&task->bscallback->bsc.IBindStatusCallback_iface);
979 heap_free(task);
982 static nsresult async_open(nsChannel *This, HTMLOuterWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
983 nsISupports *context)
985 nsChannelBSC *bscallback;
986 IMoniker *mon = NULL;
987 HRESULT hres;
989 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
990 if(FAILED(hres)) {
991 WARN("CreateURLMoniker failed: %08x\n", hres);
992 return NS_ERROR_UNEXPECTED;
995 if(is_doc_channel)
996 set_current_mon(window, mon, BINDING_NAVIGATED);
998 hres = create_channelbsc(mon, NULL, NULL, 0, is_doc_channel, &bscallback);
999 IMoniker_Release(mon);
1000 if(FAILED(hres))
1001 return NS_ERROR_UNEXPECTED;
1003 channelbsc_set_channel(bscallback, This, listener, context);
1005 if(is_doc_channel) {
1006 hres = create_pending_window(window, bscallback);
1007 if(SUCCEEDED(hres))
1008 async_start_doc_binding(window, window->pending_window);
1009 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1010 if(FAILED(hres))
1011 return NS_ERROR_UNEXPECTED;
1012 }else {
1013 start_binding_task_t *task;
1015 task = heap_alloc(sizeof(start_binding_task_t));
1016 if(!task) {
1017 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1018 return NS_ERROR_OUT_OF_MEMORY;
1021 task->window = window->base.inner_window;
1022 task->bscallback = bscallback;
1023 hres = push_task(&task->header, start_binding_proc, start_binding_task_destr, window->base.inner_window->task_magic);
1024 if(FAILED(hres))
1025 return NS_ERROR_OUT_OF_MEMORY;
1028 return NS_OK;
1031 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
1032 nsISupports *aContext)
1034 nsChannel *This = impl_from_nsIHttpChannel(iface);
1035 HTMLOuterWindow *window = NULL;
1036 BOOL cancel = FALSE;
1037 nsresult nsres = NS_OK;
1039 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
1041 if(!ensure_uri(This->uri))
1042 return NS_ERROR_FAILURE;
1044 if(TRACE_ON(mshtml)) {
1045 HRESULT hres;
1046 BSTR uri_str;
1048 hres = IUri_GetDisplayUri(This->uri->uri, &uri_str);
1049 if(SUCCEEDED(hres)) {
1050 TRACE("opening %s\n", debugstr_w(uri_str));
1051 SysFreeString(uri_str);
1052 }else {
1053 WARN("GetDisplayUri failed: %08x\n", hres);
1057 if(This->uri->is_doc_uri) {
1058 window = get_channel_window(This);
1059 if(window) {
1060 set_uri_window(This->uri, window);
1061 }else if(This->uri->container) {
1062 BOOL b;
1064 /* nscontainer->doc should be NULL which means navigation to a new window */
1065 if(This->uri->container->doc)
1066 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
1068 nsres = before_async_open(This, This->uri->container, &b);
1069 if(NS_FAILED(nsres))
1070 return nsres;
1071 if(b)
1072 FIXME("Navigation not cancelled\n");
1073 return NS_ERROR_UNEXPECTED;
1077 if(!window) {
1078 if(This->uri->window_ref && This->uri->window_ref->window) {
1079 window = This->uri->window_ref->window;
1080 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1081 }else {
1082 /* FIXME: Analyze removing get_window_from_load_group call */
1083 if(This->load_group)
1084 window = get_window_from_load_group(This);
1085 if(!window)
1086 window = get_channel_window(This);
1087 if(window)
1088 set_uri_window(This->uri, window);
1092 if(!window) {
1093 ERR("window = NULL\n");
1094 return NS_ERROR_UNEXPECTED;
1097 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1098 if(This->uri->channel_bsc) {
1099 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1101 if(window->doc_obj->mime) {
1102 heap_free(This->content_type);
1103 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1106 cancel = TRUE;
1107 }else {
1108 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
1109 if(NS_SUCCEEDED(nsres) && cancel) {
1110 TRACE("canceled\n");
1111 nsres = NS_BINDING_ABORTED;
1116 if(!cancel)
1117 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1119 if(NS_SUCCEEDED(nsres) && This->load_group) {
1120 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1121 aContext);
1122 if(NS_FAILED(nsres))
1123 ERR("AddRequest failed: %08x\n", nsres);
1126 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
1127 return nsres;
1130 static nsresult NSAPI nsChannel_GetContentDisposition(nsIHttpChannel *iface, UINT32 *aContentDisposition)
1132 nsChannel *This = impl_from_nsIHttpChannel(iface);
1133 FIXME("(%p)->(%p)\n", This, aContentDisposition);
1134 return NS_ERROR_NOT_IMPLEMENTED;
1137 static nsresult NSAPI nsChannel_SetContentDisposition(nsIHttpChannel *iface, UINT32 aContentDisposition)
1139 nsChannel *This = impl_from_nsIHttpChannel(iface);
1140 FIXME("(%p)->(%u)\n", This, aContentDisposition);
1141 return NS_ERROR_NOT_IMPLEMENTED;
1144 static nsresult NSAPI nsChannel_GetContentDispositionFilename(nsIHttpChannel *iface, nsAString *aContentDispositionFilename)
1146 nsChannel *This = impl_from_nsIHttpChannel(iface);
1147 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1148 return NS_ERROR_NOT_IMPLEMENTED;
1151 static nsresult NSAPI nsChannel_SetContentDispositionFilename(nsIHttpChannel *iface, const nsAString *aContentDispositionFilename)
1153 nsChannel *This = impl_from_nsIHttpChannel(iface);
1154 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1155 return NS_ERROR_NOT_IMPLEMENTED;
1158 static nsresult NSAPI nsChannel_GetContentDispositionHeader(nsIHttpChannel *iface, nsACString *aContentDispositionHeader)
1160 nsChannel *This = impl_from_nsIHttpChannel(iface);
1161 FIXME("(%p)->(%p)\n", This, aContentDispositionHeader);
1162 return NS_ERROR_NOT_IMPLEMENTED;
1165 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1167 nsChannel *This = impl_from_nsIHttpChannel(iface);
1169 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1171 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1172 return NS_OK;
1175 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1176 const nsACString *aRequestMethod)
1178 nsChannel *This = impl_from_nsIHttpChannel(iface);
1179 const char *method;
1180 unsigned i;
1182 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1184 nsACString_GetData(aRequestMethod, &method);
1185 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1186 if(!strcasecmp(method, request_method_strings[i])) {
1187 This->request_method = i;
1188 return NS_OK;
1192 ERR("Invalid method %s\n", debugstr_a(method));
1193 return NS_ERROR_UNEXPECTED;
1196 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1198 nsChannel *This = impl_from_nsIHttpChannel(iface);
1200 TRACE("(%p)->(%p)\n", This, aReferrer);
1202 if(This->referrer)
1203 nsIURI_AddRef(This->referrer);
1204 *aReferrer = This->referrer;
1205 return NS_OK;
1208 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1210 nsChannel *This = impl_from_nsIHttpChannel(iface);
1212 TRACE("(%p)->(%p)\n", This, aReferrer);
1214 if(aReferrer)
1215 nsIURI_AddRef(aReferrer);
1216 if(This->referrer)
1217 nsIURI_Release(This->referrer);
1218 This->referrer = aReferrer;
1219 return NS_OK;
1222 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1223 const nsACString *aHeader, nsACString *_retval)
1225 nsChannel *This = impl_from_nsIHttpChannel(iface);
1227 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1229 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1232 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1233 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1235 nsChannel *This = impl_from_nsIHttpChannel(iface);
1237 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1239 if(aMerge)
1240 FIXME("aMerge not supported\n");
1242 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1245 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1246 nsIHttpHeaderVisitor *aVisitor)
1248 nsChannel *This = impl_from_nsIHttpChannel(iface);
1250 FIXME("(%p)->(%p)\n", This, aVisitor);
1252 return NS_ERROR_NOT_IMPLEMENTED;
1255 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1257 nsChannel *This = impl_from_nsIHttpChannel(iface);
1259 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1261 return NS_ERROR_NOT_IMPLEMENTED;
1264 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1266 nsChannel *This = impl_from_nsIHttpChannel(iface);
1268 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1270 return NS_ERROR_NOT_IMPLEMENTED;
1273 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, UINT32 *aRedirectionLimit)
1275 nsChannel *This = impl_from_nsIHttpChannel(iface);
1277 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1279 return NS_ERROR_NOT_IMPLEMENTED;
1282 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, UINT32 aRedirectionLimit)
1284 nsChannel *This = impl_from_nsIHttpChannel(iface);
1286 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1288 return NS_ERROR_NOT_IMPLEMENTED;
1291 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, UINT32 *aResponseStatus)
1293 nsChannel *This = impl_from_nsIHttpChannel(iface);
1295 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1297 if(This->response_status) {
1298 *aResponseStatus = This->response_status;
1299 return NS_OK;
1302 WARN("No response status\n");
1303 return NS_ERROR_UNEXPECTED;
1306 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1307 nsACString *aResponseStatusText)
1309 nsChannel *This = impl_from_nsIHttpChannel(iface);
1311 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1313 return NS_ERROR_NOT_IMPLEMENTED;
1316 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1317 cpp_bool *aRequestSucceeded)
1319 nsChannel *This = impl_from_nsIHttpChannel(iface);
1321 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1323 if(!This->response_status)
1324 return NS_ERROR_NOT_AVAILABLE;
1326 *aRequestSucceeded = This->response_status/100 == 2;
1328 return NS_OK;
1331 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1332 const nsACString *header, nsACString *_retval)
1334 nsChannel *This = impl_from_nsIHttpChannel(iface);
1336 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1338 return get_channel_http_header(&This->response_headers, header, _retval);
1341 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1342 const nsACString *header, const nsACString *value, cpp_bool merge)
1344 nsChannel *This = impl_from_nsIHttpChannel(iface);
1346 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1348 return NS_ERROR_NOT_IMPLEMENTED;
1351 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1352 nsIHttpHeaderVisitor *aVisitor)
1354 nsChannel *This = impl_from_nsIHttpChannel(iface);
1356 TRACE("(%p)->(%p)\n", This, aVisitor);
1358 return visit_http_headers(&This->response_headers, aVisitor);
1361 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1363 nsChannel *This = impl_from_nsIHttpChannel(iface);
1364 http_header_t *header;
1366 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1367 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1369 TRACE("(%p)->(%p)\n", This, _retval);
1371 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1372 *_retval = header && !strcmpiW(header->data, no_storeW);
1373 return NS_OK;
1376 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1378 nsChannel *This = impl_from_nsIHttpChannel(iface);
1380 FIXME("(%p)->(%p)\n", This, _retval);
1382 return NS_ERROR_NOT_IMPLEMENTED;
1385 static const nsIHttpChannelVtbl nsChannelVtbl = {
1386 nsChannel_QueryInterface,
1387 nsChannel_AddRef,
1388 nsChannel_Release,
1389 nsChannel_GetName,
1390 nsChannel_IsPending,
1391 nsChannel_GetStatus,
1392 nsChannel_Cancel,
1393 nsChannel_Suspend,
1394 nsChannel_Resume,
1395 nsChannel_GetLoadGroup,
1396 nsChannel_SetLoadGroup,
1397 nsChannel_GetLoadFlags,
1398 nsChannel_SetLoadFlags,
1399 nsChannel_GetOriginalURI,
1400 nsChannel_SetOriginalURI,
1401 nsChannel_GetURI,
1402 nsChannel_GetOwner,
1403 nsChannel_SetOwner,
1404 nsChannel_GetNotificationCallbacks,
1405 nsChannel_SetNotificationCallbacks,
1406 nsChannel_GetSecurityInfo,
1407 nsChannel_GetContentType,
1408 nsChannel_SetContentType,
1409 nsChannel_GetContentCharset,
1410 nsChannel_SetContentCharset,
1411 nsChannel_GetContentLength,
1412 nsChannel_SetContentLength,
1413 nsChannel_Open,
1414 nsChannel_AsyncOpen,
1415 nsChannel_GetContentDisposition,
1416 nsChannel_SetContentDisposition,
1417 nsChannel_GetContentDispositionFilename,
1418 nsChannel_SetContentDispositionFilename,
1419 nsChannel_GetContentDispositionHeader,
1420 nsChannel_GetRequestMethod,
1421 nsChannel_SetRequestMethod,
1422 nsChannel_GetReferrer,
1423 nsChannel_SetReferrer,
1424 nsChannel_GetRequestHeader,
1425 nsChannel_SetRequestHeader,
1426 nsChannel_VisitRequestHeaders,
1427 nsChannel_GetAllowPipelining,
1428 nsChannel_SetAllowPipelining,
1429 nsChannel_GetRedirectionLimit,
1430 nsChannel_SetRedirectionLimit,
1431 nsChannel_GetResponseStatus,
1432 nsChannel_GetResponseStatusText,
1433 nsChannel_GetRequestSucceeded,
1434 nsChannel_GetResponseHeader,
1435 nsChannel_SetResponseHeader,
1436 nsChannel_VisitResponseHeaders,
1437 nsChannel_IsNoStoreResponse,
1438 nsChannel_IsNoCacheResponse
1441 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1443 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1446 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1447 void **result)
1449 nsChannel *This = impl_from_nsIUploadChannel(iface);
1450 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1453 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1455 nsChannel *This = impl_from_nsIUploadChannel(iface);
1456 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1459 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1461 nsChannel *This = impl_from_nsIUploadChannel(iface);
1462 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1465 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1466 nsIInputStream *aStream, const nsACString *aContentType, INT64 aContentLength)
1468 nsChannel *This = impl_from_nsIUploadChannel(iface);
1469 const char *content_type;
1471 static const WCHAR content_typeW[] =
1472 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1474 TRACE("(%p)->(%p %s %s)\n", This, aStream, debugstr_nsacstr(aContentType), wine_dbgstr_longlong(aContentLength));
1476 This->post_data_contains_headers = TRUE;
1478 if(aContentType) {
1479 nsACString_GetData(aContentType, &content_type);
1480 if(*content_type) {
1481 WCHAR *ct;
1483 ct = heap_strdupAtoW(content_type);
1484 if(!ct)
1485 return NS_ERROR_UNEXPECTED;
1487 set_http_header(&This->request_headers, content_typeW,
1488 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1489 heap_free(ct);
1490 This->post_data_contains_headers = FALSE;
1494 if(This->post_data_stream)
1495 nsIInputStream_Release(This->post_data_stream);
1497 if(aContentLength != -1)
1498 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength));
1500 if(This->post_data_stream)
1501 nsIInputStream_Release(This->post_data_stream);
1502 This->post_data_stream = aStream;
1503 if(aStream)
1504 nsIInputStream_AddRef(aStream);
1506 This->request_method = METHOD_POST;
1507 return NS_OK;
1510 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1511 nsIInputStream **aUploadStream)
1513 nsChannel *This = impl_from_nsIUploadChannel(iface);
1515 TRACE("(%p)->(%p)\n", This, aUploadStream);
1517 if(This->post_data_stream)
1518 nsIInputStream_AddRef(This->post_data_stream);
1520 *aUploadStream = This->post_data_stream;
1521 return NS_OK;
1524 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1525 nsUploadChannel_QueryInterface,
1526 nsUploadChannel_AddRef,
1527 nsUploadChannel_Release,
1528 nsUploadChannel_SetUploadStream,
1529 nsUploadChannel_GetUploadStream
1532 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1534 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1537 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1538 void **result)
1540 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1541 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1544 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1546 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1547 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1550 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1552 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1553 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1556 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1558 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1560 FIXME("(%p)->()\n", This);
1562 return NS_ERROR_NOT_IMPLEMENTED;
1565 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1567 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1569 FIXME("(%p)->()\n", This);
1571 return NS_ERROR_NOT_IMPLEMENTED;
1574 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1576 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1578 FIXME("(%p)->()\n", This);
1580 return NS_ERROR_NOT_IMPLEMENTED;
1583 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1585 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1587 FIXME("(%p)->()\n", This);
1589 return NS_ERROR_NOT_IMPLEMENTED;
1592 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1594 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1596 FIXME("(%p)->()\n", This);
1598 return NS_ERROR_NOT_IMPLEMENTED;
1601 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1603 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1605 FIXME("(%p)->()\n", This);
1607 return NS_ERROR_NOT_IMPLEMENTED;
1610 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1612 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1614 FIXME("(%p)->()\n", This);
1616 return NS_ERROR_NOT_IMPLEMENTED;
1619 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1621 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1623 FIXME("(%p)->()\n", This);
1625 return NS_ERROR_NOT_IMPLEMENTED;
1628 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1630 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1632 FIXME("(%p)->(%p)\n", This, aCanceled);
1634 return NS_ERROR_NOT_IMPLEMENTED;
1637 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1639 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1641 FIXME("(%p)->(%p)\n", This, aCanceled);
1643 return NS_ERROR_NOT_IMPLEMENTED;
1646 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1648 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1650 FIXME("(%p)->(%x)\n", This, aCanceled);
1652 return NS_ERROR_NOT_IMPLEMENTED;
1655 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1657 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1659 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1661 return NS_ERROR_NOT_IMPLEMENTED;
1664 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, LONG *aLocalPort)
1666 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1668 FIXME("(%p)->(%p)\n", This, aLocalPort);
1670 return NS_ERROR_NOT_IMPLEMENTED;
1673 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1675 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1677 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1679 return NS_ERROR_NOT_IMPLEMENTED;
1682 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, LONG *aRemotePort)
1684 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1686 FIXME("(%p)->(%p)\n", This, aRemotePort);
1688 return NS_ERROR_NOT_IMPLEMENTED;
1691 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1693 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1695 FIXME("(%p)->(%p)\n", This, cacheKeys);
1697 return NS_ERROR_NOT_IMPLEMENTED;
1700 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1701 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1703 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1704 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1705 return NS_ERROR_NOT_IMPLEMENTED;
1708 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1710 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1711 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1712 return NS_ERROR_NOT_IMPLEMENTED;
1715 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1717 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1718 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1719 return NS_ERROR_NOT_IMPLEMENTED;
1722 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1723 nsHttpChannelInternal_QueryInterface,
1724 nsHttpChannelInternal_AddRef,
1725 nsHttpChannelInternal_Release,
1726 nsHttpChannelInternal_GetDocumentURI,
1727 nsHttpChannelInternal_SetDocumentURI,
1728 nsHttpChannelInternal_GetRequestVersion,
1729 nsHttpChannelInternal_GetResponseVersion,
1730 nsHttpChannelInternal_SetCookie,
1731 nsHttpChannelInternal_SetupFallbackChannel,
1732 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1733 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1734 nsHttpChannelInternal_GetCanceled,
1735 nsHttpChannelInternal_GetChannelIsForDownload,
1736 nsHttpChannelInternal_SetChannelIsForDownload,
1737 nsHttpChannelInternal_GetLocalAddress,
1738 nsHttpChannelInternal_GetLocalPort,
1739 nsHttpChannelInternal_GetRemoteAddress,
1740 nsHttpChannelInternal_GetRemotePort,
1741 nsHttpChannelInternal_SetCacheKeysRedirectChain,
1742 nsHttpChannelInternal_HTTPUpgrade,
1743 nsHttpChannelInternal_GetAllowSpdy,
1744 nsHttpChannelInternal_SetAllowSpdy
1748 static void invalidate_uri(nsWineURI *This)
1750 if(This->uri) {
1751 IUri_Release(This->uri);
1752 This->uri = NULL;
1756 static BOOL ensure_uri_builder(nsWineURI *This)
1758 if(!This->is_mutable) {
1759 WARN("Not mutable URI\n");
1760 return FALSE;
1763 if(!This->uri_builder) {
1764 HRESULT hres;
1766 if(!ensure_uri(This))
1767 return FALSE;
1769 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1770 if(FAILED(hres)) {
1771 WARN("CreateIUriBuilder failed: %08x\n", hres);
1772 return FALSE;
1776 invalidate_uri(This);
1777 return TRUE;
1780 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1782 char *vala;
1783 BSTR val;
1784 HRESULT hres;
1786 if(!ensure_uri(This))
1787 return NS_ERROR_UNEXPECTED;
1789 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1790 if(FAILED(hres)) {
1791 WARN("GetPropertyBSTR failed: %08x\n", hres);
1792 return NS_ERROR_UNEXPECTED;
1795 vala = heap_strdupWtoU(val);
1796 SysFreeString(val);
1797 if(!vala)
1798 return NS_ERROR_OUT_OF_MEMORY;
1800 TRACE("ret %s\n", debugstr_a(vala));
1801 nsACString_SetData(ret, vala);
1802 heap_free(vala);
1803 return NS_OK;
1806 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
1808 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
1811 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
1813 nsWineURI *This = impl_from_nsIFileURL(iface);
1815 *result = NULL;
1817 if(IsEqualGUID(&IID_nsISupports, riid)) {
1818 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1819 *result = &This->nsIFileURL_iface;
1820 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1821 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1822 *result = &This->nsIFileURL_iface;
1823 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1824 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1825 *result = &This->nsIFileURL_iface;
1826 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
1827 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
1828 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
1829 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
1830 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
1831 *result = &This->nsIStandardURL_iface;
1832 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
1833 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
1834 *result = &This->nsIStandardURL_iface;
1835 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1836 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1837 *result = This;
1840 if(*result) {
1841 nsIFileURL_AddRef(&This->nsIFileURL_iface);
1842 return NS_OK;
1845 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1846 return NS_NOINTERFACE;
1849 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
1851 nsWineURI *This = impl_from_nsIFileURL(iface);
1852 LONG ref = InterlockedIncrement(&This->ref);
1854 TRACE("(%p) ref=%d\n", This, ref);
1856 return ref;
1859 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
1861 nsWineURI *This = impl_from_nsIFileURL(iface);
1862 LONG ref = InterlockedDecrement(&This->ref);
1864 TRACE("(%p) ref=%d\n", This, ref);
1866 if(!ref) {
1867 if(This->window_ref)
1868 windowref_release(This->window_ref);
1869 if(This->container)
1870 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1871 if(This->uri)
1872 IUri_Release(This->uri);
1873 heap_free(This->origin_charset);
1874 heap_free(This);
1877 return ref;
1880 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
1882 nsWineURI *This = impl_from_nsIFileURL(iface);
1884 TRACE("(%p)->(%p)\n", This, aSpec);
1886 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1889 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
1891 nsWineURI *This = impl_from_nsIFileURL(iface);
1892 const char *speca;
1893 WCHAR *spec;
1894 IUri *uri;
1895 HRESULT hres;
1897 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1899 if(!This->is_mutable)
1900 return NS_ERROR_UNEXPECTED;
1902 nsACString_GetData(aSpec, &speca);
1903 spec = heap_strdupUtoW(speca);
1904 if(!spec)
1905 return NS_ERROR_OUT_OF_MEMORY;
1907 hres = create_uri(spec, 0, &uri);
1908 heap_free(spec);
1909 if(FAILED(hres)) {
1910 WARN("create_uri failed: %08x\n", hres);
1911 return NS_ERROR_FAILURE;
1914 invalidate_uri(This);
1915 if(This->uri_builder) {
1916 IUriBuilder_Release(This->uri_builder);
1917 This->uri_builder = NULL;
1920 This->uri = uri;
1921 return NS_OK;
1924 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
1926 nsWineURI *This = impl_from_nsIFileURL(iface);
1927 FIXME("(%p)->(%p)\n", This, aPrePath);
1928 return NS_ERROR_NOT_IMPLEMENTED;
1931 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
1933 nsWineURI *This = impl_from_nsIFileURL(iface);
1934 DWORD scheme;
1935 HRESULT hres;
1937 TRACE("(%p)->(%p)\n", This, aScheme);
1939 if(!ensure_uri(This))
1940 return NS_ERROR_UNEXPECTED;
1942 hres = IUri_GetScheme(This->uri, &scheme);
1943 if(FAILED(hres)) {
1944 WARN("GetScheme failed: %08x\n", hres);
1945 return NS_ERROR_UNEXPECTED;
1948 if(scheme == URL_SCHEME_ABOUT) {
1949 nsACString_SetData(aScheme, "wine");
1950 return NS_OK;
1953 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1956 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
1958 nsWineURI *This = impl_from_nsIFileURL(iface);
1959 const char *schemea;
1960 WCHAR *scheme;
1961 HRESULT hres;
1963 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1965 if(!ensure_uri_builder(This))
1966 return NS_ERROR_UNEXPECTED;
1968 nsACString_GetData(aScheme, &schemea);
1969 scheme = heap_strdupUtoW(schemea);
1970 if(!scheme)
1971 return NS_ERROR_OUT_OF_MEMORY;
1973 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
1974 heap_free(scheme);
1975 if(FAILED(hres))
1976 return NS_ERROR_UNEXPECTED;
1978 return NS_OK;
1981 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
1983 nsWineURI *This = impl_from_nsIFileURL(iface);
1984 BSTR user, pass;
1985 HRESULT hres;
1987 TRACE("(%p)->(%p)\n", This, aUserPass);
1989 if(!ensure_uri(This))
1990 return NS_ERROR_UNEXPECTED;
1992 hres = IUri_GetUserName(This->uri, &user);
1993 if(FAILED(hres))
1994 return NS_ERROR_FAILURE;
1996 hres = IUri_GetPassword(This->uri, &pass);
1997 if(FAILED(hres)) {
1998 SysFreeString(user);
1999 return NS_ERROR_FAILURE;
2002 if(*user || *pass) {
2003 FIXME("Construct user:pass string\n");
2004 }else {
2005 nsACString_SetData(aUserPass, "");
2008 SysFreeString(user);
2009 SysFreeString(pass);
2010 return NS_OK;
2013 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
2015 nsWineURI *This = impl_from_nsIFileURL(iface);
2016 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
2017 const char *user_pass;
2018 HRESULT hres;
2020 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
2022 if(!ensure_uri_builder(This))
2023 return NS_ERROR_UNEXPECTED;
2025 nsACString_GetData(aUserPass, &user_pass);
2026 if(*user_pass) {
2027 WCHAR *ptr;
2029 buf = heap_strdupUtoW(user_pass);
2030 if(!buf)
2031 return NS_ERROR_OUT_OF_MEMORY;
2033 ptr = strchrW(buf, ':');
2034 if(!ptr) {
2035 user = buf;
2036 }else if(ptr != buf) {
2037 *ptr++ = 0;
2038 user = buf;
2039 if(*ptr)
2040 pass = ptr;
2041 }else {
2042 pass = buf+1;
2046 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2047 if(SUCCEEDED(hres))
2048 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2050 heap_free(buf);
2051 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2054 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2056 nsWineURI *This = impl_from_nsIFileURL(iface);
2058 TRACE("(%p)->(%p)\n", This, aUsername);
2060 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2063 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2065 nsWineURI *This = impl_from_nsIFileURL(iface);
2066 const char *usera;
2067 WCHAR *user;
2068 HRESULT hres;
2070 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2072 if(!ensure_uri_builder(This))
2073 return NS_ERROR_UNEXPECTED;
2075 nsACString_GetData(aUsername, &usera);
2076 user = heap_strdupUtoW(usera);
2077 if(!user)
2078 return NS_ERROR_OUT_OF_MEMORY;
2080 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2081 heap_free(user);
2082 if(FAILED(hres))
2083 return NS_ERROR_UNEXPECTED;
2085 return NS_OK;
2088 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2090 nsWineURI *This = impl_from_nsIFileURL(iface);
2092 TRACE("(%p)->(%p)\n", This, aPassword);
2094 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2097 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2099 nsWineURI *This = impl_from_nsIFileURL(iface);
2100 const char *passa;
2101 WCHAR *pass;
2102 HRESULT hres;
2104 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2106 if(!ensure_uri_builder(This))
2107 return NS_ERROR_UNEXPECTED;
2109 nsACString_GetData(aPassword, &passa);
2110 pass = heap_strdupUtoW(passa);
2111 if(!pass)
2112 return NS_ERROR_OUT_OF_MEMORY;
2114 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2115 heap_free(pass);
2116 if(FAILED(hres))
2117 return NS_ERROR_UNEXPECTED;
2119 return NS_OK;
2122 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2124 nsWineURI *This = impl_from_nsIFileURL(iface);
2125 const WCHAR *ptr;
2126 char *vala;
2127 BSTR val;
2128 HRESULT hres;
2130 TRACE("(%p)->(%p)\n", This, aHostPort);
2132 if(!ensure_uri(This))
2133 return NS_ERROR_UNEXPECTED;
2135 hres = IUri_GetAuthority(This->uri, &val);
2136 if(FAILED(hres)) {
2137 WARN("GetAuthority failed: %08x\n", hres);
2138 return NS_ERROR_UNEXPECTED;
2141 ptr = strchrW(val, '@');
2142 if(!ptr)
2143 ptr = val;
2145 vala = heap_strdupWtoU(ptr);
2146 SysFreeString(val);
2147 if(!vala)
2148 return NS_ERROR_OUT_OF_MEMORY;
2150 TRACE("ret %s\n", debugstr_a(vala));
2151 nsACString_SetData(aHostPort, vala);
2152 heap_free(vala);
2153 return NS_OK;
2156 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2158 nsWineURI *This = impl_from_nsIFileURL(iface);
2160 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2162 /* Not implemented by Gecko */
2163 return NS_ERROR_NOT_IMPLEMENTED;
2166 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2168 nsWineURI *This = impl_from_nsIFileURL(iface);
2170 TRACE("(%p)->(%p)\n", This, aHost);
2172 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2175 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2177 nsWineURI *This = impl_from_nsIFileURL(iface);
2178 const char *hosta;
2179 WCHAR *host;
2180 HRESULT hres;
2182 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2184 if(!ensure_uri_builder(This))
2185 return NS_ERROR_UNEXPECTED;
2187 nsACString_GetData(aHost, &hosta);
2188 host = heap_strdupUtoW(hosta);
2189 if(!host)
2190 return NS_ERROR_OUT_OF_MEMORY;
2192 hres = IUriBuilder_SetHost(This->uri_builder, host);
2193 heap_free(host);
2194 if(FAILED(hres))
2195 return NS_ERROR_UNEXPECTED;
2197 return NS_OK;
2200 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, LONG *aPort)
2202 nsWineURI *This = impl_from_nsIFileURL(iface);
2203 DWORD port;
2204 HRESULT hres;
2206 TRACE("(%p)->(%p)\n", This, aPort);
2208 if(!ensure_uri(This))
2209 return NS_ERROR_UNEXPECTED;
2211 hres = IUri_GetPort(This->uri, &port);
2212 if(FAILED(hres)) {
2213 WARN("GetPort failed: %08x\n", hres);
2214 return NS_ERROR_UNEXPECTED;
2217 *aPort = port ? port : -1;
2218 return NS_OK;
2221 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, LONG aPort)
2223 nsWineURI *This = impl_from_nsIFileURL(iface);
2224 HRESULT hres;
2226 TRACE("(%p)->(%d)\n", This, aPort);
2228 if(!ensure_uri_builder(This))
2229 return NS_ERROR_UNEXPECTED;
2231 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2232 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2235 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2237 nsWineURI *This = impl_from_nsIFileURL(iface);
2239 TRACE("(%p)->(%p)\n", This, aPath);
2241 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2244 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2246 nsWineURI *This = impl_from_nsIFileURL(iface);
2247 const char *patha;
2248 WCHAR *path;
2249 HRESULT hres;
2251 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2253 if(!ensure_uri_builder(This))
2254 return NS_ERROR_UNEXPECTED;
2256 nsACString_GetData(aPath, &patha);
2257 path = heap_strdupUtoW(patha);
2258 if(!path)
2259 return NS_ERROR_OUT_OF_MEMORY;
2261 hres = IUriBuilder_SetPath(This->uri_builder, path);
2262 heap_free(path);
2263 if(FAILED(hres))
2264 return NS_ERROR_UNEXPECTED;
2266 return NS_OK;
2269 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2271 nsWineURI *This = impl_from_nsIFileURL(iface);
2272 nsWineURI *other_obj;
2273 nsresult nsres;
2274 HRESULT hres;
2276 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2278 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2279 if(NS_FAILED(nsres)) {
2280 TRACE("Could not get nsWineURI interface\n");
2281 *_retval = FALSE;
2282 return NS_OK;
2285 if(ensure_uri(This) && ensure_uri(other_obj)) {
2286 BOOL b;
2288 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2289 if(SUCCEEDED(hres)) {
2290 *_retval = b;
2291 nsres = NS_OK;
2292 }else {
2293 nsres = NS_ERROR_FAILURE;
2295 }else {
2296 nsres = NS_ERROR_UNEXPECTED;
2299 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2300 return nsres;
2303 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2305 nsWineURI *This = impl_from_nsIFileURL(iface);
2306 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2307 BSTR scheme_name;
2308 HRESULT hres;
2310 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2312 if(!ensure_uri(This))
2313 return NS_ERROR_UNEXPECTED;
2315 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2316 if(FAILED(hres))
2317 return NS_ERROR_UNEXPECTED;
2319 MultiByteToWideChar(CP_UTF8, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2320 *_retval = !strcmpW(scheme_name, buf);
2321 SysFreeString(scheme_name);
2322 return NS_OK;
2325 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2327 nsWineURI *This = impl_from_nsIFileURL(iface);
2328 nsWineURI *wine_uri;
2329 nsresult nsres;
2331 TRACE("(%p)->(%p)\n", This, _retval);
2333 if(!ensure_uri(This))
2334 return NS_ERROR_UNEXPECTED;
2336 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL,
2337 This->container, This->origin_charset, &wine_uri);
2338 if(NS_FAILED(nsres)) {
2339 WARN("create_nsuri failed: %08x\n", nsres);
2340 return nsres;
2343 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2344 return NS_OK;
2347 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2348 nsACString *_retval)
2350 nsWineURI *This = impl_from_nsIFileURL(iface);
2351 const char *patha;
2352 IUri *new_uri;
2353 WCHAR *path;
2354 char *reta;
2355 BSTR ret;
2356 HRESULT hres;
2358 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2360 if(!ensure_uri(This))
2361 return NS_ERROR_UNEXPECTED;
2363 nsACString_GetData(aRelativePath, &patha);
2364 path = heap_strdupUtoW(patha);
2365 if(!path)
2366 return NS_ERROR_OUT_OF_MEMORY;
2368 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2369 heap_free(path);
2370 if(FAILED(hres)) {
2371 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2372 return NS_ERROR_FAILURE;
2375 hres = IUri_GetDisplayUri(new_uri, &ret);
2376 IUri_Release(new_uri);
2377 if(FAILED(hres))
2378 return NS_ERROR_FAILURE;
2380 reta = heap_strdupWtoU(ret);
2381 SysFreeString(ret);
2382 if(!reta)
2383 return NS_ERROR_OUT_OF_MEMORY;
2385 TRACE("returning %s\n", debugstr_a(reta));
2386 nsACString_SetData(_retval, reta);
2387 heap_free(reta);
2388 return NS_OK;
2391 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2393 nsWineURI *This = impl_from_nsIFileURL(iface);
2395 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2397 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2400 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2402 nsWineURI *This = impl_from_nsIFileURL(iface);
2404 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2406 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2409 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2411 nsWineURI *This = impl_from_nsIFileURL(iface);
2413 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2415 nsACString_SetData(aOriginCharset, This->origin_charset);
2416 return NS_OK;
2419 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2421 nsWineURI *This = impl_from_nsIFileURL(iface);
2422 char *refa = NULL;
2423 BSTR ref;
2424 HRESULT hres;
2426 TRACE("(%p)->(%p)\n", This, aRef);
2428 if(!ensure_uri(This))
2429 return NS_ERROR_UNEXPECTED;
2431 hres = IUri_GetFragment(This->uri, &ref);
2432 if(FAILED(hres))
2433 return NS_ERROR_UNEXPECTED;
2435 refa = heap_strdupWtoU(ref);
2436 SysFreeString(ref);
2437 if(ref && !refa)
2438 return NS_ERROR_OUT_OF_MEMORY;
2440 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2441 heap_free(refa);
2442 return NS_OK;
2445 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2447 nsWineURI *This = impl_from_nsIFileURL(iface);
2448 const char *refa;
2449 WCHAR *ref;
2450 HRESULT hres;
2452 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2454 if(!ensure_uri_builder(This))
2455 return NS_ERROR_UNEXPECTED;
2457 nsACString_GetData(aRef, &refa);
2458 ref = heap_strdupUtoW(refa);
2459 if(!ref)
2460 return NS_ERROR_OUT_OF_MEMORY;
2462 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2463 heap_free(ref);
2464 if(FAILED(hres))
2465 return NS_ERROR_UNEXPECTED;
2467 return NS_OK;
2470 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2472 nsWineURI *This = impl_from_nsIFileURL(iface);
2473 nsWineURI *other_obj;
2474 nsresult nsres;
2476 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2478 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2479 if(NS_FAILED(nsres)) {
2480 TRACE("Could not get nsWineURI interface\n");
2481 *_retval = FALSE;
2482 return NS_OK;
2485 if(ensure_uri(This) && ensure_uri(other_obj)) {
2486 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2487 nsres = NS_OK;
2488 }else {
2489 nsres = NS_ERROR_UNEXPECTED;
2492 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2493 return nsres;
2496 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2498 nsWineURI *This = impl_from_nsIFileURL(iface);
2499 nsWineURI *wine_uri;
2500 IUri *uri;
2501 nsresult nsres;
2503 TRACE("(%p)->(%p)\n", This, _retval);
2505 if(!ensure_uri(This))
2506 return NS_ERROR_UNEXPECTED;
2508 uri = get_uri_nofrag(This->uri);
2509 if(!uri)
2510 return NS_ERROR_FAILURE;
2512 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container,
2513 This->origin_charset, &wine_uri);
2514 IUri_Release(uri);
2515 if(NS_FAILED(nsres)) {
2516 WARN("create_nsuri failed: %08x\n", nsres);
2517 return nsres;
2520 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2521 return NS_OK;
2524 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2526 nsWineURI *This = impl_from_nsIFileURL(iface);
2528 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2530 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2533 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2535 nsWineURI *This = impl_from_nsIFileURL(iface);
2536 BOOL b;
2537 HRESULT hres;
2539 TRACE("(%p)->(%p)\n", This, aHasRef);
2541 if(!ensure_uri(This))
2542 return NS_ERROR_UNEXPECTED;
2544 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2545 if(FAILED(hres))
2546 return NS_ERROR_FAILURE;
2548 *aHasRef = b;
2549 return NS_OK;
2552 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2554 nsWineURI *This = impl_from_nsIFileURL(iface);
2556 TRACE("(%p)->(%p)\n", This, aFilePath);
2558 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2561 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2563 nsWineURI *This = impl_from_nsIFileURL(iface);
2565 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2567 if(!This->is_mutable)
2568 return NS_ERROR_UNEXPECTED;
2570 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
2573 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
2575 nsWineURI *This = impl_from_nsIFileURL(iface);
2577 TRACE("(%p)->(%p)\n", This, aQuery);
2579 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2582 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
2584 nsWineURI *This = impl_from_nsIFileURL(iface);
2585 const char *querya;
2586 WCHAR *query;
2587 HRESULT hres;
2589 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2591 if(!ensure_uri_builder(This))
2592 return NS_ERROR_UNEXPECTED;
2594 nsACString_GetData(aQuery, &querya);
2595 query = heap_strdupUtoW(querya);
2596 if(!query)
2597 return NS_ERROR_OUT_OF_MEMORY;
2599 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2600 heap_free(query);
2601 if(FAILED(hres))
2602 return NS_ERROR_UNEXPECTED;
2604 return NS_OK;
2607 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
2609 const WCHAR *ptr;
2610 HRESULT hres;
2612 if(!ensure_uri(This))
2613 return NS_ERROR_UNEXPECTED;
2615 hres = IUri_GetPath(This->uri, path);
2616 if(FAILED(hres))
2617 return NS_ERROR_FAILURE;
2619 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
2620 if(*ptr == '/' || *ptr == '\\')
2621 ptr++;
2622 *file = ptr;
2624 if(ext) {
2625 ptr = strrchrW(ptr, '.');
2626 if(!ptr)
2627 ptr = *path + SysStringLen(*path);
2628 *ext = ptr;
2631 return NS_OK;
2634 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
2636 nsWineURI *This = impl_from_nsIFileURL(iface);
2637 const WCHAR *file;
2638 BSTR path;
2639 nsresult nsres;
2641 TRACE("(%p)->(%p)\n", This, aDirectory);
2643 nsres = get_uri_path(This, &path, &file, NULL);
2644 if(NS_FAILED(nsres))
2645 return nsres;
2647 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
2648 SysFreeString(path);
2649 return nsres;
2652 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
2654 nsWineURI *This = impl_from_nsIFileURL(iface);
2656 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2658 /* Not implemented by Gecko */
2659 return NS_ERROR_NOT_IMPLEMENTED;
2662 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
2664 nsWineURI *This = impl_from_nsIFileURL(iface);
2665 const WCHAR *file;
2666 BSTR path;
2667 nsresult nsres;
2669 TRACE("(%p)->(%p)\n", This, aFileName);
2671 nsres = get_uri_path(This, &path, &file, NULL);
2672 if(NS_FAILED(nsres))
2673 return nsres;
2675 nsres = return_wstr_nsacstr(aFileName, file, -1);
2676 SysFreeString(path);
2677 return nsres;
2680 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
2682 nsWineURI *This = impl_from_nsIFileURL(iface);
2683 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2684 return NS_ERROR_NOT_IMPLEMENTED;
2687 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
2689 nsWineURI *This = impl_from_nsIFileURL(iface);
2690 const WCHAR *file, *ext;
2691 BSTR path;
2692 nsresult nsres;
2694 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2696 nsres = get_uri_path(This, &path, &file, &ext);
2697 if(NS_FAILED(nsres))
2698 return nsres;
2700 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
2701 SysFreeString(path);
2702 return nsres;
2705 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
2707 nsWineURI *This = impl_from_nsIFileURL(iface);
2708 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2709 return NS_ERROR_NOT_IMPLEMENTED;
2712 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
2714 nsWineURI *This = impl_from_nsIFileURL(iface);
2716 TRACE("(%p)->(%p)\n", This, aFileExtension);
2718 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
2721 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
2723 nsWineURI *This = impl_from_nsIFileURL(iface);
2724 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2725 return NS_ERROR_NOT_IMPLEMENTED;
2728 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2730 nsWineURI *This = impl_from_nsIFileURL(iface);
2731 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2732 return NS_ERROR_NOT_IMPLEMENTED;
2735 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2737 nsWineURI *This = impl_from_nsIFileURL(iface);
2738 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2739 return NS_ERROR_NOT_IMPLEMENTED;
2742 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
2744 nsWineURI *This = impl_from_nsIFileURL(iface);
2745 WCHAR path[MAX_PATH];
2746 DWORD size;
2747 HRESULT hres;
2749 TRACE("(%p)->(%p)\n", This, aFile);
2751 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
2752 if(FAILED(hres)) {
2753 WARN("CoInternetParseIUri failed: %08x\n", hres);
2754 return NS_ERROR_FAILURE;
2757 return create_nsfile(path, aFile);
2760 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
2762 nsWineURI *This = impl_from_nsIFileURL(iface);
2763 FIXME("(%p)->(%p)\n", This, aFile);
2764 return NS_ERROR_NOT_IMPLEMENTED;
2767 static const nsIFileURLVtbl nsFileURLVtbl = {
2768 nsURI_QueryInterface,
2769 nsURI_AddRef,
2770 nsURI_Release,
2771 nsURI_GetSpec,
2772 nsURI_SetSpec,
2773 nsURI_GetPrePath,
2774 nsURI_GetScheme,
2775 nsURI_SetScheme,
2776 nsURI_GetUserPass,
2777 nsURI_SetUserPass,
2778 nsURI_GetUsername,
2779 nsURI_SetUsername,
2780 nsURI_GetPassword,
2781 nsURI_SetPassword,
2782 nsURI_GetHostPort,
2783 nsURI_SetHostPort,
2784 nsURI_GetHost,
2785 nsURI_SetHost,
2786 nsURI_GetPort,
2787 nsURI_SetPort,
2788 nsURI_GetPath,
2789 nsURI_SetPath,
2790 nsURI_Equals,
2791 nsURI_SchemeIs,
2792 nsURI_Clone,
2793 nsURI_Resolve,
2794 nsURI_GetAsciiSpec,
2795 nsURI_GetAsciiHost,
2796 nsURI_GetOriginCharset,
2797 nsURL_GetRef,
2798 nsURL_SetRef,
2799 nsURI_EqualsExceptRef,
2800 nsURI_CloneIgnoreRef,
2801 nsURI_GetSpecIgnoringRef,
2802 nsURI_GetHasRef,
2803 nsURL_GetFilePath,
2804 nsURL_SetFilePath,
2805 nsURL_GetQuery,
2806 nsURL_SetQuery,
2807 nsURL_GetDirectory,
2808 nsURL_SetDirectory,
2809 nsURL_GetFileName,
2810 nsURL_SetFileName,
2811 nsURL_GetFileBaseName,
2812 nsURL_SetFileBaseName,
2813 nsURL_GetFileExtension,
2814 nsURL_SetFileExtension,
2815 nsURL_GetCommonBaseSpec,
2816 nsURL_GetRelativeSpec,
2817 nsFileURL_GetFile,
2818 nsFileURL_SetFile
2821 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
2823 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
2826 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
2827 void **result)
2829 nsWineURI *This = impl_from_nsIStandardURL(iface);
2830 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
2833 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
2835 nsWineURI *This = impl_from_nsIStandardURL(iface);
2836 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
2839 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
2841 nsWineURI *This = impl_from_nsIStandardURL(iface);
2842 return nsIFileURL_Release(&This->nsIFileURL_iface);
2845 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
2847 nsWineURI *This = impl_from_nsIStandardURL(iface);
2849 TRACE("(%p)->(%p)\n", This, aMutable);
2851 *aMutable = This->is_mutable;
2852 return NS_OK;
2855 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
2857 nsWineURI *This = impl_from_nsIStandardURL(iface);
2859 TRACE("(%p)->(%x)\n", This, aMutable);
2861 This->is_mutable = aMutable;
2862 return NS_OK;
2865 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, UINT32 aUrlType, LONG aDefaultPort,
2866 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
2868 nsWineURI *This = impl_from_nsIStandardURL(iface);
2869 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
2870 return NS_ERROR_NOT_IMPLEMENTED;
2873 static const nsIStandardURLVtbl nsStandardURLVtbl = {
2874 nsStandardURL_QueryInterface,
2875 nsStandardURL_AddRef,
2876 nsStandardURL_Release,
2877 nsStandardURL_GetMutable,
2878 nsStandardURL_SetMutable,
2879 nsStandardURL_Init
2882 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container,
2883 const char *origin_charset, nsWineURI **_retval)
2885 nsWineURI *ret;
2886 HRESULT hres;
2888 ret = heap_alloc_zero(sizeof(nsWineURI));
2889 if(!ret)
2890 return NS_ERROR_OUT_OF_MEMORY;
2892 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
2893 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
2894 ret->ref = 1;
2895 ret->is_mutable = TRUE;
2897 set_uri_nscontainer(ret, container);
2898 set_uri_window(ret, window);
2900 IUri_AddRef(iuri);
2901 ret->uri = iuri;
2903 hres = IUri_GetScheme(iuri, &ret->scheme);
2904 if(FAILED(hres))
2905 ret->scheme = URL_SCHEME_UNKNOWN;
2907 if(origin_charset && *origin_charset && strcmp(origin_charset, "UTF-8")) {
2908 ret->origin_charset = heap_strdupA(origin_charset);
2909 if(!ret->origin_charset) {
2910 nsIFileURL_Release(&ret->nsIFileURL_iface);
2911 return NS_ERROR_OUT_OF_MEMORY;
2915 TRACE("retval=%p\n", ret);
2916 *_retval = ret;
2917 return NS_OK;
2920 HRESULT create_doc_uri(HTMLOuterWindow *window, IUri *iuri, nsWineURI **ret)
2922 nsWineURI *uri;
2923 nsresult nsres;
2925 nsres = create_nsuri(iuri, window, window->doc_obj->nscontainer, NULL, &uri);
2926 if(NS_FAILED(nsres))
2927 return E_FAIL;
2929 uri->is_doc_uri = TRUE;
2931 *ret = uri;
2932 return S_OK;
2935 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2937 nsChannel *channel;
2939 if(!ensure_uri(uri))
2940 return NS_ERROR_UNEXPECTED;
2942 channel = heap_alloc_zero(sizeof(nsChannel));
2943 if(!channel)
2944 return NS_ERROR_OUT_OF_MEMORY;
2946 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2947 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2948 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2949 channel->ref = 1;
2950 channel->request_method = METHOD_GET;
2951 list_init(&channel->response_headers);
2952 list_init(&channel->request_headers);
2954 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
2955 channel->uri = uri;
2957 *ret = channel;
2958 return NS_OK;
2961 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
2963 HTMLOuterWindow *window = NULL;
2964 nsChannel *channel;
2965 nsWineURI *uri;
2966 IUri *iuri;
2967 nsresult nsres;
2968 HRESULT hres;
2970 hres = create_uri(url, 0, &iuri);
2971 if(FAILED(hres))
2972 return hres;
2974 if(orig_channel->uri->window_ref)
2975 window = orig_channel->uri->window_ref->window;
2976 nsres = create_nsuri(iuri, window, NULL, NULL, &uri);
2977 IUri_Release(iuri);
2978 if(NS_FAILED(nsres))
2979 return E_FAIL;
2981 nsres = create_nschannel(uri, &channel);
2982 nsIFileURL_Release(&uri->nsIFileURL_iface);
2983 if(NS_FAILED(nsres))
2984 return E_FAIL;
2986 if(orig_channel->load_group) {
2987 nsILoadGroup_AddRef(orig_channel->load_group);
2988 channel->load_group = orig_channel->load_group;
2991 if(orig_channel->notif_callback) {
2992 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
2993 channel->notif_callback = orig_channel->notif_callback;
2996 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
2998 if(orig_channel->request_method == METHOD_POST)
2999 FIXME("unsupported POST method\n");
3001 if(orig_channel->original_uri) {
3002 nsIURI_AddRef(orig_channel->original_uri);
3003 channel->original_uri = orig_channel->original_uri;
3006 if(orig_channel->referrer) {
3007 nsIURI_AddRef(orig_channel->referrer);
3008 channel->referrer = orig_channel->referrer;
3011 *ret = channel;
3012 return S_OK;
3015 typedef struct {
3016 nsIProtocolHandler nsIProtocolHandler_iface;
3018 LONG ref;
3020 nsIProtocolHandler *nshandler;
3021 } nsProtocolHandler;
3023 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
3025 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
3028 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3029 void **result)
3031 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3033 *result = NULL;
3035 if(IsEqualGUID(&IID_nsISupports, riid)) {
3036 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3037 *result = &This->nsIProtocolHandler_iface;
3038 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3039 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3040 *result = &This->nsIProtocolHandler_iface;
3041 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3042 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3043 return NS_NOINTERFACE;
3046 if(*result) {
3047 nsISupports_AddRef((nsISupports*)*result);
3048 return NS_OK;
3051 WARN("(%s %p)\n", debugstr_guid(riid), result);
3052 return NS_NOINTERFACE;
3055 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3057 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3058 LONG ref = InterlockedIncrement(&This->ref);
3060 TRACE("(%p) ref=%d\n", This, ref);
3062 return ref;
3065 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3067 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3068 LONG ref = InterlockedDecrement(&This->ref);
3070 TRACE("(%p) ref=%d\n", This, ref);
3072 if(!ref) {
3073 if(This->nshandler)
3074 nsIProtocolHandler_Release(This->nshandler);
3075 heap_free(This);
3078 return ref;
3081 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3083 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3085 TRACE("(%p)->(%p)\n", This, aScheme);
3087 if(This->nshandler)
3088 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3089 return NS_ERROR_NOT_IMPLEMENTED;
3092 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3093 LONG *aDefaultPort)
3095 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3097 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3099 if(This->nshandler)
3100 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3101 return NS_ERROR_NOT_IMPLEMENTED;
3104 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3105 UINT32 *aProtocolFlags)
3107 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3109 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3111 if(This->nshandler)
3112 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3113 return NS_ERROR_NOT_IMPLEMENTED;
3116 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3117 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3119 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3121 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3122 aBaseURI, _retval);
3124 if(This->nshandler)
3125 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3126 return NS_ERROR_NOT_IMPLEMENTED;
3129 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3130 nsIURI *aURI, nsIChannel **_retval)
3132 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3134 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3136 if(This->nshandler)
3137 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3138 return NS_ERROR_NOT_IMPLEMENTED;
3141 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3142 LONG port, const char *scheme, cpp_bool *_retval)
3144 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3146 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3148 if(This->nshandler)
3149 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3150 return NS_ERROR_NOT_IMPLEMENTED;
3153 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3154 nsProtocolHandler_QueryInterface,
3155 nsProtocolHandler_AddRef,
3156 nsProtocolHandler_Release,
3157 nsProtocolHandler_GetScheme,
3158 nsProtocolHandler_GetDefaultPort,
3159 nsProtocolHandler_GetProtocolFlags,
3160 nsProtocolHandler_NewURI,
3161 nsProtocolHandler_NewChannel,
3162 nsProtocolHandler_AllowPort
3165 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
3167 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
3169 return 2;
3172 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
3174 return 1;
3177 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
3178 nsIProtocolHandler **_retval)
3180 nsIExternalProtocolHandler *nsexthandler;
3181 nsIProtocolHandler *nshandler;
3182 nsProtocolHandler *ret;
3183 nsresult nsres;
3185 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3187 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
3188 if(NS_FAILED(nsres)) {
3189 WARN("GetProtocolHandler failed: %08x\n", nsres);
3190 return nsres;
3193 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
3194 (void**)&nsexthandler);
3195 if(NS_FAILED(nsres)) {
3196 *_retval = nshandler;
3197 return NS_OK;
3200 nsIExternalProtocolHandler_Release(nsexthandler);
3202 ret = heap_alloc(sizeof(nsProtocolHandler));
3203 if(!ret)
3204 return NS_ERROR_OUT_OF_MEMORY;
3206 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3207 ret->ref = 1;
3208 ret->nshandler = nshandler;
3209 *_retval = &ret->nsIProtocolHandler_iface;
3211 TRACE("return %p\n", *_retval);
3212 return NS_OK;
3215 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
3216 UINT32 *_retval)
3218 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3219 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
3222 static BOOL is_gecko_special_uri(const char *spec)
3224 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3225 unsigned int i;
3227 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3228 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3229 return TRUE;
3232 if(!strncasecmp(spec, "file:", 5)) {
3233 const char *ptr = spec+5;
3234 while(*ptr == '/')
3235 ptr++;
3236 return is_gecko_path(ptr);
3239 return FALSE;
3242 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
3243 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3245 nsWineURI *wine_uri, *base_wine_uri = NULL;
3246 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3247 HTMLOuterWindow *window = NULL;
3248 const char *spec = NULL;
3249 IUri *urlmon_uri;
3250 nsresult nsres;
3251 HRESULT hres;
3253 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3254 aBaseURI, _retval);
3256 nsACString_GetData(aSpec, &spec);
3257 if(is_gecko_special_uri(spec))
3258 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3260 if(!strncmp(spec, "wine:", 5))
3261 spec += 5;
3263 if(aBaseURI) {
3264 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3265 if(NS_SUCCEEDED(nsres)) {
3266 if(!ensure_uri(base_wine_uri))
3267 return NS_ERROR_UNEXPECTED;
3268 if(base_wine_uri->window_ref)
3269 window = base_wine_uri->window_ref->window;
3270 }else {
3271 WARN("Could not get base nsWineURI: %08x\n", nsres);
3275 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3277 if(base_wine_uri) {
3278 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
3279 &urlmon_uri, 0);
3280 if(FAILED(hres))
3281 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
3282 }else {
3283 hres = create_uri(new_spec, 0, &urlmon_uri);
3284 if(FAILED(hres))
3285 WARN("create_uri failed: %08x\n", hres);
3288 if(FAILED(hres))
3289 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3291 nsres = create_nsuri(urlmon_uri, window, NULL, NULL, &wine_uri);
3292 IUri_Release(urlmon_uri);
3293 if(base_wine_uri)
3294 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3295 if(NS_FAILED(nsres))
3296 return nsres;
3298 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3299 return nsres;
3302 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
3303 nsIURI **_retval)
3305 TRACE("(%p %p)\n", aFile, _retval);
3306 return nsIIOService_NewFileURI(nsio, aFile, _retval);
3309 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
3310 nsIChannel **_retval)
3312 nsWineURI *wine_uri;
3313 nsChannel *ret;
3314 nsresult nsres;
3316 TRACE("(%p %p)\n", aURI, _retval);
3318 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3319 if(NS_FAILED(nsres)) {
3320 TRACE("Could not get nsWineURI: %08x\n", nsres);
3321 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
3324 nsres = create_nschannel(wine_uri, &ret);
3325 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3326 if(NS_FAILED(nsres))
3327 return nsres;
3329 nsIURI_AddRef(aURI);
3330 ret->original_uri = aURI;
3332 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3333 return NS_OK;
3336 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
3337 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
3339 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
3340 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3343 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, cpp_bool *aOffline)
3345 TRACE("(%p)\n", aOffline);
3346 return nsIIOService_GetOffline(nsio, aOffline);
3349 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, cpp_bool aOffline)
3351 TRACE("(%x)\n", aOffline);
3352 return nsIIOService_SetOffline(nsio, aOffline);
3355 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, LONG aPort,
3356 const char *aScheme, cpp_bool *_retval)
3358 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
3359 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
3362 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
3363 nsACString * _retval)
3365 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
3366 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
3369 static const nsIIOServiceVtbl nsIOServiceVtbl = {
3370 nsIOService_QueryInterface,
3371 nsIOService_AddRef,
3372 nsIOService_Release,
3373 nsIOService_GetProtocolHandler,
3374 nsIOService_GetProtocolFlags,
3375 nsIOService_NewURI,
3376 nsIOService_NewFileURI,
3377 nsIOService_NewChannelFromURI,
3378 nsIOService_NewChannel,
3379 nsIOService_GetOffline,
3380 nsIOService_SetOffline,
3381 nsIOService_AllowPort,
3382 nsIOService_ExtractScheme
3385 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3387 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3388 void **result)
3390 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3393 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3395 return 2;
3398 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3400 return 1;
3403 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3404 nsACString *aCharset, cpp_bool *aHadCharset, nsACString *aContentType)
3406 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3408 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3411 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3413 TRACE("()\n");
3415 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3418 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3420 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3422 if(aFlags == (1<<11)) {
3423 *_retval = FALSE;
3424 return NS_OK;
3427 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3430 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3432 TRACE("(%p %p)\n", aURI, _retval);
3434 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3437 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3439 TRACE("(%p %p)\n", aURI, _retval);
3441 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3444 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3445 UINT32 aEscapeType, nsACString *_retval)
3447 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3449 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3452 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, UINT32 aFlags,
3453 nsACString *_retval)
3455 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3457 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3460 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3461 UINT32 aFlags, nsACString *_retval)
3463 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3465 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3468 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3469 nsACString *aCharset, LONG *aCharsetStart, LONG *aCharsetEnd, cpp_bool *_retval)
3471 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3472 aCharsetEnd, _retval);
3474 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3477 static const nsINetUtilVtbl nsNetUtilVtbl = {
3478 nsNetUtil_QueryInterface,
3479 nsNetUtil_AddRef,
3480 nsNetUtil_Release,
3481 nsNetUtil_ParseContentType,
3482 nsNetUtil_ProtocolHasFlags,
3483 nsNetUtil_URIChainHasFlags,
3484 nsNetUtil_ToImmutableURI,
3485 nsNetUtil_NewSimpleNestedURI,
3486 nsNetUtil_EscapeString,
3487 nsNetUtil_EscapeURL,
3488 nsNetUtil_UnescapeString,
3489 nsNetUtil_ExtractCharsetFromContentType
3492 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3494 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3495 void **result)
3497 *result = NULL;
3499 if(IsEqualGUID(&IID_nsISupports, riid))
3500 *result = &nsIOService;
3501 else if(IsEqualGUID(&IID_nsIIOService, riid))
3502 *result = &nsIOService;
3503 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3504 *result = &nsNetUtil;
3506 if(*result) {
3507 nsISupports_AddRef((nsISupports*)*result);
3508 return NS_OK;
3511 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3512 return NS_NOINTERFACE;
3515 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3516 void **result)
3518 *result = NULL;
3520 if(IsEqualGUID(&IID_nsISupports, riid)) {
3521 TRACE("(IID_nsISupports %p)\n", result);
3522 *result = iface;
3523 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3524 TRACE("(IID_nsIFactory %p)\n", result);
3525 *result = iface;
3528 if(*result) {
3529 nsIFactory_AddRef(iface);
3530 return NS_OK;
3533 WARN("(%s %p)\n", debugstr_guid(riid), result);
3534 return NS_NOINTERFACE;
3537 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3539 return 2;
3542 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3544 return 1;
3547 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3548 nsISupports *aOuter, const nsIID *iid, void **result)
3550 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3553 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
3555 WARN("(%x)\n", lock);
3556 return NS_OK;
3559 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3560 nsIOServiceFactory_QueryInterface,
3561 nsIOServiceFactory_AddRef,
3562 nsIOServiceFactory_Release,
3563 nsIOServiceFactory_CreateInstance,
3564 nsIOServiceFactory_LockFactory
3567 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3569 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3571 OLECHAR *new_url = NULL;
3572 WCHAR *url;
3573 BOOL ret = FALSE;
3574 HRESULT hres;
3576 if(!doc->hostui || !ensure_uri(uri))
3577 return FALSE;
3579 hres = IUri_GetDisplayUri(uri->uri, &url);
3580 if(FAILED(hres))
3581 return FALSE;
3583 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3584 if(hres == S_OK && new_url) {
3585 if(strcmpW(url, new_url)) {
3586 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3587 ret = TRUE;
3589 CoTaskMemFree(new_url);
3592 SysFreeString(url);
3593 return ret;
3596 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
3598 nsWineURI *wine_uri;
3599 nsresult nsres;
3601 *_retval = FALSE;
3603 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3604 if(NS_FAILED(nsres)) {
3605 WARN("Could not get nsWineURI: %08x\n", nsres);
3606 return NS_ERROR_NOT_IMPLEMENTED;
3609 if(!wine_uri->is_doc_uri) {
3610 wine_uri->is_doc_uri = TRUE;
3612 if(!wine_uri->container) {
3613 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3614 wine_uri->container = nscontainer;
3617 if(nscontainer->doc)
3618 *_retval = translate_url(nscontainer->doc, wine_uri);
3621 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3622 return NS_OK;
3625 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3627 nsIFactory *old_factory = NULL;
3628 nsresult nsres;
3630 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3631 &IID_nsIFactory, (void**)&old_factory);
3632 if(NS_FAILED(nsres)) {
3633 ERR("Could not get factory: %08x\n", nsres);
3634 return;
3637 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3638 if(NS_FAILED(nsres)) {
3639 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3640 nsIFactory_Release(old_factory);
3641 return;
3644 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3645 if(NS_FAILED(nsres)) {
3646 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3647 nsIIOService_Release(nsio);
3648 return;
3651 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3652 nsIFactory_Release(old_factory);
3653 if(NS_FAILED(nsres))
3654 ERR("UnregisterFactory failed: %08x\n", nsres);
3656 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3657 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3658 if(NS_FAILED(nsres))
3659 ERR("RegisterFactory failed: %08x\n", nsres);
3662 void release_nsio(void)
3664 if(net_util) {
3665 nsINetUtil_Release(net_util);
3666 net_util = NULL;
3669 if(nsio) {
3670 nsIIOService_Release(nsio);
3671 nsio = NULL;