winemac: Activate an app if it sets focus on a window shortly after a hot key is...
[wine.git] / dlls / mshtml / nsio.c
blobda7d93068c8ae6fc4c1876d90460a5bce3a876a3
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, INT64 *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, INT64 aContentLength)
848 nsChannel *This = impl_from_nsIHttpChannel(iface);
850 FIXME("(%p)->(%s)\n", This, wine_dbgstr_longlong(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 nsresult NSAPI nsChannel_RedirectTo(nsIHttpChannel *iface, nsIURI *aNewURI)
1387 nsChannel *This = impl_from_nsIHttpChannel(iface);
1389 FIXME("(%p)->(%p)\n", This, aNewURI);
1391 return NS_ERROR_NOT_IMPLEMENTED;
1394 static const nsIHttpChannelVtbl nsChannelVtbl = {
1395 nsChannel_QueryInterface,
1396 nsChannel_AddRef,
1397 nsChannel_Release,
1398 nsChannel_GetName,
1399 nsChannel_IsPending,
1400 nsChannel_GetStatus,
1401 nsChannel_Cancel,
1402 nsChannel_Suspend,
1403 nsChannel_Resume,
1404 nsChannel_GetLoadGroup,
1405 nsChannel_SetLoadGroup,
1406 nsChannel_GetLoadFlags,
1407 nsChannel_SetLoadFlags,
1408 nsChannel_GetOriginalURI,
1409 nsChannel_SetOriginalURI,
1410 nsChannel_GetURI,
1411 nsChannel_GetOwner,
1412 nsChannel_SetOwner,
1413 nsChannel_GetNotificationCallbacks,
1414 nsChannel_SetNotificationCallbacks,
1415 nsChannel_GetSecurityInfo,
1416 nsChannel_GetContentType,
1417 nsChannel_SetContentType,
1418 nsChannel_GetContentCharset,
1419 nsChannel_SetContentCharset,
1420 nsChannel_GetContentLength,
1421 nsChannel_SetContentLength,
1422 nsChannel_Open,
1423 nsChannel_AsyncOpen,
1424 nsChannel_GetContentDisposition,
1425 nsChannel_SetContentDisposition,
1426 nsChannel_GetContentDispositionFilename,
1427 nsChannel_SetContentDispositionFilename,
1428 nsChannel_GetContentDispositionHeader,
1429 nsChannel_GetRequestMethod,
1430 nsChannel_SetRequestMethod,
1431 nsChannel_GetReferrer,
1432 nsChannel_SetReferrer,
1433 nsChannel_GetRequestHeader,
1434 nsChannel_SetRequestHeader,
1435 nsChannel_VisitRequestHeaders,
1436 nsChannel_GetAllowPipelining,
1437 nsChannel_SetAllowPipelining,
1438 nsChannel_GetRedirectionLimit,
1439 nsChannel_SetRedirectionLimit,
1440 nsChannel_GetResponseStatus,
1441 nsChannel_GetResponseStatusText,
1442 nsChannel_GetRequestSucceeded,
1443 nsChannel_GetResponseHeader,
1444 nsChannel_SetResponseHeader,
1445 nsChannel_VisitResponseHeaders,
1446 nsChannel_IsNoStoreResponse,
1447 nsChannel_IsNoCacheResponse,
1448 nsChannel_RedirectTo
1451 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1453 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1456 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1457 void **result)
1459 nsChannel *This = impl_from_nsIUploadChannel(iface);
1460 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1463 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1465 nsChannel *This = impl_from_nsIUploadChannel(iface);
1466 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1469 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1471 nsChannel *This = impl_from_nsIUploadChannel(iface);
1472 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1475 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1476 nsIInputStream *aStream, const nsACString *aContentType, INT64 aContentLength)
1478 nsChannel *This = impl_from_nsIUploadChannel(iface);
1479 const char *content_type;
1481 static const WCHAR content_typeW[] =
1482 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1484 TRACE("(%p)->(%p %s %s)\n", This, aStream, debugstr_nsacstr(aContentType), wine_dbgstr_longlong(aContentLength));
1486 This->post_data_contains_headers = TRUE;
1488 if(aContentType) {
1489 nsACString_GetData(aContentType, &content_type);
1490 if(*content_type) {
1491 WCHAR *ct;
1493 ct = heap_strdupAtoW(content_type);
1494 if(!ct)
1495 return NS_ERROR_UNEXPECTED;
1497 set_http_header(&This->request_headers, content_typeW,
1498 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1499 heap_free(ct);
1500 This->post_data_contains_headers = FALSE;
1504 if(This->post_data_stream)
1505 nsIInputStream_Release(This->post_data_stream);
1507 if(aContentLength != -1)
1508 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength));
1510 if(This->post_data_stream)
1511 nsIInputStream_Release(This->post_data_stream);
1512 This->post_data_stream = aStream;
1513 if(aStream)
1514 nsIInputStream_AddRef(aStream);
1516 This->request_method = METHOD_POST;
1517 return NS_OK;
1520 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1521 nsIInputStream **aUploadStream)
1523 nsChannel *This = impl_from_nsIUploadChannel(iface);
1525 TRACE("(%p)->(%p)\n", This, aUploadStream);
1527 if(This->post_data_stream)
1528 nsIInputStream_AddRef(This->post_data_stream);
1530 *aUploadStream = This->post_data_stream;
1531 return NS_OK;
1534 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1535 nsUploadChannel_QueryInterface,
1536 nsUploadChannel_AddRef,
1537 nsUploadChannel_Release,
1538 nsUploadChannel_SetUploadStream,
1539 nsUploadChannel_GetUploadStream
1542 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1544 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1547 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1548 void **result)
1550 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1551 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1554 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1556 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1557 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1560 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1562 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1563 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1566 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1568 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1570 FIXME("(%p)->()\n", This);
1572 return NS_ERROR_NOT_IMPLEMENTED;
1575 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1577 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1579 FIXME("(%p)->()\n", This);
1581 return NS_ERROR_NOT_IMPLEMENTED;
1584 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1586 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1588 FIXME("(%p)->()\n", This);
1590 return NS_ERROR_NOT_IMPLEMENTED;
1593 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1595 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1597 FIXME("(%p)->()\n", This);
1599 return NS_ERROR_NOT_IMPLEMENTED;
1602 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1604 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1606 FIXME("(%p)->()\n", This);
1608 return NS_ERROR_NOT_IMPLEMENTED;
1611 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1613 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1615 FIXME("(%p)->()\n", This);
1617 return NS_ERROR_NOT_IMPLEMENTED;
1620 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1622 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1624 FIXME("(%p)->()\n", This);
1626 return NS_ERROR_NOT_IMPLEMENTED;
1629 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1631 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1633 FIXME("(%p)->()\n", This);
1635 return NS_ERROR_NOT_IMPLEMENTED;
1638 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1640 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1642 FIXME("(%p)->(%p)\n", This, aCanceled);
1644 return NS_ERROR_NOT_IMPLEMENTED;
1647 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1649 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1651 FIXME("(%p)->(%p)\n", This, aCanceled);
1653 return NS_ERROR_NOT_IMPLEMENTED;
1656 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1658 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1660 FIXME("(%p)->(%x)\n", This, aCanceled);
1662 return NS_ERROR_NOT_IMPLEMENTED;
1665 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1667 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1669 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1671 return NS_ERROR_NOT_IMPLEMENTED;
1674 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, LONG *aLocalPort)
1676 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1678 FIXME("(%p)->(%p)\n", This, aLocalPort);
1680 return NS_ERROR_NOT_IMPLEMENTED;
1683 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1685 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1687 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1689 return NS_ERROR_NOT_IMPLEMENTED;
1692 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, LONG *aRemotePort)
1694 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1696 FIXME("(%p)->(%p)\n", This, aRemotePort);
1698 return NS_ERROR_NOT_IMPLEMENTED;
1701 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1703 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1705 FIXME("(%p)->(%p)\n", This, cacheKeys);
1707 return NS_ERROR_NOT_IMPLEMENTED;
1710 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1711 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1713 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1714 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1715 return NS_ERROR_NOT_IMPLEMENTED;
1718 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1720 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1721 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1722 return NS_ERROR_NOT_IMPLEMENTED;
1725 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1727 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1728 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1729 return NS_ERROR_NOT_IMPLEMENTED;
1732 static nsresult NSAPI nsHttpChannelInternal_GetLoadAsBlocking(nsIHttpChannelInternal *iface, cpp_bool *aLoadAsBlocking)
1734 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1735 FIXME("(%p)->(%p)\n", This, aLoadAsBlocking);
1736 return NS_ERROR_NOT_IMPLEMENTED;
1739 static nsresult NSAPI nsHttpChannelInternal_SetLoadAsBlocking(nsIHttpChannelInternal *iface, cpp_bool aLoadAsBlocking)
1741 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1742 FIXME("(%p)->(%x)\n", This, aLoadAsBlocking);
1743 return NS_ERROR_NOT_IMPLEMENTED;
1746 static nsresult NSAPI nsHttpChannelInternal_GetLoadUnblocked(nsIHttpChannelInternal *iface, cpp_bool *aLoadUnblocked)
1748 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1749 FIXME("(%p)->(%p)\n", This, aLoadUnblocked);
1750 return NS_ERROR_NOT_IMPLEMENTED;
1753 static nsresult NSAPI nsHttpChannelInternal_SetLoadUnblocked(nsIHttpChannelInternal *iface, cpp_bool aLoadUnblocked)
1755 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1756 FIXME("(%p)->(%x)\n", This, aLoadUnblocked);
1757 return NS_ERROR_NOT_IMPLEMENTED;
1760 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1761 nsHttpChannelInternal_QueryInterface,
1762 nsHttpChannelInternal_AddRef,
1763 nsHttpChannelInternal_Release,
1764 nsHttpChannelInternal_GetDocumentURI,
1765 nsHttpChannelInternal_SetDocumentURI,
1766 nsHttpChannelInternal_GetRequestVersion,
1767 nsHttpChannelInternal_GetResponseVersion,
1768 nsHttpChannelInternal_SetCookie,
1769 nsHttpChannelInternal_SetupFallbackChannel,
1770 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1771 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1772 nsHttpChannelInternal_GetCanceled,
1773 nsHttpChannelInternal_GetChannelIsForDownload,
1774 nsHttpChannelInternal_SetChannelIsForDownload,
1775 nsHttpChannelInternal_GetLocalAddress,
1776 nsHttpChannelInternal_GetLocalPort,
1777 nsHttpChannelInternal_GetRemoteAddress,
1778 nsHttpChannelInternal_GetRemotePort,
1779 nsHttpChannelInternal_SetCacheKeysRedirectChain,
1780 nsHttpChannelInternal_HTTPUpgrade,
1781 nsHttpChannelInternal_GetAllowSpdy,
1782 nsHttpChannelInternal_SetAllowSpdy,
1783 nsHttpChannelInternal_GetLoadAsBlocking,
1784 nsHttpChannelInternal_SetLoadAsBlocking,
1785 nsHttpChannelInternal_GetLoadUnblocked,
1786 nsHttpChannelInternal_SetLoadUnblocked
1790 static void invalidate_uri(nsWineURI *This)
1792 if(This->uri) {
1793 IUri_Release(This->uri);
1794 This->uri = NULL;
1798 static BOOL ensure_uri_builder(nsWineURI *This)
1800 if(!This->is_mutable) {
1801 WARN("Not mutable URI\n");
1802 return FALSE;
1805 if(!This->uri_builder) {
1806 HRESULT hres;
1808 if(!ensure_uri(This))
1809 return FALSE;
1811 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
1812 if(FAILED(hres)) {
1813 WARN("CreateIUriBuilder failed: %08x\n", hres);
1814 return FALSE;
1818 invalidate_uri(This);
1819 return TRUE;
1822 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
1824 char *vala;
1825 BSTR val;
1826 HRESULT hres;
1828 if(!ensure_uri(This))
1829 return NS_ERROR_UNEXPECTED;
1831 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
1832 if(FAILED(hres)) {
1833 WARN("GetPropertyBSTR failed: %08x\n", hres);
1834 return NS_ERROR_UNEXPECTED;
1837 vala = heap_strdupWtoU(val);
1838 SysFreeString(val);
1839 if(!vala)
1840 return NS_ERROR_OUT_OF_MEMORY;
1842 TRACE("ret %s\n", debugstr_a(vala));
1843 nsACString_SetData(ret, vala);
1844 heap_free(vala);
1845 return NS_OK;
1848 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
1850 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
1853 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
1855 nsWineURI *This = impl_from_nsIFileURL(iface);
1857 *result = NULL;
1859 if(IsEqualGUID(&IID_nsISupports, riid)) {
1860 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1861 *result = &This->nsIFileURL_iface;
1862 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1863 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1864 *result = &This->nsIFileURL_iface;
1865 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1866 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1867 *result = &This->nsIFileURL_iface;
1868 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
1869 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
1870 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
1871 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
1872 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
1873 *result = &This->nsIStandardURL_iface;
1874 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
1875 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
1876 *result = &This->nsIStandardURL_iface;
1877 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1878 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1879 *result = This;
1882 if(*result) {
1883 nsIFileURL_AddRef(&This->nsIFileURL_iface);
1884 return NS_OK;
1887 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1888 return NS_NOINTERFACE;
1891 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
1893 nsWineURI *This = impl_from_nsIFileURL(iface);
1894 LONG ref = InterlockedIncrement(&This->ref);
1896 TRACE("(%p) ref=%d\n", This, ref);
1898 return ref;
1901 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
1903 nsWineURI *This = impl_from_nsIFileURL(iface);
1904 LONG ref = InterlockedDecrement(&This->ref);
1906 TRACE("(%p) ref=%d\n", This, ref);
1908 if(!ref) {
1909 if(This->window_ref)
1910 windowref_release(This->window_ref);
1911 if(This->container)
1912 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
1913 if(This->uri)
1914 IUri_Release(This->uri);
1915 heap_free(This->origin_charset);
1916 heap_free(This);
1919 return ref;
1922 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
1924 nsWineURI *This = impl_from_nsIFileURL(iface);
1926 TRACE("(%p)->(%p)\n", This, aSpec);
1928 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
1931 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
1933 nsWineURI *This = impl_from_nsIFileURL(iface);
1934 const char *speca;
1935 WCHAR *spec;
1936 IUri *uri;
1937 HRESULT hres;
1939 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
1941 if(!This->is_mutable)
1942 return NS_ERROR_UNEXPECTED;
1944 nsACString_GetData(aSpec, &speca);
1945 spec = heap_strdupUtoW(speca);
1946 if(!spec)
1947 return NS_ERROR_OUT_OF_MEMORY;
1949 hres = create_uri(spec, 0, &uri);
1950 heap_free(spec);
1951 if(FAILED(hres)) {
1952 WARN("create_uri failed: %08x\n", hres);
1953 return NS_ERROR_FAILURE;
1956 invalidate_uri(This);
1957 if(This->uri_builder) {
1958 IUriBuilder_Release(This->uri_builder);
1959 This->uri_builder = NULL;
1962 This->uri = uri;
1963 return NS_OK;
1966 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
1968 nsWineURI *This = impl_from_nsIFileURL(iface);
1969 FIXME("(%p)->(%p)\n", This, aPrePath);
1970 return NS_ERROR_NOT_IMPLEMENTED;
1973 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
1975 nsWineURI *This = impl_from_nsIFileURL(iface);
1976 DWORD scheme;
1977 HRESULT hres;
1979 TRACE("(%p)->(%p)\n", This, aScheme);
1981 if(!ensure_uri(This))
1982 return NS_ERROR_UNEXPECTED;
1984 hres = IUri_GetScheme(This->uri, &scheme);
1985 if(FAILED(hres)) {
1986 WARN("GetScheme failed: %08x\n", hres);
1987 return NS_ERROR_UNEXPECTED;
1990 if(scheme == URL_SCHEME_ABOUT) {
1991 nsACString_SetData(aScheme, "wine");
1992 return NS_OK;
1995 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
1998 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
2000 nsWineURI *This = impl_from_nsIFileURL(iface);
2001 const char *schemea;
2002 WCHAR *scheme;
2003 HRESULT hres;
2005 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
2007 if(!ensure_uri_builder(This))
2008 return NS_ERROR_UNEXPECTED;
2010 nsACString_GetData(aScheme, &schemea);
2011 scheme = heap_strdupUtoW(schemea);
2012 if(!scheme)
2013 return NS_ERROR_OUT_OF_MEMORY;
2015 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
2016 heap_free(scheme);
2017 if(FAILED(hres))
2018 return NS_ERROR_UNEXPECTED;
2020 return NS_OK;
2023 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
2025 nsWineURI *This = impl_from_nsIFileURL(iface);
2026 BSTR user, pass;
2027 HRESULT hres;
2029 TRACE("(%p)->(%p)\n", This, aUserPass);
2031 if(!ensure_uri(This))
2032 return NS_ERROR_UNEXPECTED;
2034 hres = IUri_GetUserName(This->uri, &user);
2035 if(FAILED(hres))
2036 return NS_ERROR_FAILURE;
2038 hres = IUri_GetPassword(This->uri, &pass);
2039 if(FAILED(hres)) {
2040 SysFreeString(user);
2041 return NS_ERROR_FAILURE;
2044 if(*user || *pass) {
2045 FIXME("Construct user:pass string\n");
2046 }else {
2047 nsACString_SetData(aUserPass, "");
2050 SysFreeString(user);
2051 SysFreeString(pass);
2052 return NS_OK;
2055 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
2057 nsWineURI *This = impl_from_nsIFileURL(iface);
2058 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
2059 const char *user_pass;
2060 HRESULT hres;
2062 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
2064 if(!ensure_uri_builder(This))
2065 return NS_ERROR_UNEXPECTED;
2067 nsACString_GetData(aUserPass, &user_pass);
2068 if(*user_pass) {
2069 WCHAR *ptr;
2071 buf = heap_strdupUtoW(user_pass);
2072 if(!buf)
2073 return NS_ERROR_OUT_OF_MEMORY;
2075 ptr = strchrW(buf, ':');
2076 if(!ptr) {
2077 user = buf;
2078 }else if(ptr != buf) {
2079 *ptr++ = 0;
2080 user = buf;
2081 if(*ptr)
2082 pass = ptr;
2083 }else {
2084 pass = buf+1;
2088 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2089 if(SUCCEEDED(hres))
2090 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2092 heap_free(buf);
2093 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2096 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2098 nsWineURI *This = impl_from_nsIFileURL(iface);
2100 TRACE("(%p)->(%p)\n", This, aUsername);
2102 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2105 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2107 nsWineURI *This = impl_from_nsIFileURL(iface);
2108 const char *usera;
2109 WCHAR *user;
2110 HRESULT hres;
2112 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2114 if(!ensure_uri_builder(This))
2115 return NS_ERROR_UNEXPECTED;
2117 nsACString_GetData(aUsername, &usera);
2118 user = heap_strdupUtoW(usera);
2119 if(!user)
2120 return NS_ERROR_OUT_OF_MEMORY;
2122 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2123 heap_free(user);
2124 if(FAILED(hres))
2125 return NS_ERROR_UNEXPECTED;
2127 return NS_OK;
2130 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2132 nsWineURI *This = impl_from_nsIFileURL(iface);
2134 TRACE("(%p)->(%p)\n", This, aPassword);
2136 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2139 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2141 nsWineURI *This = impl_from_nsIFileURL(iface);
2142 const char *passa;
2143 WCHAR *pass;
2144 HRESULT hres;
2146 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2148 if(!ensure_uri_builder(This))
2149 return NS_ERROR_UNEXPECTED;
2151 nsACString_GetData(aPassword, &passa);
2152 pass = heap_strdupUtoW(passa);
2153 if(!pass)
2154 return NS_ERROR_OUT_OF_MEMORY;
2156 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2157 heap_free(pass);
2158 if(FAILED(hres))
2159 return NS_ERROR_UNEXPECTED;
2161 return NS_OK;
2164 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2166 nsWineURI *This = impl_from_nsIFileURL(iface);
2167 const WCHAR *ptr;
2168 char *vala;
2169 BSTR val;
2170 HRESULT hres;
2172 TRACE("(%p)->(%p)\n", This, aHostPort);
2174 if(!ensure_uri(This))
2175 return NS_ERROR_UNEXPECTED;
2177 hres = IUri_GetAuthority(This->uri, &val);
2178 if(FAILED(hres)) {
2179 WARN("GetAuthority failed: %08x\n", hres);
2180 return NS_ERROR_UNEXPECTED;
2183 ptr = strchrW(val, '@');
2184 if(!ptr)
2185 ptr = val;
2187 vala = heap_strdupWtoU(ptr);
2188 SysFreeString(val);
2189 if(!vala)
2190 return NS_ERROR_OUT_OF_MEMORY;
2192 TRACE("ret %s\n", debugstr_a(vala));
2193 nsACString_SetData(aHostPort, vala);
2194 heap_free(vala);
2195 return NS_OK;
2198 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2200 nsWineURI *This = impl_from_nsIFileURL(iface);
2202 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2204 /* Not implemented by Gecko */
2205 return NS_ERROR_NOT_IMPLEMENTED;
2208 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2210 nsWineURI *This = impl_from_nsIFileURL(iface);
2212 TRACE("(%p)->(%p)\n", This, aHost);
2214 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2217 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2219 nsWineURI *This = impl_from_nsIFileURL(iface);
2220 const char *hosta;
2221 WCHAR *host;
2222 HRESULT hres;
2224 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2226 if(!ensure_uri_builder(This))
2227 return NS_ERROR_UNEXPECTED;
2229 nsACString_GetData(aHost, &hosta);
2230 host = heap_strdupUtoW(hosta);
2231 if(!host)
2232 return NS_ERROR_OUT_OF_MEMORY;
2234 hres = IUriBuilder_SetHost(This->uri_builder, host);
2235 heap_free(host);
2236 if(FAILED(hres))
2237 return NS_ERROR_UNEXPECTED;
2239 return NS_OK;
2242 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, LONG *aPort)
2244 nsWineURI *This = impl_from_nsIFileURL(iface);
2245 DWORD port;
2246 HRESULT hres;
2248 TRACE("(%p)->(%p)\n", This, aPort);
2250 if(!ensure_uri(This))
2251 return NS_ERROR_UNEXPECTED;
2253 hres = IUri_GetPort(This->uri, &port);
2254 if(FAILED(hres)) {
2255 WARN("GetPort failed: %08x\n", hres);
2256 return NS_ERROR_UNEXPECTED;
2259 *aPort = port ? port : -1;
2260 return NS_OK;
2263 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, LONG aPort)
2265 nsWineURI *This = impl_from_nsIFileURL(iface);
2266 HRESULT hres;
2268 TRACE("(%p)->(%d)\n", This, aPort);
2270 if(!ensure_uri_builder(This))
2271 return NS_ERROR_UNEXPECTED;
2273 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2274 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2277 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2279 nsWineURI *This = impl_from_nsIFileURL(iface);
2281 TRACE("(%p)->(%p)\n", This, aPath);
2283 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2286 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2288 nsWineURI *This = impl_from_nsIFileURL(iface);
2289 const char *patha;
2290 WCHAR *path;
2291 HRESULT hres;
2293 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2295 if(!ensure_uri_builder(This))
2296 return NS_ERROR_UNEXPECTED;
2298 nsACString_GetData(aPath, &patha);
2299 path = heap_strdupUtoW(patha);
2300 if(!path)
2301 return NS_ERROR_OUT_OF_MEMORY;
2303 hres = IUriBuilder_SetPath(This->uri_builder, path);
2304 heap_free(path);
2305 if(FAILED(hres))
2306 return NS_ERROR_UNEXPECTED;
2308 return NS_OK;
2311 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2313 nsWineURI *This = impl_from_nsIFileURL(iface);
2314 nsWineURI *other_obj;
2315 nsresult nsres;
2316 HRESULT hres;
2318 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2320 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2321 if(NS_FAILED(nsres)) {
2322 TRACE("Could not get nsWineURI interface\n");
2323 *_retval = FALSE;
2324 return NS_OK;
2327 if(ensure_uri(This) && ensure_uri(other_obj)) {
2328 BOOL b;
2330 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2331 if(SUCCEEDED(hres)) {
2332 *_retval = b;
2333 nsres = NS_OK;
2334 }else {
2335 nsres = NS_ERROR_FAILURE;
2337 }else {
2338 nsres = NS_ERROR_UNEXPECTED;
2341 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2342 return nsres;
2345 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2347 nsWineURI *This = impl_from_nsIFileURL(iface);
2348 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2349 BSTR scheme_name;
2350 HRESULT hres;
2352 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2354 if(!ensure_uri(This))
2355 return NS_ERROR_UNEXPECTED;
2357 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2358 if(FAILED(hres))
2359 return NS_ERROR_UNEXPECTED;
2361 MultiByteToWideChar(CP_UTF8, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2362 *_retval = !strcmpW(scheme_name, buf);
2363 SysFreeString(scheme_name);
2364 return NS_OK;
2367 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2369 nsWineURI *This = impl_from_nsIFileURL(iface);
2370 nsWineURI *wine_uri;
2371 nsresult nsres;
2373 TRACE("(%p)->(%p)\n", This, _retval);
2375 if(!ensure_uri(This))
2376 return NS_ERROR_UNEXPECTED;
2378 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL,
2379 This->container, This->origin_charset, &wine_uri);
2380 if(NS_FAILED(nsres)) {
2381 WARN("create_nsuri failed: %08x\n", nsres);
2382 return nsres;
2385 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2386 return NS_OK;
2389 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2390 nsACString *_retval)
2392 nsWineURI *This = impl_from_nsIFileURL(iface);
2393 const char *patha;
2394 IUri *new_uri;
2395 WCHAR *path;
2396 char *reta;
2397 BSTR ret;
2398 HRESULT hres;
2400 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2402 if(!ensure_uri(This))
2403 return NS_ERROR_UNEXPECTED;
2405 nsACString_GetData(aRelativePath, &patha);
2406 path = heap_strdupUtoW(patha);
2407 if(!path)
2408 return NS_ERROR_OUT_OF_MEMORY;
2410 hres = CoInternetCombineUrlEx(This->uri, path, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, &new_uri, 0);
2411 heap_free(path);
2412 if(FAILED(hres)) {
2413 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres);
2414 return NS_ERROR_FAILURE;
2417 hres = IUri_GetDisplayUri(new_uri, &ret);
2418 IUri_Release(new_uri);
2419 if(FAILED(hres))
2420 return NS_ERROR_FAILURE;
2422 reta = heap_strdupWtoU(ret);
2423 SysFreeString(ret);
2424 if(!reta)
2425 return NS_ERROR_OUT_OF_MEMORY;
2427 TRACE("returning %s\n", debugstr_a(reta));
2428 nsACString_SetData(_retval, reta);
2429 heap_free(reta);
2430 return NS_OK;
2433 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2435 nsWineURI *This = impl_from_nsIFileURL(iface);
2437 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2439 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2442 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2444 nsWineURI *This = impl_from_nsIFileURL(iface);
2446 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2448 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2451 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2453 nsWineURI *This = impl_from_nsIFileURL(iface);
2455 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2457 nsACString_SetData(aOriginCharset, This->origin_charset);
2458 return NS_OK;
2461 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2463 nsWineURI *This = impl_from_nsIFileURL(iface);
2464 char *refa = NULL;
2465 BSTR ref;
2466 HRESULT hres;
2468 TRACE("(%p)->(%p)\n", This, aRef);
2470 if(!ensure_uri(This))
2471 return NS_ERROR_UNEXPECTED;
2473 hres = IUri_GetFragment(This->uri, &ref);
2474 if(FAILED(hres))
2475 return NS_ERROR_UNEXPECTED;
2477 refa = heap_strdupWtoU(ref);
2478 SysFreeString(ref);
2479 if(ref && !refa)
2480 return NS_ERROR_OUT_OF_MEMORY;
2482 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2483 heap_free(refa);
2484 return NS_OK;
2487 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2489 nsWineURI *This = impl_from_nsIFileURL(iface);
2490 const char *refa;
2491 WCHAR *ref;
2492 HRESULT hres;
2494 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2496 if(!ensure_uri_builder(This))
2497 return NS_ERROR_UNEXPECTED;
2499 nsACString_GetData(aRef, &refa);
2500 ref = heap_strdupUtoW(refa);
2501 if(!ref)
2502 return NS_ERROR_OUT_OF_MEMORY;
2504 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2505 heap_free(ref);
2506 if(FAILED(hres))
2507 return NS_ERROR_UNEXPECTED;
2509 return NS_OK;
2512 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2514 nsWineURI *This = impl_from_nsIFileURL(iface);
2515 nsWineURI *other_obj;
2516 nsresult nsres;
2518 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2520 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2521 if(NS_FAILED(nsres)) {
2522 TRACE("Could not get nsWineURI interface\n");
2523 *_retval = FALSE;
2524 return NS_OK;
2527 if(ensure_uri(This) && ensure_uri(other_obj)) {
2528 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2529 nsres = NS_OK;
2530 }else {
2531 nsres = NS_ERROR_UNEXPECTED;
2534 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2535 return nsres;
2538 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2540 nsWineURI *This = impl_from_nsIFileURL(iface);
2541 nsWineURI *wine_uri;
2542 IUri *uri;
2543 nsresult nsres;
2545 TRACE("(%p)->(%p)\n", This, _retval);
2547 if(!ensure_uri(This))
2548 return NS_ERROR_UNEXPECTED;
2550 uri = get_uri_nofrag(This->uri);
2551 if(!uri)
2552 return NS_ERROR_FAILURE;
2554 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container,
2555 This->origin_charset, &wine_uri);
2556 IUri_Release(uri);
2557 if(NS_FAILED(nsres)) {
2558 WARN("create_nsuri failed: %08x\n", nsres);
2559 return nsres;
2562 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2563 return NS_OK;
2566 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2568 nsWineURI *This = impl_from_nsIFileURL(iface);
2570 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2572 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2575 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2577 nsWineURI *This = impl_from_nsIFileURL(iface);
2578 BOOL b;
2579 HRESULT hres;
2581 TRACE("(%p)->(%p)\n", This, aHasRef);
2583 if(!ensure_uri(This))
2584 return NS_ERROR_UNEXPECTED;
2586 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2587 if(FAILED(hres))
2588 return NS_ERROR_FAILURE;
2590 *aHasRef = b;
2591 return NS_OK;
2594 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2596 nsWineURI *This = impl_from_nsIFileURL(iface);
2598 TRACE("(%p)->(%p)\n", This, aFilePath);
2600 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2603 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2605 nsWineURI *This = impl_from_nsIFileURL(iface);
2607 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2609 if(!This->is_mutable)
2610 return NS_ERROR_UNEXPECTED;
2612 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
2615 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
2617 nsWineURI *This = impl_from_nsIFileURL(iface);
2619 TRACE("(%p)->(%p)\n", This, aQuery);
2621 return get_uri_string(This, Uri_PROPERTY_QUERY, aQuery);
2624 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
2626 nsWineURI *This = impl_from_nsIFileURL(iface);
2627 const char *querya;
2628 WCHAR *query;
2629 HRESULT hres;
2631 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2633 if(!ensure_uri_builder(This))
2634 return NS_ERROR_UNEXPECTED;
2636 nsACString_GetData(aQuery, &querya);
2637 query = heap_strdupUtoW(querya);
2638 if(!query)
2639 return NS_ERROR_OUT_OF_MEMORY;
2641 hres = IUriBuilder_SetQuery(This->uri_builder, query);
2642 heap_free(query);
2643 if(FAILED(hres))
2644 return NS_ERROR_UNEXPECTED;
2646 return NS_OK;
2649 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
2651 const WCHAR *ptr;
2652 HRESULT hres;
2654 if(!ensure_uri(This))
2655 return NS_ERROR_UNEXPECTED;
2657 hres = IUri_GetPath(This->uri, path);
2658 if(FAILED(hres))
2659 return NS_ERROR_FAILURE;
2661 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
2662 if(*ptr == '/' || *ptr == '\\')
2663 ptr++;
2664 *file = ptr;
2666 if(ext) {
2667 ptr = strrchrW(ptr, '.');
2668 if(!ptr)
2669 ptr = *path + SysStringLen(*path);
2670 *ext = ptr;
2673 return NS_OK;
2676 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
2678 nsWineURI *This = impl_from_nsIFileURL(iface);
2679 const WCHAR *file;
2680 BSTR path;
2681 nsresult nsres;
2683 TRACE("(%p)->(%p)\n", This, aDirectory);
2685 nsres = get_uri_path(This, &path, &file, NULL);
2686 if(NS_FAILED(nsres))
2687 return nsres;
2689 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
2690 SysFreeString(path);
2691 return nsres;
2694 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
2696 nsWineURI *This = impl_from_nsIFileURL(iface);
2698 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2700 /* Not implemented by Gecko */
2701 return NS_ERROR_NOT_IMPLEMENTED;
2704 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
2706 nsWineURI *This = impl_from_nsIFileURL(iface);
2707 const WCHAR *file;
2708 BSTR path;
2709 nsresult nsres;
2711 TRACE("(%p)->(%p)\n", This, aFileName);
2713 nsres = get_uri_path(This, &path, &file, NULL);
2714 if(NS_FAILED(nsres))
2715 return nsres;
2717 nsres = return_wstr_nsacstr(aFileName, file, -1);
2718 SysFreeString(path);
2719 return nsres;
2722 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
2724 nsWineURI *This = impl_from_nsIFileURL(iface);
2725 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2726 return NS_ERROR_NOT_IMPLEMENTED;
2729 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
2731 nsWineURI *This = impl_from_nsIFileURL(iface);
2732 const WCHAR *file, *ext;
2733 BSTR path;
2734 nsresult nsres;
2736 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2738 nsres = get_uri_path(This, &path, &file, &ext);
2739 if(NS_FAILED(nsres))
2740 return nsres;
2742 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
2743 SysFreeString(path);
2744 return nsres;
2747 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
2749 nsWineURI *This = impl_from_nsIFileURL(iface);
2750 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2751 return NS_ERROR_NOT_IMPLEMENTED;
2754 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
2756 nsWineURI *This = impl_from_nsIFileURL(iface);
2758 TRACE("(%p)->(%p)\n", This, aFileExtension);
2760 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
2763 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
2765 nsWineURI *This = impl_from_nsIFileURL(iface);
2766 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2767 return NS_ERROR_NOT_IMPLEMENTED;
2770 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2772 nsWineURI *This = impl_from_nsIFileURL(iface);
2773 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2774 return NS_ERROR_NOT_IMPLEMENTED;
2777 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2779 nsWineURI *This = impl_from_nsIFileURL(iface);
2780 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2781 return NS_ERROR_NOT_IMPLEMENTED;
2784 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
2786 nsWineURI *This = impl_from_nsIFileURL(iface);
2787 WCHAR path[MAX_PATH];
2788 DWORD size;
2789 HRESULT hres;
2791 TRACE("(%p)->(%p)\n", This, aFile);
2793 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
2794 if(FAILED(hres)) {
2795 WARN("CoInternetParseIUri failed: %08x\n", hres);
2796 return NS_ERROR_FAILURE;
2799 return create_nsfile(path, aFile);
2802 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
2804 nsWineURI *This = impl_from_nsIFileURL(iface);
2805 FIXME("(%p)->(%p)\n", This, aFile);
2806 return NS_ERROR_NOT_IMPLEMENTED;
2809 static const nsIFileURLVtbl nsFileURLVtbl = {
2810 nsURI_QueryInterface,
2811 nsURI_AddRef,
2812 nsURI_Release,
2813 nsURI_GetSpec,
2814 nsURI_SetSpec,
2815 nsURI_GetPrePath,
2816 nsURI_GetScheme,
2817 nsURI_SetScheme,
2818 nsURI_GetUserPass,
2819 nsURI_SetUserPass,
2820 nsURI_GetUsername,
2821 nsURI_SetUsername,
2822 nsURI_GetPassword,
2823 nsURI_SetPassword,
2824 nsURI_GetHostPort,
2825 nsURI_SetHostPort,
2826 nsURI_GetHost,
2827 nsURI_SetHost,
2828 nsURI_GetPort,
2829 nsURI_SetPort,
2830 nsURI_GetPath,
2831 nsURI_SetPath,
2832 nsURI_Equals,
2833 nsURI_SchemeIs,
2834 nsURI_Clone,
2835 nsURI_Resolve,
2836 nsURI_GetAsciiSpec,
2837 nsURI_GetAsciiHost,
2838 nsURI_GetOriginCharset,
2839 nsURL_GetRef,
2840 nsURL_SetRef,
2841 nsURI_EqualsExceptRef,
2842 nsURI_CloneIgnoreRef,
2843 nsURI_GetSpecIgnoringRef,
2844 nsURI_GetHasRef,
2845 nsURL_GetFilePath,
2846 nsURL_SetFilePath,
2847 nsURL_GetQuery,
2848 nsURL_SetQuery,
2849 nsURL_GetDirectory,
2850 nsURL_SetDirectory,
2851 nsURL_GetFileName,
2852 nsURL_SetFileName,
2853 nsURL_GetFileBaseName,
2854 nsURL_SetFileBaseName,
2855 nsURL_GetFileExtension,
2856 nsURL_SetFileExtension,
2857 nsURL_GetCommonBaseSpec,
2858 nsURL_GetRelativeSpec,
2859 nsFileURL_GetFile,
2860 nsFileURL_SetFile
2863 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
2865 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
2868 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
2869 void **result)
2871 nsWineURI *This = impl_from_nsIStandardURL(iface);
2872 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
2875 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
2877 nsWineURI *This = impl_from_nsIStandardURL(iface);
2878 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
2881 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
2883 nsWineURI *This = impl_from_nsIStandardURL(iface);
2884 return nsIFileURL_Release(&This->nsIFileURL_iface);
2887 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
2889 nsWineURI *This = impl_from_nsIStandardURL(iface);
2891 TRACE("(%p)->(%p)\n", This, aMutable);
2893 *aMutable = This->is_mutable;
2894 return NS_OK;
2897 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
2899 nsWineURI *This = impl_from_nsIStandardURL(iface);
2901 TRACE("(%p)->(%x)\n", This, aMutable);
2903 This->is_mutable = aMutable;
2904 return NS_OK;
2907 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, UINT32 aUrlType, LONG aDefaultPort,
2908 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
2910 nsWineURI *This = impl_from_nsIStandardURL(iface);
2911 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
2912 return NS_ERROR_NOT_IMPLEMENTED;
2915 static const nsIStandardURLVtbl nsStandardURLVtbl = {
2916 nsStandardURL_QueryInterface,
2917 nsStandardURL_AddRef,
2918 nsStandardURL_Release,
2919 nsStandardURL_GetMutable,
2920 nsStandardURL_SetMutable,
2921 nsStandardURL_Init
2924 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container,
2925 const char *origin_charset, nsWineURI **_retval)
2927 nsWineURI *ret;
2928 HRESULT hres;
2930 ret = heap_alloc_zero(sizeof(nsWineURI));
2931 if(!ret)
2932 return NS_ERROR_OUT_OF_MEMORY;
2934 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
2935 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
2936 ret->ref = 1;
2937 ret->is_mutable = TRUE;
2939 set_uri_nscontainer(ret, container);
2940 set_uri_window(ret, window);
2942 IUri_AddRef(iuri);
2943 ret->uri = iuri;
2945 hres = IUri_GetScheme(iuri, &ret->scheme);
2946 if(FAILED(hres))
2947 ret->scheme = URL_SCHEME_UNKNOWN;
2949 if(origin_charset && *origin_charset && strcmp(origin_charset, "UTF-8")) {
2950 ret->origin_charset = heap_strdupA(origin_charset);
2951 if(!ret->origin_charset) {
2952 nsIFileURL_Release(&ret->nsIFileURL_iface);
2953 return NS_ERROR_OUT_OF_MEMORY;
2957 TRACE("retval=%p\n", ret);
2958 *_retval = ret;
2959 return NS_OK;
2962 HRESULT create_doc_uri(HTMLOuterWindow *window, IUri *iuri, nsWineURI **ret)
2964 nsWineURI *uri;
2965 nsresult nsres;
2967 nsres = create_nsuri(iuri, window, window->doc_obj->nscontainer, NULL, &uri);
2968 if(NS_FAILED(nsres))
2969 return E_FAIL;
2971 uri->is_doc_uri = TRUE;
2973 *ret = uri;
2974 return S_OK;
2977 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
2979 nsChannel *channel;
2981 if(!ensure_uri(uri))
2982 return NS_ERROR_UNEXPECTED;
2984 channel = heap_alloc_zero(sizeof(nsChannel));
2985 if(!channel)
2986 return NS_ERROR_OUT_OF_MEMORY;
2988 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
2989 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
2990 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
2991 channel->ref = 1;
2992 channel->request_method = METHOD_GET;
2993 list_init(&channel->response_headers);
2994 list_init(&channel->request_headers);
2996 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
2997 channel->uri = uri;
2999 *ret = channel;
3000 return NS_OK;
3003 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
3005 HTMLOuterWindow *window = NULL;
3006 nsChannel *channel;
3007 nsWineURI *uri;
3008 IUri *iuri;
3009 nsresult nsres;
3010 HRESULT hres;
3012 hres = create_uri(url, 0, &iuri);
3013 if(FAILED(hres))
3014 return hres;
3016 if(orig_channel->uri->window_ref)
3017 window = orig_channel->uri->window_ref->window;
3018 nsres = create_nsuri(iuri, window, NULL, NULL, &uri);
3019 IUri_Release(iuri);
3020 if(NS_FAILED(nsres))
3021 return E_FAIL;
3023 nsres = create_nschannel(uri, &channel);
3024 nsIFileURL_Release(&uri->nsIFileURL_iface);
3025 if(NS_FAILED(nsres))
3026 return E_FAIL;
3028 if(orig_channel->load_group) {
3029 nsILoadGroup_AddRef(orig_channel->load_group);
3030 channel->load_group = orig_channel->load_group;
3033 if(orig_channel->notif_callback) {
3034 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
3035 channel->notif_callback = orig_channel->notif_callback;
3038 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
3040 if(orig_channel->request_method == METHOD_POST)
3041 FIXME("unsupported POST method\n");
3043 if(orig_channel->original_uri) {
3044 nsIURI_AddRef(orig_channel->original_uri);
3045 channel->original_uri = orig_channel->original_uri;
3048 if(orig_channel->referrer) {
3049 nsIURI_AddRef(orig_channel->referrer);
3050 channel->referrer = orig_channel->referrer;
3053 *ret = channel;
3054 return S_OK;
3057 typedef struct {
3058 nsIProtocolHandler nsIProtocolHandler_iface;
3060 LONG ref;
3062 nsIProtocolHandler *nshandler;
3063 } nsProtocolHandler;
3065 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
3067 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
3070 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3071 void **result)
3073 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3075 *result = NULL;
3077 if(IsEqualGUID(&IID_nsISupports, riid)) {
3078 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3079 *result = &This->nsIProtocolHandler_iface;
3080 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3081 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3082 *result = &This->nsIProtocolHandler_iface;
3083 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3084 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3085 return NS_NOINTERFACE;
3088 if(*result) {
3089 nsISupports_AddRef((nsISupports*)*result);
3090 return NS_OK;
3093 WARN("(%s %p)\n", debugstr_guid(riid), result);
3094 return NS_NOINTERFACE;
3097 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3099 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3100 LONG ref = InterlockedIncrement(&This->ref);
3102 TRACE("(%p) ref=%d\n", This, ref);
3104 return ref;
3107 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3109 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3110 LONG ref = InterlockedDecrement(&This->ref);
3112 TRACE("(%p) ref=%d\n", This, ref);
3114 if(!ref) {
3115 if(This->nshandler)
3116 nsIProtocolHandler_Release(This->nshandler);
3117 heap_free(This);
3120 return ref;
3123 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3125 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3127 TRACE("(%p)->(%p)\n", This, aScheme);
3129 if(This->nshandler)
3130 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3131 return NS_ERROR_NOT_IMPLEMENTED;
3134 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3135 LONG *aDefaultPort)
3137 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3139 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3141 if(This->nshandler)
3142 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3143 return NS_ERROR_NOT_IMPLEMENTED;
3146 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3147 UINT32 *aProtocolFlags)
3149 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3151 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3153 if(This->nshandler)
3154 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3155 return NS_ERROR_NOT_IMPLEMENTED;
3158 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3159 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3161 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3163 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3164 aBaseURI, _retval);
3166 if(This->nshandler)
3167 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3168 return NS_ERROR_NOT_IMPLEMENTED;
3171 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3172 nsIURI *aURI, nsIChannel **_retval)
3174 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3176 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3178 if(This->nshandler)
3179 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3180 return NS_ERROR_NOT_IMPLEMENTED;
3183 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3184 LONG port, const char *scheme, cpp_bool *_retval)
3186 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3188 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3190 if(This->nshandler)
3191 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3192 return NS_ERROR_NOT_IMPLEMENTED;
3195 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3196 nsProtocolHandler_QueryInterface,
3197 nsProtocolHandler_AddRef,
3198 nsProtocolHandler_Release,
3199 nsProtocolHandler_GetScheme,
3200 nsProtocolHandler_GetDefaultPort,
3201 nsProtocolHandler_GetProtocolFlags,
3202 nsProtocolHandler_NewURI,
3203 nsProtocolHandler_NewChannel,
3204 nsProtocolHandler_AllowPort
3207 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
3209 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
3211 return 2;
3214 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
3216 return 1;
3219 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
3220 nsIProtocolHandler **_retval)
3222 nsIExternalProtocolHandler *nsexthandler;
3223 nsIProtocolHandler *nshandler;
3224 nsProtocolHandler *ret;
3225 nsresult nsres;
3227 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3229 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
3230 if(NS_FAILED(nsres)) {
3231 WARN("GetProtocolHandler failed: %08x\n", nsres);
3232 return nsres;
3235 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
3236 (void**)&nsexthandler);
3237 if(NS_FAILED(nsres)) {
3238 *_retval = nshandler;
3239 return NS_OK;
3242 nsIExternalProtocolHandler_Release(nsexthandler);
3244 ret = heap_alloc(sizeof(nsProtocolHandler));
3245 if(!ret)
3246 return NS_ERROR_OUT_OF_MEMORY;
3248 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3249 ret->ref = 1;
3250 ret->nshandler = nshandler;
3251 *_retval = &ret->nsIProtocolHandler_iface;
3253 TRACE("return %p\n", *_retval);
3254 return NS_OK;
3257 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
3258 UINT32 *_retval)
3260 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
3261 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
3264 static BOOL is_gecko_special_uri(const char *spec)
3266 static const char *special_schemes[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3267 unsigned int i;
3269 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3270 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3271 return TRUE;
3274 if(!strncasecmp(spec, "file:", 5)) {
3275 const char *ptr = spec+5;
3276 while(*ptr == '/')
3277 ptr++;
3278 return is_gecko_path(ptr);
3281 return FALSE;
3284 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
3285 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3287 nsWineURI *wine_uri, *base_wine_uri = NULL;
3288 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3289 HTMLOuterWindow *window = NULL;
3290 const char *spec = NULL;
3291 IUri *urlmon_uri;
3292 nsresult nsres;
3293 HRESULT hres;
3295 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3296 aBaseURI, _retval);
3298 nsACString_GetData(aSpec, &spec);
3299 if(is_gecko_special_uri(spec))
3300 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3302 if(!strncmp(spec, "wine:", 5))
3303 spec += 5;
3305 if(aBaseURI) {
3306 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3307 if(NS_SUCCEEDED(nsres)) {
3308 if(!ensure_uri(base_wine_uri))
3309 return NS_ERROR_UNEXPECTED;
3310 if(base_wine_uri->window_ref)
3311 window = base_wine_uri->window_ref->window;
3312 }else {
3313 WARN("Could not get base nsWineURI: %08x\n", nsres);
3317 MultiByteToWideChar(CP_ACP, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3319 if(base_wine_uri) {
3320 hres = CoInternetCombineUrlEx(base_wine_uri->uri, new_spec, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
3321 &urlmon_uri, 0);
3322 if(FAILED(hres))
3323 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
3324 }else {
3325 hres = create_uri(new_spec, 0, &urlmon_uri);
3326 if(FAILED(hres))
3327 WARN("create_uri failed: %08x\n", hres);
3330 if(FAILED(hres))
3331 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3333 nsres = create_nsuri(urlmon_uri, window, NULL, NULL, &wine_uri);
3334 IUri_Release(urlmon_uri);
3335 if(base_wine_uri)
3336 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3337 if(NS_FAILED(nsres))
3338 return nsres;
3340 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3341 return nsres;
3344 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
3345 nsIURI **_retval)
3347 TRACE("(%p %p)\n", aFile, _retval);
3348 return nsIIOService_NewFileURI(nsio, aFile, _retval);
3351 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
3352 nsIChannel **_retval)
3354 nsWineURI *wine_uri;
3355 nsChannel *ret;
3356 nsresult nsres;
3358 TRACE("(%p %p)\n", aURI, _retval);
3360 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3361 if(NS_FAILED(nsres)) {
3362 TRACE("Could not get nsWineURI: %08x\n", nsres);
3363 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
3366 nsres = create_nschannel(wine_uri, &ret);
3367 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3368 if(NS_FAILED(nsres))
3369 return nsres;
3371 nsIURI_AddRef(aURI);
3372 ret->original_uri = aURI;
3374 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3375 return NS_OK;
3378 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
3379 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
3381 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
3382 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
3385 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, cpp_bool *aOffline)
3387 TRACE("(%p)\n", aOffline);
3388 return nsIIOService_GetOffline(nsio, aOffline);
3391 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, cpp_bool aOffline)
3393 TRACE("(%x)\n", aOffline);
3394 return nsIIOService_SetOffline(nsio, aOffline);
3397 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, LONG aPort,
3398 const char *aScheme, cpp_bool *_retval)
3400 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
3401 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
3404 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
3405 nsACString * _retval)
3407 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
3408 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
3411 static const nsIIOServiceVtbl nsIOServiceVtbl = {
3412 nsIOService_QueryInterface,
3413 nsIOService_AddRef,
3414 nsIOService_Release,
3415 nsIOService_GetProtocolHandler,
3416 nsIOService_GetProtocolFlags,
3417 nsIOService_NewURI,
3418 nsIOService_NewFileURI,
3419 nsIOService_NewChannelFromURI,
3420 nsIOService_NewChannel,
3421 nsIOService_GetOffline,
3422 nsIOService_SetOffline,
3423 nsIOService_AllowPort,
3424 nsIOService_ExtractScheme
3427 static nsIIOService nsIOService = { &nsIOServiceVtbl };
3429 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
3430 void **result)
3432 return nsIIOService_QueryInterface(&nsIOService, riid, result);
3435 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
3437 return 2;
3440 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
3442 return 1;
3445 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3446 nsACString *aCharset, cpp_bool *aHadCharset, nsACString *aContentType)
3448 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
3450 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
3453 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3455 TRACE("()\n");
3457 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
3460 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3462 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
3464 if(aFlags == (1<<11)) {
3465 *_retval = FALSE;
3466 return NS_OK;
3469 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
3472 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3474 TRACE("(%p %p)\n", aURI, _retval);
3476 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
3479 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
3481 TRACE("(%p %p)\n", aURI, _retval);
3483 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
3486 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
3487 UINT32 aEscapeType, nsACString *_retval)
3489 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
3491 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
3494 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, UINT32 aFlags,
3495 nsACString *_retval)
3497 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3499 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
3502 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
3503 UINT32 aFlags, nsACString *_retval)
3505 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
3507 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
3510 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
3511 nsACString *aCharset, LONG *aCharsetStart, LONG *aCharsetEnd, cpp_bool *_retval)
3513 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
3514 aCharsetEnd, _retval);
3516 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
3519 static const nsINetUtilVtbl nsNetUtilVtbl = {
3520 nsNetUtil_QueryInterface,
3521 nsNetUtil_AddRef,
3522 nsNetUtil_Release,
3523 nsNetUtil_ParseContentType,
3524 nsNetUtil_ProtocolHasFlags,
3525 nsNetUtil_URIChainHasFlags,
3526 nsNetUtil_ToImmutableURI,
3527 nsNetUtil_NewSimpleNestedURI,
3528 nsNetUtil_EscapeString,
3529 nsNetUtil_EscapeURL,
3530 nsNetUtil_UnescapeString,
3531 nsNetUtil_ExtractCharsetFromContentType
3534 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
3536 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
3537 void **result)
3539 *result = NULL;
3541 if(IsEqualGUID(&IID_nsISupports, riid))
3542 *result = &nsIOService;
3543 else if(IsEqualGUID(&IID_nsIIOService, riid))
3544 *result = &nsIOService;
3545 else if(IsEqualGUID(&IID_nsINetUtil, riid))
3546 *result = &nsNetUtil;
3548 if(*result) {
3549 nsISupports_AddRef((nsISupports*)*result);
3550 return NS_OK;
3553 FIXME("(%s %p)\n", debugstr_guid(riid), result);
3554 return NS_NOINTERFACE;
3557 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
3558 void **result)
3560 *result = NULL;
3562 if(IsEqualGUID(&IID_nsISupports, riid)) {
3563 TRACE("(IID_nsISupports %p)\n", result);
3564 *result = iface;
3565 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
3566 TRACE("(IID_nsIFactory %p)\n", result);
3567 *result = iface;
3570 if(*result) {
3571 nsIFactory_AddRef(iface);
3572 return NS_OK;
3575 WARN("(%s %p)\n", debugstr_guid(riid), result);
3576 return NS_NOINTERFACE;
3579 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
3581 return 2;
3584 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
3586 return 1;
3589 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
3590 nsISupports *aOuter, const nsIID *iid, void **result)
3592 return nsIIOService_QueryInterface(&nsIOService, iid, result);
3595 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
3597 WARN("(%x)\n", lock);
3598 return NS_OK;
3601 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
3602 nsIOServiceFactory_QueryInterface,
3603 nsIOServiceFactory_AddRef,
3604 nsIOServiceFactory_Release,
3605 nsIOServiceFactory_CreateInstance,
3606 nsIOServiceFactory_LockFactory
3609 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
3611 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3613 OLECHAR *new_url = NULL;
3614 WCHAR *url;
3615 BOOL ret = FALSE;
3616 HRESULT hres;
3618 if(!doc->hostui || !ensure_uri(uri))
3619 return FALSE;
3621 hres = IUri_GetDisplayUri(uri->uri, &url);
3622 if(FAILED(hres))
3623 return FALSE;
3625 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3626 if(hres == S_OK && new_url) {
3627 if(strcmpW(url, new_url)) {
3628 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3629 ret = TRUE;
3631 CoTaskMemFree(new_url);
3634 SysFreeString(url);
3635 return ret;
3638 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
3640 nsWineURI *wine_uri;
3641 nsresult nsres;
3643 *_retval = FALSE;
3645 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3646 if(NS_FAILED(nsres)) {
3647 WARN("Could not get nsWineURI: %08x\n", nsres);
3648 return NS_ERROR_NOT_IMPLEMENTED;
3651 if(!wine_uri->is_doc_uri) {
3652 wine_uri->is_doc_uri = TRUE;
3654 if(!wine_uri->container) {
3655 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3656 wine_uri->container = nscontainer;
3659 if(nscontainer->doc)
3660 *_retval = translate_url(nscontainer->doc, wine_uri);
3663 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3664 return NS_OK;
3667 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
3669 nsIFactory *old_factory = NULL;
3670 nsresult nsres;
3672 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3673 &IID_nsIFactory, (void**)&old_factory);
3674 if(NS_FAILED(nsres)) {
3675 ERR("Could not get factory: %08x\n", nsres);
3676 return;
3679 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3680 if(NS_FAILED(nsres)) {
3681 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3682 nsIFactory_Release(old_factory);
3683 return;
3686 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3687 if(NS_FAILED(nsres)) {
3688 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3689 nsIIOService_Release(nsio);
3690 return;
3693 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3694 nsIFactory_Release(old_factory);
3695 if(NS_FAILED(nsres))
3696 ERR("UnregisterFactory failed: %08x\n", nsres);
3698 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3699 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3700 if(NS_FAILED(nsres))
3701 ERR("RegisterFactory failed: %08x\n", nsres);
3704 void release_nsio(void)
3706 if(net_util) {
3707 nsINetUtil_Release(net_util);
3708 net_util = NULL;
3711 if(nsio) {
3712 nsIIOService_Release(nsio);
3713 nsio = NULL;