wined3d: Add basic support for rendering to 3D textures.
[wine.git] / dlls / mshtml / nsio.c
blob5a806c4b58612c25608757dc78188924a0afc9b4
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;
52 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
54 struct nsWineURI {
55 nsIFileURL nsIFileURL_iface; /* For non-file URL objects, it's just nsIURL */
56 nsIStandardURL nsIStandardURL_iface;
58 LONG ref;
60 NSContainer *container;
61 windowref_t *window_ref;
62 nsChannelBSC *channel_bsc;
63 IUri *uri;
64 IUriBuilder *uri_builder;
65 char *origin_charset;
66 BOOL is_doc_uri;
67 BOOL is_mutable;
68 DWORD scheme;
71 static BOOL ensure_uri(nsWineURI *This)
73 HRESULT hres;
75 assert(This->uri || This->uri_builder);
77 if(!This->uri) {
78 hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
79 if(FAILED(hres)) {
80 WARN("CreateUriSimple failed: %08x\n", hres);
81 return FALSE;
85 return TRUE;
88 IUri *nsuri_get_uri(nsWineURI *nsuri)
90 if(!ensure_uri(nsuri))
91 return NULL;
93 IUri_AddRef(nsuri->uri);
94 return nsuri->uri;
97 IUri *get_uri_nofrag(IUri *uri)
99 IUriBuilder *uri_builder;
100 IUri *ret;
101 BOOL b;
102 HRESULT hres;
104 hres = IUri_HasProperty(uri, Uri_PROPERTY_FRAGMENT, &b);
105 if(SUCCEEDED(hres) && !b) {
106 IUri_AddRef(uri);
107 return uri;
110 hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
111 if(FAILED(hres))
112 return NULL;
114 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_FRAGMENT);
115 if(SUCCEEDED(hres))
116 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &ret);
117 IUriBuilder_Release(uri_builder);
118 if(FAILED(hres))
119 return NULL;
121 return ret;
124 static BOOL compare_ignoring_frag(IUri *uri1, IUri *uri2)
126 IUri *uri_nofrag1, *uri_nofrag2;
127 BOOL ret = FALSE;
129 uri_nofrag1 = get_uri_nofrag(uri1);
130 if(!uri_nofrag1)
131 return FALSE;
133 uri_nofrag2 = get_uri_nofrag(uri2);
134 if(uri_nofrag2) {
135 IUri_IsEqual(uri_nofrag1, uri_nofrag2, &ret);
136 IUri_Release(uri_nofrag2);
139 IUri_Release(uri_nofrag1);
140 return ret;
143 static HRESULT combine_url(IUri *base_uri, const WCHAR *rel_url, IUri **ret)
145 IUri *uri_nofrag;
146 HRESULT hres;
148 uri_nofrag = get_uri_nofrag(base_uri);
149 if(!uri_nofrag)
150 return E_FAIL;
152 hres = CoInternetCombineUrlEx(uri_nofrag, rel_url, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
153 ret, 0);
154 IUri_Release(uri_nofrag);
155 if(FAILED(hres))
156 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
157 return hres;
160 static nsresult create_nsuri(IUri*,HTMLOuterWindow*,NSContainer*,const char*,nsWineURI**);
162 static const char *debugstr_nsacstr(const nsACString *nsstr)
164 const char *data;
166 nsACString_GetData(nsstr, &data);
167 return debugstr_a(data);
170 static nsresult return_wstr_nsacstr(nsACString *ret_str, const WCHAR *str, int len)
172 char *stra;
173 int lena;
175 TRACE("returning %s\n", debugstr_wn(str, len));
177 if(!*str) {
178 nsACString_SetData(ret_str, "");
179 return NS_OK;
182 lena = WideCharToMultiByte(CP_UTF8, 0, str, len, NULL, 0, NULL, NULL);
183 stra = heap_alloc(lena+1);
184 if(!stra)
185 return NS_ERROR_OUT_OF_MEMORY;
187 WideCharToMultiByte(CP_UTF8, 0, str, len, stra, lena, NULL, NULL);
188 stra[lena] = 0;
190 nsACString_SetData(ret_str, stra);
191 heap_free(stra);
192 return NS_OK;
195 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
197 const WCHAR *ptr = nsuri;
199 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
201 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
202 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
204 if(*ptr || ret_empty) {
205 *ret = SysAllocString(ptr);
206 if(!*ret)
207 return E_OUTOFMEMORY;
208 }else {
209 *ret = NULL;
212 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
213 return S_OK;
216 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
218 IOleCommandTarget *cmdtrg = NULL;
219 HRESULT hres;
221 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
222 if(SUCCEEDED(hres)) {
223 VARIANT varUrl, varRes;
225 V_VT(&varUrl) = VT_BSTR;
226 V_BSTR(&varUrl) = url;
227 V_VT(&varRes) = VT_BOOL;
229 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
231 IOleCommandTarget_Release(cmdtrg);
233 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
234 TRACE("got VARIANT_FALSE, do not load\n");
235 return FALSE;
239 return TRUE;
242 static nsresult before_async_open(nsChannel *channel, NSContainer *container, BOOL *cancel)
244 HTMLDocumentObj *doc = container->doc;
245 BSTR display_uri;
246 HRESULT hres;
248 if(!doc->client) {
249 *cancel = TRUE;
250 return NS_OK;
253 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
254 if(FAILED(hres))
255 return NS_ERROR_FAILURE;
257 if(!exec_shldocvw_67(doc, display_uri)) {
258 SysFreeString(display_uri);
259 *cancel = FALSE;
260 return NS_OK;
263 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, 0, cancel);
264 SysFreeString(display_uri);
265 if(FAILED(hres))
266 *cancel = TRUE;
267 return NS_OK;
270 HRESULT load_nsuri(HTMLOuterWindow *window, nsWineURI *uri, nsIInputStream *post_stream,
271 nsChannelBSC *channelbsc, DWORD flags)
273 nsIDocShellLoadInfo *load_info = NULL;
274 nsIWebNavigation *web_navigation;
275 nsIDocShell *doc_shell;
276 HTMLDocumentNode *doc;
277 nsresult nsres;
279 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
280 if(NS_FAILED(nsres)) {
281 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
282 return E_FAIL;
285 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
286 nsIWebNavigation_Release(web_navigation);
287 if(NS_FAILED(nsres)) {
288 ERR("Could not get nsIDocShell: %08x\n", nsres);
289 return E_FAIL;
292 if(post_stream) {
293 nsres = nsIDocShell_CreateLoadInfo(doc_shell, &load_info);
294 if(NS_FAILED(nsres)) {
295 nsIDocShell_Release(doc_shell);
296 return E_FAIL;
299 nsres = nsIDocShellLoadInfo_SetPostDataStream(load_info, post_stream);
300 assert(nsres == NS_OK);
303 uri->channel_bsc = channelbsc;
304 doc = window->base.inner_window->doc;
305 doc->skip_mutation_notif = TRUE;
306 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIFileURL_iface, load_info, flags, FALSE);
307 if(doc == window->base.inner_window->doc)
308 doc->skip_mutation_notif = FALSE;
309 uri->channel_bsc = NULL;
310 nsIDocShell_Release(doc_shell);
311 if(load_info)
312 nsIDocShellLoadInfo_Release(load_info);
313 if(NS_FAILED(nsres)) {
314 WARN("LoadURI failed: %08x\n", nsres);
315 return E_FAIL;
318 return S_OK;
321 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
323 if(This->container) {
324 if(This->container == nscontainer)
325 return;
326 TRACE("Changing %p -> %p\n", This->container, nscontainer);
327 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
330 if(nscontainer)
331 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
332 This->container = nscontainer;
335 static void set_uri_window(nsWineURI *This, HTMLOuterWindow *window)
337 if(This->window_ref) {
338 if(This->window_ref->window == window)
339 return;
340 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
341 windowref_release(This->window_ref);
344 if(window) {
345 windowref_addref(window->window_ref);
346 This->window_ref = window->window_ref;
348 if(window->doc_obj)
349 set_uri_nscontainer(This, window->doc_obj->nscontainer);
350 }else {
351 This->window_ref = NULL;
355 static inline BOOL is_http_channel(nsChannel *This)
357 return This->uri->scheme == URL_SCHEME_HTTP || This->uri->scheme == URL_SCHEME_HTTPS;
360 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
362 http_header_t *iter;
364 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
365 if(!strncmpiW(iter->header, name, len) && !iter->header[len])
366 return iter;
369 return NULL;
372 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
373 nsACString *_retval)
375 const char *header_namea;
376 http_header_t *header;
377 WCHAR *header_name;
378 char *data;
380 nsACString_GetData(header_name_str, &header_namea);
381 header_name = heap_strdupAtoW(header_namea);
382 if(!header_name)
383 return NS_ERROR_UNEXPECTED;
385 header = find_http_header(headers, header_name, strlenW(header_name));
386 heap_free(header_name);
387 if(!header)
388 return NS_ERROR_NOT_AVAILABLE;
390 data = heap_strdupWtoA(header->data);
391 if(!data)
392 return NS_ERROR_UNEXPECTED;
394 TRACE("%s -> %s\n", debugstr_a(header_namea), debugstr_a(data));
395 nsACString_SetData(_retval, data);
396 heap_free(data);
397 return NS_OK;
400 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
401 const WCHAR *value, int value_len)
403 http_header_t *header;
405 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
407 header = find_http_header(headers, name, name_len);
408 if(header) {
409 WCHAR *new_data;
411 new_data = heap_strndupW(value, value_len);
412 if(!new_data)
413 return E_OUTOFMEMORY;
415 heap_free(header->data);
416 header->data = new_data;
417 }else {
418 header = heap_alloc(sizeof(http_header_t));
419 if(!header)
420 return E_OUTOFMEMORY;
422 header->header = heap_strndupW(name, name_len);
423 header->data = heap_strndupW(value, value_len);
424 if(!header->header || !header->data) {
425 heap_free(header->header);
426 heap_free(header->data);
427 heap_free(header);
428 return E_OUTOFMEMORY;
431 list_add_tail(headers, &header->entry);
434 return S_OK;
437 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
438 const nsACString *value_str)
440 const char *namea, *valuea;
441 WCHAR *name, *value;
442 HRESULT hres;
444 nsACString_GetData(name_str, &namea);
445 name = heap_strdupAtoW(namea);
446 if(!name)
447 return NS_ERROR_UNEXPECTED;
449 nsACString_GetData(value_str, &valuea);
450 value = heap_strdupAtoW(valuea);
451 if(!value) {
452 heap_free(name);
453 return NS_ERROR_UNEXPECTED;
456 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
458 heap_free(name);
459 heap_free(value);
460 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
463 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
465 nsACString header_str, value_str;
466 char *header, *value;
467 http_header_t *iter;
468 nsresult nsres;
470 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
471 header = heap_strdupWtoA(iter->header);
472 if(!header)
473 return NS_ERROR_OUT_OF_MEMORY;
475 value = heap_strdupWtoA(iter->data);
476 if(!value) {
477 heap_free(header);
478 return NS_ERROR_OUT_OF_MEMORY;
481 nsACString_InitDepend(&header_str, header);
482 nsACString_InitDepend(&value_str, value);
483 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
484 nsACString_Finish(&header_str);
485 nsACString_Finish(&value_str);
486 heap_free(header);
487 heap_free(value);
488 if(NS_FAILED(nsres))
489 break;
492 return NS_OK;
495 static void free_http_headers(struct list *list)
497 http_header_t *iter, *iter_next;
499 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
500 list_remove(&iter->entry);
501 heap_free(iter->header);
502 heap_free(iter->data);
503 heap_free(iter);
507 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
509 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
512 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
514 nsChannel *This = impl_from_nsIHttpChannel(iface);
516 if(IsEqualGUID(&IID_nsISupports, riid)) {
517 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
518 *result = &This->nsIHttpChannel_iface;
519 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
520 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
521 *result = &This->nsIHttpChannel_iface;
522 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
523 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
524 *result = &This->nsIHttpChannel_iface;
525 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
526 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
527 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
528 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
529 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
530 *result = &This->nsIUploadChannel_iface;
531 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
532 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
533 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
534 }else {
535 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
536 *result = NULL;
539 if(*result) {
540 nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
541 return NS_OK;
544 return NS_NOINTERFACE;
547 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
549 nsChannel *This = impl_from_nsIHttpChannel(iface);
550 nsrefcnt ref = InterlockedIncrement(&This->ref);
552 TRACE("(%p) ref=%d\n", This, ref);
554 return ref;
557 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
559 nsChannel *This = impl_from_nsIHttpChannel(iface);
560 LONG ref = InterlockedDecrement(&This->ref);
562 if(!ref) {
563 nsIFileURL_Release(&This->uri->nsIFileURL_iface);
564 if(This->owner)
565 nsISupports_Release(This->owner);
566 if(This->post_data_stream)
567 nsIInputStream_Release(This->post_data_stream);
568 if(This->load_group)
569 nsILoadGroup_Release(This->load_group);
570 if(This->notif_callback)
571 nsIInterfaceRequestor_Release(This->notif_callback);
572 if(This->original_uri)
573 nsIURI_Release(This->original_uri);
574 if(This->referrer)
575 nsIURI_Release(This->referrer);
577 free_http_headers(&This->response_headers);
578 free_http_headers(&This->request_headers);
580 heap_free(This->content_type);
581 heap_free(This->charset);
582 heap_free(This);
585 return ref;
588 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
590 nsChannel *This = impl_from_nsIHttpChannel(iface);
592 TRACE("(%p)->(%p)\n", This, aName);
594 return nsIFileURL_GetSpec(&This->uri->nsIFileURL_iface, aName);
597 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, cpp_bool *_retval)
599 nsChannel *This = impl_from_nsIHttpChannel(iface);
601 FIXME("(%p)->(%p)\n", This, _retval);
603 return NS_ERROR_NOT_IMPLEMENTED;
606 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
608 nsChannel *This = impl_from_nsIHttpChannel(iface);
610 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
612 return *aStatus = NS_OK;
615 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
617 nsChannel *This = impl_from_nsIHttpChannel(iface);
619 TRACE("(%p)->(%08x)\n", This, aStatus);
621 if(This->binding && This->binding->bsc.binding)
622 IBinding_Abort(This->binding->bsc.binding);
623 else
624 WARN("No binding to cancel\n");
625 return NS_OK;
628 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
630 nsChannel *This = impl_from_nsIHttpChannel(iface);
632 FIXME("(%p)\n", This);
634 return NS_ERROR_NOT_IMPLEMENTED;
637 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
639 nsChannel *This = impl_from_nsIHttpChannel(iface);
641 FIXME("(%p)\n", This);
643 return NS_ERROR_NOT_IMPLEMENTED;
646 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
648 nsChannel *This = impl_from_nsIHttpChannel(iface);
650 TRACE("(%p)->(%p)\n", This, aLoadGroup);
652 if(This->load_group)
653 nsILoadGroup_AddRef(This->load_group);
655 *aLoadGroup = This->load_group;
656 return NS_OK;
659 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
661 nsChannel *This = impl_from_nsIHttpChannel(iface);
663 TRACE("(%p)->(%p)\n", This, aLoadGroup);
665 if(This->load_group)
666 nsILoadGroup_Release(This->load_group);
667 if(aLoadGroup)
668 nsILoadGroup_AddRef(aLoadGroup);
669 This->load_group = aLoadGroup;
671 return NS_OK;
674 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
676 nsChannel *This = impl_from_nsIHttpChannel(iface);
678 TRACE("(%p)->(%p)\n", This, aLoadFlags);
680 *aLoadFlags = This->load_flags;
681 return NS_OK;
684 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
686 nsChannel *This = impl_from_nsIHttpChannel(iface);
688 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
690 This->load_flags = aLoadFlags;
691 return NS_OK;
694 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
696 nsChannel *This = impl_from_nsIHttpChannel(iface);
698 TRACE("(%p)->(%p)\n", This, aOriginalURI);
700 if(This->original_uri)
701 nsIURI_AddRef(This->original_uri);
703 *aOriginalURI = This->original_uri;
704 return NS_OK;
707 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
709 nsChannel *This = impl_from_nsIHttpChannel(iface);
711 TRACE("(%p)->(%p)\n", This, aOriginalURI);
713 if(This->original_uri)
714 nsIURI_Release(This->original_uri);
716 nsIURI_AddRef(aOriginalURI);
717 This->original_uri = aOriginalURI;
718 return NS_OK;
721 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
723 nsChannel *This = impl_from_nsIHttpChannel(iface);
725 TRACE("(%p)->(%p)\n", This, aURI);
727 nsIFileURL_AddRef(&This->uri->nsIFileURL_iface);
728 *aURI = (nsIURI*)&This->uri->nsIFileURL_iface;
730 return NS_OK;
733 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
735 nsChannel *This = impl_from_nsIHttpChannel(iface);
737 TRACE("(%p)->(%p)\n", This, aOwner);
739 if(This->owner)
740 nsISupports_AddRef(This->owner);
741 *aOwner = This->owner;
743 return NS_OK;
746 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
748 nsChannel *This = impl_from_nsIHttpChannel(iface);
750 TRACE("(%p)->(%p)\n", This, aOwner);
752 if(aOwner)
753 nsISupports_AddRef(aOwner);
754 if(This->owner)
755 nsISupports_Release(This->owner);
756 This->owner = aOwner;
758 return NS_OK;
761 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
762 nsIInterfaceRequestor **aNotificationCallbacks)
764 nsChannel *This = impl_from_nsIHttpChannel(iface);
766 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
768 if(This->notif_callback)
769 nsIInterfaceRequestor_AddRef(This->notif_callback);
770 *aNotificationCallbacks = This->notif_callback;
772 return NS_OK;
775 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
776 nsIInterfaceRequestor *aNotificationCallbacks)
778 nsChannel *This = impl_from_nsIHttpChannel(iface);
780 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
782 if(This->notif_callback)
783 nsIInterfaceRequestor_Release(This->notif_callback);
784 if(aNotificationCallbacks)
785 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
787 This->notif_callback = aNotificationCallbacks;
789 return NS_OK;
792 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
794 nsChannel *This = impl_from_nsIHttpChannel(iface);
796 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
798 return NS_ERROR_NOT_IMPLEMENTED;
801 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
803 nsChannel *This = impl_from_nsIHttpChannel(iface);
805 TRACE("(%p)->(%p)\n", This, aContentType);
807 if(This->content_type) {
808 nsACString_SetData(aContentType, This->content_type);
809 return S_OK;
812 if(This->uri->is_doc_uri) {
813 WARN("Document channel with no MIME set. Assuming text/html\n");
814 nsACString_SetData(aContentType, "text/html");
815 return S_OK;
818 WARN("unknown type\n");
819 return NS_ERROR_FAILURE;
822 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
823 const nsACString *aContentType)
825 nsChannel *This = impl_from_nsIHttpChannel(iface);
826 const char *content_type;
828 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
830 nsACString_GetData(aContentType, &content_type);
831 heap_free(This->content_type);
832 This->content_type = heap_strdupA(content_type);
834 return NS_OK;
837 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
838 nsACString *aContentCharset)
840 nsChannel *This = impl_from_nsIHttpChannel(iface);
842 TRACE("(%p)->(%p)\n", This, aContentCharset);
844 if(This->charset) {
845 nsACString_SetData(aContentCharset, This->charset);
846 return NS_OK;
849 nsACString_SetData(aContentCharset, "");
850 return NS_OK;
853 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
854 const nsACString *aContentCharset)
856 nsChannel *This = impl_from_nsIHttpChannel(iface);
857 const char *data;
858 char *charset;
860 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
862 nsACString_GetData(aContentCharset, &data);
863 charset = heap_strdupA(data);
864 if(!charset)
865 return NS_ERROR_OUT_OF_MEMORY;
867 heap_free(This->charset);
868 This->charset = charset;
869 return NS_OK;
872 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, INT64 *aContentLength)
874 nsChannel *This = impl_from_nsIHttpChannel(iface);
876 FIXME("(%p)->(%p)\n", This, aContentLength);
878 return NS_ERROR_NOT_IMPLEMENTED;
881 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, INT64 aContentLength)
883 nsChannel *This = impl_from_nsIHttpChannel(iface);
885 FIXME("(%p)->(%s)\n", This, wine_dbgstr_longlong(aContentLength));
887 return NS_ERROR_NOT_IMPLEMENTED;
890 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
892 nsChannel *This = impl_from_nsIHttpChannel(iface);
894 FIXME("(%p)->(%p)\n", This, _retval);
896 return NS_ERROR_NOT_IMPLEMENTED;
899 static nsresult NSAPI nsChannel_Open2(nsIHttpChannel *iface, nsIInputStream **_retval)
901 nsChannel *This = impl_from_nsIHttpChannel(iface);
903 FIXME("(%p)->(%p)\n", This, _retval);
905 return NS_ERROR_NOT_IMPLEMENTED;
908 static HTMLOuterWindow *get_window_from_load_group(nsChannel *This)
910 HTMLOuterWindow *window;
911 nsIChannel *channel;
912 nsIRequest *req;
913 nsWineURI *wine_uri;
914 nsIURI *uri;
915 nsresult nsres;
917 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
918 if(NS_FAILED(nsres)) {
919 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
920 return NULL;
923 if(!req)
924 return NULL;
926 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
927 nsIRequest_Release(req);
928 if(NS_FAILED(nsres)) {
929 WARN("Could not get nsIChannel interface: %08x\n", nsres);
930 return NULL;
933 nsres = nsIChannel_GetURI(channel, &uri);
934 nsIChannel_Release(channel);
935 if(NS_FAILED(nsres)) {
936 ERR("GetURI failed: %08x\n", nsres);
937 return NULL;
940 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
941 nsIURI_Release(uri);
942 if(NS_FAILED(nsres)) {
943 TRACE("Could not get nsWineURI: %08x\n", nsres);
944 return NULL;
947 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
948 if(window)
949 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
950 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
952 return window;
955 static HTMLOuterWindow *get_channel_window(nsChannel *This)
957 nsIWebProgress *web_progress;
958 mozIDOMWindowProxy *mozwindow;
959 HTMLOuterWindow *window;
960 nsresult nsres;
962 if(This->load_group) {
963 nsIRequestObserver *req_observer;
965 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
966 if(NS_FAILED(nsres) || !req_observer) {
967 ERR("GetGroupObserver failed: %08x\n", nsres);
968 return NULL;
971 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
972 nsIRequestObserver_Release(req_observer);
973 if(NS_FAILED(nsres)) {
974 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
975 return NULL;
977 }else if(This->notif_callback) {
978 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
979 if(NS_FAILED(nsres)) {
980 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
981 return NULL;
983 }else {
984 ERR("no load group nor notif callback\n");
985 return NULL;
988 nsres = nsIWebProgress_GetDOMWindow(web_progress, &mozwindow);
989 nsIWebProgress_Release(web_progress);
990 if(NS_FAILED(nsres) || !mozwindow) {
991 ERR("GetDOMWindow failed: %08x\n", nsres);
992 return NULL;
995 window = mozwindow_to_window(mozwindow);
996 mozIDOMWindowProxy_Release(mozwindow);
998 if(window)
999 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1000 else
1001 FIXME("NULL window for %p\n", mozwindow);
1002 return window;
1005 typedef struct {
1006 task_t header;
1007 HTMLInnerWindow *window;
1008 nsChannelBSC *bscallback;
1009 } start_binding_task_t;
1011 static void start_binding_proc(task_t *_task)
1013 start_binding_task_t *task = (start_binding_task_t*)_task;
1015 start_binding(task->window, (BSCallback*)task->bscallback, NULL);
1018 static void start_binding_task_destr(task_t *_task)
1020 start_binding_task_t *task = (start_binding_task_t*)_task;
1022 IBindStatusCallback_Release(&task->bscallback->bsc.IBindStatusCallback_iface);
1023 heap_free(task);
1026 static nsresult async_open(nsChannel *This, HTMLOuterWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
1027 nsISupports *context)
1029 nsChannelBSC *bscallback;
1030 IMoniker *mon = NULL;
1031 HRESULT hres;
1033 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
1034 if(FAILED(hres)) {
1035 WARN("CreateURLMoniker failed: %08x\n", hres);
1036 return NS_ERROR_UNEXPECTED;
1039 if(is_doc_channel)
1040 set_current_mon(window, mon, BINDING_NAVIGATED);
1042 hres = create_channelbsc(mon, NULL, NULL, 0, is_doc_channel, &bscallback);
1043 IMoniker_Release(mon);
1044 if(FAILED(hres))
1045 return NS_ERROR_UNEXPECTED;
1047 channelbsc_set_channel(bscallback, This, listener, context);
1049 if(is_doc_channel) {
1050 hres = create_pending_window(window, bscallback);
1051 if(SUCCEEDED(hres))
1052 async_start_doc_binding(window, window->pending_window);
1053 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1054 if(FAILED(hres))
1055 return NS_ERROR_UNEXPECTED;
1056 }else {
1057 start_binding_task_t *task;
1059 task = heap_alloc(sizeof(start_binding_task_t));
1060 if(!task) {
1061 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1062 return NS_ERROR_OUT_OF_MEMORY;
1065 task->window = window->base.inner_window;
1066 task->bscallback = bscallback;
1067 hres = push_task(&task->header, start_binding_proc, start_binding_task_destr, window->base.inner_window->task_magic);
1068 if(FAILED(hres))
1069 return NS_ERROR_OUT_OF_MEMORY;
1072 return NS_OK;
1075 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
1076 nsISupports *aContext)
1078 nsChannel *This = impl_from_nsIHttpChannel(iface);
1079 HTMLOuterWindow *window = NULL;
1080 BOOL cancel = FALSE;
1081 nsresult nsres = NS_OK;
1083 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
1085 if(!ensure_uri(This->uri))
1086 return NS_ERROR_FAILURE;
1088 if(TRACE_ON(mshtml)) {
1089 HRESULT hres;
1090 BSTR uri_str;
1092 hres = IUri_GetDisplayUri(This->uri->uri, &uri_str);
1093 if(SUCCEEDED(hres)) {
1094 TRACE("opening %s\n", debugstr_w(uri_str));
1095 SysFreeString(uri_str);
1096 }else {
1097 WARN("GetDisplayUri failed: %08x\n", hres);
1101 if(This->uri->is_doc_uri) {
1102 window = get_channel_window(This);
1103 if(window) {
1104 set_uri_window(This->uri, window);
1105 }else if(This->uri->container) {
1106 BOOL b;
1108 /* nscontainer->doc should be NULL which means navigation to a new window */
1109 if(This->uri->container->doc)
1110 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
1112 nsres = before_async_open(This, This->uri->container, &b);
1113 if(NS_FAILED(nsres))
1114 return nsres;
1115 if(b)
1116 FIXME("Navigation not cancelled\n");
1117 return NS_ERROR_UNEXPECTED;
1121 if(!window) {
1122 if(This->uri->window_ref && This->uri->window_ref->window) {
1123 window = This->uri->window_ref->window;
1124 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1125 }else {
1126 /* FIXME: Analyze removing get_window_from_load_group call */
1127 if(This->load_group)
1128 window = get_window_from_load_group(This);
1129 if(!window)
1130 window = get_channel_window(This);
1131 if(window)
1132 set_uri_window(This->uri, window);
1136 if(!window) {
1137 ERR("window = NULL\n");
1138 return NS_ERROR_UNEXPECTED;
1141 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1142 if(This->uri->channel_bsc) {
1143 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1145 if(window->doc_obj->mime) {
1146 heap_free(This->content_type);
1147 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1150 cancel = TRUE;
1151 }else {
1152 nsres = before_async_open(This, window->doc_obj->nscontainer, &cancel);
1153 if(NS_SUCCEEDED(nsres) && cancel) {
1154 TRACE("canceled\n");
1155 nsres = NS_BINDING_ABORTED;
1160 if(!cancel)
1161 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1163 if(NS_SUCCEEDED(nsres) && This->load_group) {
1164 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1165 aContext);
1166 if(NS_FAILED(nsres))
1167 ERR("AddRequest failed: %08x\n", nsres);
1170 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
1171 return nsres;
1174 static nsresult NSAPI nsChannel_AsyncOpen2(nsIHttpChannel *iface, nsIStreamListener *aListener)
1176 nsChannel *This = impl_from_nsIHttpChannel(iface);
1177 FIXME("(%p)->(%p)\n", This, aListener);
1178 return nsIHttpChannel_AsyncOpen(&This->nsIHttpChannel_iface, aListener, NULL);
1181 static nsresult NSAPI nsChannel_GetContentDisposition(nsIHttpChannel *iface, UINT32 *aContentDisposition)
1183 nsChannel *This = impl_from_nsIHttpChannel(iface);
1184 FIXME("(%p)->(%p)\n", This, aContentDisposition);
1185 return NS_ERROR_NOT_IMPLEMENTED;
1188 static nsresult NSAPI nsChannel_SetContentDisposition(nsIHttpChannel *iface, UINT32 aContentDisposition)
1190 nsChannel *This = impl_from_nsIHttpChannel(iface);
1191 FIXME("(%p)->(%u)\n", This, aContentDisposition);
1192 return NS_ERROR_NOT_IMPLEMENTED;
1195 static nsresult NSAPI nsChannel_GetContentDispositionFilename(nsIHttpChannel *iface, nsAString *aContentDispositionFilename)
1197 nsChannel *This = impl_from_nsIHttpChannel(iface);
1198 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1199 return NS_ERROR_NOT_IMPLEMENTED;
1202 static nsresult NSAPI nsChannel_SetContentDispositionFilename(nsIHttpChannel *iface, const nsAString *aContentDispositionFilename)
1204 nsChannel *This = impl_from_nsIHttpChannel(iface);
1205 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1206 return NS_ERROR_NOT_IMPLEMENTED;
1209 static nsresult NSAPI nsChannel_GetContentDispositionHeader(nsIHttpChannel *iface, nsACString *aContentDispositionHeader)
1211 nsChannel *This = impl_from_nsIHttpChannel(iface);
1212 FIXME("(%p)->(%p)\n", This, aContentDispositionHeader);
1213 return NS_ERROR_NOT_IMPLEMENTED;
1216 static nsresult NSAPI nsChannel_GetLoadInfo(nsIHttpChannel *iface, nsILoadInfo **aLoadInfo)
1218 nsChannel *This = impl_from_nsIHttpChannel(iface);
1220 TRACE("(%p)->(%p)\n", This, aLoadInfo);
1222 if(This->load_info)
1223 nsISupports_AddRef(This->load_info);
1224 *aLoadInfo = This->load_info;
1225 return NS_OK;
1228 static nsresult NSAPI nsChannel_SetLoadInfo(nsIHttpChannel *iface, nsILoadInfo *aLoadInfo)
1230 nsChannel *This = impl_from_nsIHttpChannel(iface);
1232 TRACE("(%p)->(%p)\n", This, aLoadInfo);
1234 if(This->load_info)
1235 nsISupports_Release(This->load_info);
1236 This->load_info = aLoadInfo;
1237 if(This->load_info)
1238 nsISupports_AddRef(This->load_info);
1239 return NS_OK;
1242 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1244 nsChannel *This = impl_from_nsIHttpChannel(iface);
1246 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1248 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1249 return NS_OK;
1252 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1253 const nsACString *aRequestMethod)
1255 nsChannel *This = impl_from_nsIHttpChannel(iface);
1256 const char *method;
1257 unsigned i;
1259 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1261 nsACString_GetData(aRequestMethod, &method);
1262 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1263 if(!strcasecmp(method, request_method_strings[i])) {
1264 This->request_method = i;
1265 return NS_OK;
1269 ERR("Invalid method %s\n", debugstr_a(method));
1270 return NS_ERROR_UNEXPECTED;
1273 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1275 nsChannel *This = impl_from_nsIHttpChannel(iface);
1277 TRACE("(%p)->(%p)\n", This, aReferrer);
1279 if(This->referrer)
1280 nsIURI_AddRef(This->referrer);
1281 *aReferrer = This->referrer;
1282 return NS_OK;
1285 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1287 nsChannel *This = impl_from_nsIHttpChannel(iface);
1289 TRACE("(%p)->(%p)\n", This, aReferrer);
1291 return nsIHttpChannel_SetReferrerWithPolicy(&This->nsIHttpChannel_iface, aReferrer, 0);
1294 static nsresult NSAPI nsChannel_GetReferrerPolicy(nsIHttpChannel *iface, UINT32 *aReferrerPolicy)
1296 nsChannel *This = impl_from_nsIHttpChannel(iface);
1297 FIXME("(%p)->(%p)\n", This, aReferrerPolicy);
1298 return NS_ERROR_NOT_IMPLEMENTED;
1301 static nsresult NSAPI nsChannel_SetReferrerWithPolicy(nsIHttpChannel *iface, nsIURI *aReferrer, UINT32 aReferrerPolicy)
1303 nsChannel *This = impl_from_nsIHttpChannel(iface);
1304 DWORD channel_scheme, referrer_scheme;
1305 nsWineURI *referrer;
1306 BSTR referrer_uri;
1307 nsresult nsres;
1308 HRESULT hres;
1310 static const WCHAR refererW[] = {'R','e','f','e','r','e','r'};
1312 TRACE("(%p)->(%p %d)\n", This, aReferrer, aReferrerPolicy);
1314 if(aReferrerPolicy)
1315 FIXME("refferer policy %d not implemented\n", aReferrerPolicy);
1317 if(This->referrer) {
1318 nsIURI_Release(This->referrer);
1319 This->referrer = NULL;
1321 if(!aReferrer)
1322 return NS_OK;
1324 nsres = nsIURI_QueryInterface(aReferrer, &IID_nsWineURI, (void**)&referrer);
1325 if(NS_FAILED(nsres))
1326 return NS_OK;
1328 if(!ensure_uri(referrer)) {
1329 nsIFileURL_Release(&referrer->nsIFileURL_iface);
1330 return NS_ERROR_UNEXPECTED;
1333 if(!ensure_uri(This->uri) || FAILED(IUri_GetScheme(This->uri->uri, &channel_scheme)))
1334 channel_scheme = INTERNET_SCHEME_UNKNOWN;
1336 if(FAILED(IUri_GetScheme(referrer->uri, &referrer_scheme)))
1337 referrer_scheme = INTERNET_SCHEME_UNKNOWN;
1339 if(referrer_scheme == INTERNET_SCHEME_HTTPS && channel_scheme != INTERNET_SCHEME_HTTPS) {
1340 TRACE("Ignoring https referrer on non-https channel\n");
1341 nsIFileURL_Release(&referrer->nsIFileURL_iface);
1342 return NS_OK;
1345 hres = IUri_GetDisplayUri(referrer->uri, &referrer_uri);
1346 if(SUCCEEDED(hres)) {
1347 set_http_header(&This->request_headers, refererW, sizeof(refererW)/sizeof(WCHAR), referrer_uri, SysStringLen(referrer_uri));
1348 SysFreeString(referrer_uri);
1351 This->referrer = (nsIURI*)&referrer->nsIFileURL_iface;
1352 return NS_OK;
1355 static nsresult NSAPI nsHttpChannel_GetProtocolVersion(nsIHttpChannel *iface, nsACString *aProtocolVersion)
1357 nsChannel *This = impl_from_nsIHttpChannel(iface);
1358 FIXME("(%p)->(%p)\n", This, aProtocolVersion);
1359 return NS_ERROR_NOT_IMPLEMENTED;
1362 static nsresult NSAPI nsHttpChannel_GetTransferSize(nsIHttpChannel *iface, UINT64 *aTransferSize)
1364 nsChannel *This = impl_from_nsIHttpChannel(iface);
1365 FIXME("(%p)->(%p)\n", This, aTransferSize);
1366 return NS_ERROR_NOT_IMPLEMENTED;
1369 static nsresult NSAPI nsHttpChannel_GetDecodedBodySize(nsIHttpChannel *iface, UINT64 *aDecodedBodySize)
1371 nsChannel *This = impl_from_nsIHttpChannel(iface);
1372 FIXME("(%p)->(%p)\n", This, aDecodedBodySize);
1373 return NS_ERROR_NOT_IMPLEMENTED;
1376 static nsresult NSAPI nsHttpChannel_GetEncodedBodySize(nsIHttpChannel *iface, UINT64 *aEncodedBodySize)
1378 nsChannel *This = impl_from_nsIHttpChannel(iface);
1379 FIXME("(%p)->(%p)\n", This, aEncodedBodySize);
1380 return NS_ERROR_NOT_IMPLEMENTED;
1383 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1384 const nsACString *aHeader, nsACString *_retval)
1386 nsChannel *This = impl_from_nsIHttpChannel(iface);
1388 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1390 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1393 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1394 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1396 nsChannel *This = impl_from_nsIHttpChannel(iface);
1398 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1400 if(aMerge)
1401 FIXME("aMerge not supported\n");
1403 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1406 static nsresult NSAPI nsChannel_SetEmptyRequestHeader(nsIHttpChannel *iface, const nsACString *aHeader)
1408 nsChannel *This = impl_from_nsIHttpChannel(iface);
1409 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aHeader));
1410 return NS_ERROR_NOT_IMPLEMENTED;
1413 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1414 nsIHttpHeaderVisitor *aVisitor)
1416 nsChannel *This = impl_from_nsIHttpChannel(iface);
1418 FIXME("(%p)->(%p)\n", This, aVisitor);
1420 return NS_ERROR_NOT_IMPLEMENTED;
1423 static nsresult NSAPI nsChannel_VisitNonDefaultRequestHeaders(nsIHttpChannel *iface, nsIHttpHeaderVisitor *aVisitor)
1425 nsChannel *This = impl_from_nsIHttpChannel(iface);
1426 FIXME("(%p)->(%p)\n", This, aVisitor);
1427 return NS_ERROR_NOT_IMPLEMENTED;
1430 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1432 nsChannel *This = impl_from_nsIHttpChannel(iface);
1434 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1436 return NS_ERROR_NOT_IMPLEMENTED;
1439 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1441 nsChannel *This = impl_from_nsIHttpChannel(iface);
1443 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1445 return NS_ERROR_NOT_IMPLEMENTED;
1448 static nsresult NSAPI nsChannel_GetAllowTLS(nsIHttpChannel *iface, cpp_bool *aAllowTLS)
1450 nsChannel *This = impl_from_nsIHttpChannel(iface);
1451 FIXME("(%p)->(%p)\n", This, aAllowTLS);
1452 return NS_ERROR_NOT_IMPLEMENTED;
1455 static nsresult NSAPI nsChannel_SetAllowTLS(nsIHttpChannel *iface, cpp_bool aAllowTLS)
1457 nsChannel *This = impl_from_nsIHttpChannel(iface);
1458 FIXME("(%p)->(%x)\n", This, aAllowTLS);
1459 return NS_ERROR_NOT_IMPLEMENTED;
1462 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, UINT32 *aRedirectionLimit)
1464 nsChannel *This = impl_from_nsIHttpChannel(iface);
1466 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1468 return NS_ERROR_NOT_IMPLEMENTED;
1471 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, UINT32 aRedirectionLimit)
1473 nsChannel *This = impl_from_nsIHttpChannel(iface);
1475 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1477 return NS_ERROR_NOT_IMPLEMENTED;
1480 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, UINT32 *aResponseStatus)
1482 nsChannel *This = impl_from_nsIHttpChannel(iface);
1484 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1486 if(This->response_status) {
1487 *aResponseStatus = This->response_status;
1488 return NS_OK;
1491 WARN("No response status\n");
1492 return NS_ERROR_UNEXPECTED;
1495 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1496 nsACString *aResponseStatusText)
1498 nsChannel *This = impl_from_nsIHttpChannel(iface);
1500 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
1502 nsACString_SetData(aResponseStatusText, This->response_status_text);
1503 return NS_OK;
1506 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1507 cpp_bool *aRequestSucceeded)
1509 nsChannel *This = impl_from_nsIHttpChannel(iface);
1511 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1513 if(!This->response_status)
1514 return NS_ERROR_NOT_AVAILABLE;
1516 *aRequestSucceeded = This->response_status/100 == 2;
1518 return NS_OK;
1521 static nsresult NSAPI nsChannel_GetIsMainDocumentChannel(nsIHttpChannel *iface, cpp_bool *aIsMainDocumentChannel)
1523 nsChannel *This = impl_from_nsIHttpChannel(iface);
1524 FIXME("(%p)->(%p)\n", This, aIsMainDocumentChannel);
1525 return NS_ERROR_NOT_IMPLEMENTED;
1528 static nsresult NSAPI nsChannel_SetIsMainDocumentChannel(nsIHttpChannel *iface, cpp_bool aIsMainDocumentChannel)
1530 nsChannel *This = impl_from_nsIHttpChannel(iface);
1531 FIXME("(%p)->(%x)\n", This, aIsMainDocumentChannel);
1532 return NS_ERROR_NOT_IMPLEMENTED;
1535 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1536 const nsACString *header, nsACString *_retval)
1538 nsChannel *This = impl_from_nsIHttpChannel(iface);
1540 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1542 return get_channel_http_header(&This->response_headers, header, _retval);
1545 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1546 const nsACString *header, const nsACString *value, cpp_bool merge)
1548 nsChannel *This = impl_from_nsIHttpChannel(iface);
1550 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1552 return NS_ERROR_NOT_IMPLEMENTED;
1555 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1556 nsIHttpHeaderVisitor *aVisitor)
1558 nsChannel *This = impl_from_nsIHttpChannel(iface);
1560 TRACE("(%p)->(%p)\n", This, aVisitor);
1562 return visit_http_headers(&This->response_headers, aVisitor);
1565 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1567 nsChannel *This = impl_from_nsIHttpChannel(iface);
1568 http_header_t *header;
1570 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1571 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1573 TRACE("(%p)->(%p)\n", This, _retval);
1575 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1576 *_retval = header && !strcmpiW(header->data, no_storeW);
1577 return NS_OK;
1580 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1582 nsChannel *This = impl_from_nsIHttpChannel(iface);
1584 FIXME("(%p)->(%p)\n", This, _retval);
1586 return NS_ERROR_NOT_IMPLEMENTED;
1589 static nsresult NSAPI nsChannel_IsPrivateResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1591 nsChannel *This = impl_from_nsIHttpChannel(iface);
1593 FIXME("(%p)->(%p)\n", This, _retval);
1595 return NS_ERROR_NOT_IMPLEMENTED;
1598 static nsresult NSAPI nsChannel_RedirectTo(nsIHttpChannel *iface, nsIURI *aTargetURI)
1600 nsChannel *This = impl_from_nsIHttpChannel(iface);
1602 FIXME("(%p)->(%p)\n", This, aTargetURI);
1604 return NS_ERROR_NOT_IMPLEMENTED;
1607 static nsresult NSAPI nsHttpChannel_GetSchedulingContextID(nsIHttpChannel *iface, nsIID *aSchedulingContextID)
1609 nsChannel *This = impl_from_nsIHttpChannel(iface);
1611 FIXME("(%p)->(%p)\n", This, aSchedulingContextID);
1613 return NS_ERROR_NOT_IMPLEMENTED;
1616 static nsresult NSAPI nsHttpChannel_SetSchedulingContextID(nsIHttpChannel *iface, const nsIID aSchedulingContextID)
1618 nsChannel *This = impl_from_nsIHttpChannel(iface);
1620 FIXME("(%p)->(%s)\n", This, debugstr_guid(&aSchedulingContextID));
1622 return NS_ERROR_NOT_IMPLEMENTED;
1625 static const nsIHttpChannelVtbl nsChannelVtbl = {
1626 nsChannel_QueryInterface,
1627 nsChannel_AddRef,
1628 nsChannel_Release,
1629 nsChannel_GetName,
1630 nsChannel_IsPending,
1631 nsChannel_GetStatus,
1632 nsChannel_Cancel,
1633 nsChannel_Suspend,
1634 nsChannel_Resume,
1635 nsChannel_GetLoadGroup,
1636 nsChannel_SetLoadGroup,
1637 nsChannel_GetLoadFlags,
1638 nsChannel_SetLoadFlags,
1639 nsChannel_GetOriginalURI,
1640 nsChannel_SetOriginalURI,
1641 nsChannel_GetURI,
1642 nsChannel_GetOwner,
1643 nsChannel_SetOwner,
1644 nsChannel_GetNotificationCallbacks,
1645 nsChannel_SetNotificationCallbacks,
1646 nsChannel_GetSecurityInfo,
1647 nsChannel_GetContentType,
1648 nsChannel_SetContentType,
1649 nsChannel_GetContentCharset,
1650 nsChannel_SetContentCharset,
1651 nsChannel_GetContentLength,
1652 nsChannel_SetContentLength,
1653 nsChannel_Open,
1654 nsChannel_Open2,
1655 nsChannel_AsyncOpen,
1656 nsChannel_AsyncOpen2,
1657 nsChannel_GetContentDisposition,
1658 nsChannel_SetContentDisposition,
1659 nsChannel_GetContentDispositionFilename,
1660 nsChannel_SetContentDispositionFilename,
1661 nsChannel_GetContentDispositionHeader,
1662 nsChannel_GetLoadInfo,
1663 nsChannel_SetLoadInfo,
1664 nsChannel_GetRequestMethod,
1665 nsChannel_SetRequestMethod,
1666 nsChannel_GetReferrer,
1667 nsChannel_SetReferrer,
1668 nsChannel_GetReferrerPolicy,
1669 nsChannel_SetReferrerWithPolicy,
1670 nsHttpChannel_GetProtocolVersion,
1671 nsHttpChannel_GetTransferSize,
1672 nsHttpChannel_GetDecodedBodySize,
1673 nsHttpChannel_GetEncodedBodySize,
1674 nsChannel_GetRequestHeader,
1675 nsChannel_SetRequestHeader,
1676 nsChannel_SetEmptyRequestHeader,
1677 nsChannel_VisitRequestHeaders,
1678 nsChannel_VisitNonDefaultRequestHeaders,
1679 nsChannel_GetAllowPipelining,
1680 nsChannel_SetAllowPipelining,
1681 nsChannel_GetAllowTLS,
1682 nsChannel_SetAllowTLS,
1683 nsChannel_GetRedirectionLimit,
1684 nsChannel_SetRedirectionLimit,
1685 nsChannel_GetResponseStatus,
1686 nsChannel_GetResponseStatusText,
1687 nsChannel_GetRequestSucceeded,
1688 nsChannel_GetIsMainDocumentChannel,
1689 nsChannel_SetIsMainDocumentChannel,
1690 nsChannel_GetResponseHeader,
1691 nsChannel_SetResponseHeader,
1692 nsChannel_VisitResponseHeaders,
1693 nsChannel_IsNoStoreResponse,
1694 nsChannel_IsNoCacheResponse,
1695 nsChannel_IsPrivateResponse,
1696 nsChannel_RedirectTo,
1697 nsHttpChannel_GetSchedulingContextID,
1698 nsHttpChannel_SetSchedulingContextID
1701 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1703 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1706 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1707 void **result)
1709 nsChannel *This = impl_from_nsIUploadChannel(iface);
1710 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1713 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1715 nsChannel *This = impl_from_nsIUploadChannel(iface);
1716 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1719 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1721 nsChannel *This = impl_from_nsIUploadChannel(iface);
1722 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1725 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1726 nsIInputStream *aStream, const nsACString *aContentType, INT64 aContentLength)
1728 nsChannel *This = impl_from_nsIUploadChannel(iface);
1729 const char *content_type;
1731 static const WCHAR content_typeW[] =
1732 {'C','o','n','t','e','n','t','-','T','y','p','e'};
1734 TRACE("(%p)->(%p %s %s)\n", This, aStream, debugstr_nsacstr(aContentType), wine_dbgstr_longlong(aContentLength));
1736 This->post_data_contains_headers = TRUE;
1738 if(aContentType) {
1739 nsACString_GetData(aContentType, &content_type);
1740 if(*content_type) {
1741 WCHAR *ct;
1743 ct = heap_strdupAtoW(content_type);
1744 if(!ct)
1745 return NS_ERROR_UNEXPECTED;
1747 set_http_header(&This->request_headers, content_typeW,
1748 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1749 heap_free(ct);
1750 This->post_data_contains_headers = FALSE;
1754 if(aContentLength != -1)
1755 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength));
1757 if(This->post_data_stream)
1758 nsIInputStream_Release(This->post_data_stream);
1759 This->post_data_stream = aStream;
1760 if(aStream)
1761 nsIInputStream_AddRef(aStream);
1763 This->request_method = METHOD_POST;
1764 return NS_OK;
1767 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1768 nsIInputStream **aUploadStream)
1770 nsChannel *This = impl_from_nsIUploadChannel(iface);
1772 TRACE("(%p)->(%p)\n", This, aUploadStream);
1774 if(This->post_data_stream)
1775 nsIInputStream_AddRef(This->post_data_stream);
1777 *aUploadStream = This->post_data_stream;
1778 return NS_OK;
1781 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1782 nsUploadChannel_QueryInterface,
1783 nsUploadChannel_AddRef,
1784 nsUploadChannel_Release,
1785 nsUploadChannel_SetUploadStream,
1786 nsUploadChannel_GetUploadStream
1789 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1791 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1794 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1795 void **result)
1797 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1798 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1801 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1803 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1804 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1807 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1809 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1810 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1813 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1815 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1817 FIXME("(%p)->()\n", This);
1819 return NS_ERROR_NOT_IMPLEMENTED;
1822 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1824 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1826 FIXME("(%p)->()\n", This);
1828 return NS_ERROR_NOT_IMPLEMENTED;
1831 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1833 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1835 FIXME("(%p)->()\n", This);
1837 return NS_ERROR_NOT_IMPLEMENTED;
1840 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1842 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1844 FIXME("(%p)->()\n", This);
1846 return NS_ERROR_NOT_IMPLEMENTED;
1849 static nsresult NSAPI nsHttpChannelInternal_TakeAllSecurityMessages(nsIHttpChannelInternal *iface, void *aMessages)
1851 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1853 FIXME("(%p)->()\n", This);
1855 return NS_ERROR_NOT_IMPLEMENTED;
1858 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1860 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1862 FIXME("(%p)->()\n", This);
1864 return NS_ERROR_NOT_IMPLEMENTED;
1867 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1869 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1871 FIXME("(%p)->()\n", This);
1873 return NS_ERROR_NOT_IMPLEMENTED;
1876 static nsresult NSAPI nsHttpChannelInternal_GetThirdPartyFlags(nsIHttpChannelInternal *iface, UINT32 *aThirdPartyFlags)
1878 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1879 FIXME("(%p)->(%p)\n", This, aThirdPartyFlags);
1880 return NS_ERROR_NOT_IMPLEMENTED;
1883 static nsresult NSAPI nsHttpChannelInternal_SetThirdPartyFlags(nsIHttpChannelInternal *iface, UINT32 aThirdPartyFlags)
1885 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1886 FIXME("(%p)->(%x)\n", This, aThirdPartyFlags);
1887 return NS_ERROR_NOT_IMPLEMENTED;
1890 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1892 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1894 FIXME("(%p)->()\n", This);
1896 return NS_ERROR_NOT_IMPLEMENTED;
1899 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1901 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1903 FIXME("(%p)->()\n", This);
1905 return NS_ERROR_NOT_IMPLEMENTED;
1908 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1910 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1912 FIXME("(%p)->(%p)\n", This, aCanceled);
1914 return NS_ERROR_NOT_IMPLEMENTED;
1917 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1919 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1921 FIXME("(%p)->(%p)\n", This, aCanceled);
1923 return NS_ERROR_NOT_IMPLEMENTED;
1926 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1928 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1930 FIXME("(%p)->(%x)\n", This, aCanceled);
1932 return NS_ERROR_NOT_IMPLEMENTED;
1935 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1937 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1939 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1941 return NS_ERROR_NOT_IMPLEMENTED;
1944 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, LONG *aLocalPort)
1946 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1948 FIXME("(%p)->(%p)\n", This, aLocalPort);
1950 return NS_ERROR_NOT_IMPLEMENTED;
1953 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1955 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1957 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1959 return NS_ERROR_NOT_IMPLEMENTED;
1962 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, LONG *aRemotePort)
1964 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1966 FIXME("(%p)->(%p)\n", This, aRemotePort);
1968 return NS_ERROR_NOT_IMPLEMENTED;
1971 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1973 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1975 FIXME("(%p)->(%p)\n", This, cacheKeys);
1977 return NS_ERROR_NOT_IMPLEMENTED;
1980 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1981 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1983 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1984 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1985 return NS_ERROR_NOT_IMPLEMENTED;
1988 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1990 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1991 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1992 return NS_ERROR_NOT_IMPLEMENTED;
1995 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1997 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1998 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1999 return NS_ERROR_NOT_IMPLEMENTED;
2002 static nsresult NSAPI nsHttpChannelInternal_GetResponseTimeoutEnabled(nsIHttpChannelInternal *iface,
2003 cpp_bool *aResponseTimeoutEnabled)
2005 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2006 FIXME("(%p)->(%p)\n", This, aResponseTimeoutEnabled);
2007 return NS_ERROR_NOT_IMPLEMENTED;
2010 static nsresult NSAPI nsHttpChannelInternal_SetResponseTimeoutEnabled(nsIHttpChannelInternal *iface,
2011 cpp_bool aResponseTimeoutEnabled)
2013 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2014 FIXME("(%p)->(%x)\n", This, aResponseTimeoutEnabled);
2015 return NS_ERROR_NOT_IMPLEMENTED;
2018 static nsresult NSAPI nsHttpChannelInternal_GetInitialRwin(nsIHttpChannelInternal *iface,
2019 UINT32 *aInitialRwin)
2021 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2022 FIXME("(%p)->(%p)\n", This, aInitialRwin);
2023 return NS_ERROR_NOT_IMPLEMENTED;
2026 static nsresult NSAPI nsHttpChannelInternal_SetInitialRwin(nsIHttpChannelInternal *iface,
2027 UINT32 aInitialRwin)
2029 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2030 FIXME("(%p)->(%x)\n", This, aInitialRwin);
2031 return NS_ERROR_NOT_IMPLEMENTED;
2034 static nsresult NSAPI nsHttpChannelInternal_GetApiRedirectToURI(nsIHttpChannelInternal *iface, nsIURI **aApiRedirectToURI)
2036 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2037 FIXME("(%p)->(%p)\n", This, aApiRedirectToURI);
2038 return NS_ERROR_NOT_IMPLEMENTED;
2041 static nsresult NSAPI nsHttpChannelInternal_GetAllowAltSvc(nsIHttpChannelInternal *iface, cpp_bool *aAllowAltSvc)
2043 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2044 FIXME("(%p)->(%p)\n", This, aAllowAltSvc);
2045 return NS_ERROR_NOT_IMPLEMENTED;
2048 static nsresult NSAPI nsHttpChannelInternal_SetAllowAltSvc(nsIHttpChannelInternal *iface, cpp_bool aAllowAltSvc)
2050 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2051 FIXME("(%p)->(%x)\n", This, aAllowAltSvc);
2052 return NS_ERROR_NOT_IMPLEMENTED;
2055 static nsresult NSAPI nsHttpChannelInternal_GetLastModifiedTime(nsIHttpChannelInternal *iface, PRTime *aLastModifiedTime)
2057 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2058 FIXME("(%p)->(%p)\n", This, aLastModifiedTime);
2059 return NS_ERROR_NOT_IMPLEMENTED;
2062 static nsresult NSAPI nsHttpChannelInternal_ForceIntercepted(nsIHttpChannelInternal *iface, UINT64 aInterceptionID)
2064 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2065 FIXME("(%p)->(%s)\n", This, wine_dbgstr_longlong(aInterceptionID));
2066 return NS_ERROR_NOT_IMPLEMENTED;
2069 static nsresult NSAPI nsHttpChannelInternal_GetResponseSynthesized(nsIHttpChannelInternal *iface, cpp_bool *ResponseSynthesized)
2071 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2072 FIXME("(%p, %p)\n", This, ResponseSynthesized);
2073 return NS_ERROR_NOT_IMPLEMENTED;
2076 static nsresult NSAPI nsHttpChannelInternal_GetCorsIncludeCredentials(nsIHttpChannelInternal *iface,
2077 cpp_bool *aCorsIncludeCredentials)
2079 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2080 FIXME("(%p)->(%p)\n", This, aCorsIncludeCredentials);
2081 return NS_ERROR_NOT_IMPLEMENTED;
2084 static nsresult NSAPI nsHttpChannelInternal_SetCorsIncludeCredentials(nsIHttpChannelInternal *iface,
2085 cpp_bool aCorsIncludeCredentials)
2087 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2088 TRACE("(%p)->(%x)\n", This, aCorsIncludeCredentials);
2089 return NS_OK;
2092 static nsresult NSAPI nsHttpChannelInternal_GetCorsMode(nsIHttpChannelInternal *iface, UINT32 *aCorsMode)
2094 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2095 FIXME("(%p)->(%p)\n", This, aCorsMode);
2096 return NS_ERROR_NOT_IMPLEMENTED;
2099 static nsresult NSAPI nsHttpChannelInternal_SetCorsMode(nsIHttpChannelInternal *iface, UINT32 aCorsMode)
2101 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2102 TRACE("(%p)->(%d)\n", This, aCorsMode);
2103 return NS_OK;
2106 static nsresult NSAPI nsHttpChannelInternal_GetRedirectMode(nsIHttpChannelInternal *iface, UINT32 *aRedirectMode)
2108 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2109 FIXME("(%p)->(%p)\n", This, aRedirectMode);
2110 return NS_ERROR_NOT_IMPLEMENTED;
2113 static nsresult NSAPI nsHttpChannelInternal_SetRedirectMode(nsIHttpChannelInternal *iface, UINT32 aRedirectMode)
2115 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2116 FIXME("(%p)->(%d)\n", This, aRedirectMode);
2117 return NS_ERROR_NOT_IMPLEMENTED;
2120 static nsresult NSAPI nsHttpChannelInternal_GetTopWindowURI(nsIHttpChannelInternal *iface, nsIURI **aTopWindowURI)
2122 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2123 FIXME("(%p)->(%p)\n", This, aTopWindowURI);
2124 return NS_ERROR_NOT_IMPLEMENTED;
2127 static nsresult NSAPI nsHttpChannelInternal_GetNetworkInterfaceId(nsIHttpChannelInternal *iface,
2128 nsACString *aNetworkInterfaceId)
2130 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2131 FIXME("(%p)->(%p)\n", This, aNetworkInterfaceId);
2132 return NS_ERROR_NOT_IMPLEMENTED;
2135 static nsresult NSAPI nsHttpChannelInternal_SetNetworkInterfaceId(nsIHttpChannelInternal *iface,
2136 const nsACString *aNetworkInterfaceId)
2138 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2139 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aNetworkInterfaceId));
2140 return NS_ERROR_NOT_IMPLEMENTED;
2143 static nsresult NSAPI nsHttpChannelInternal_GetProxyURI(nsIHttpChannelInternal *iface, nsIURI **aProxyURI)
2145 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2146 FIXME("(%p)->(%p)\n", This, aProxyURI);
2147 return NS_ERROR_NOT_IMPLEMENTED;
2150 static nsresult NSAPI nsHttpChannelInternal_SetCorsPreflightParameters(nsIHttpChannelInternal *iface,
2151 const void /*nsTArray<nsCString>*/ *unsafeHeaders)
2153 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2154 FIXME("(%p)->(%p)\n", This, unsafeHeaders);
2155 return NS_ERROR_NOT_IMPLEMENTED;
2158 static nsresult NSAPI nsHttpChannelInternal_GetBlockAuthPrompt(nsIHttpChannelInternal *iface, cpp_bool *aBlockAuthPrompt)
2160 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2161 FIXME("(%p)->(%p)\n", This, aBlockAuthPrompt);
2162 return NS_ERROR_NOT_IMPLEMENTED;
2165 static nsresult NSAPI nsHttpChannelInternal_SetBlockAuthPrompt(nsIHttpChannelInternal *iface, cpp_bool aBlockAuthPrompt)
2167 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2168 FIXME("(%p)->(%x)\n", This, aBlockAuthPrompt);
2169 return NS_ERROR_NOT_IMPLEMENTED;
2172 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
2173 nsHttpChannelInternal_QueryInterface,
2174 nsHttpChannelInternal_AddRef,
2175 nsHttpChannelInternal_Release,
2176 nsHttpChannelInternal_GetDocumentURI,
2177 nsHttpChannelInternal_SetDocumentURI,
2178 nsHttpChannelInternal_GetRequestVersion,
2179 nsHttpChannelInternal_GetResponseVersion,
2180 nsHttpChannelInternal_TakeAllSecurityMessages,
2181 nsHttpChannelInternal_SetCookie,
2182 nsHttpChannelInternal_SetupFallbackChannel,
2183 nsHttpChannelInternal_GetThirdPartyFlags,
2184 nsHttpChannelInternal_SetThirdPartyFlags,
2185 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
2186 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
2187 nsHttpChannelInternal_GetCanceled,
2188 nsHttpChannelInternal_GetChannelIsForDownload,
2189 nsHttpChannelInternal_SetChannelIsForDownload,
2190 nsHttpChannelInternal_GetLocalAddress,
2191 nsHttpChannelInternal_GetLocalPort,
2192 nsHttpChannelInternal_GetRemoteAddress,
2193 nsHttpChannelInternal_GetRemotePort,
2194 nsHttpChannelInternal_SetCacheKeysRedirectChain,
2195 nsHttpChannelInternal_HTTPUpgrade,
2196 nsHttpChannelInternal_GetAllowSpdy,
2197 nsHttpChannelInternal_SetAllowSpdy,
2198 nsHttpChannelInternal_GetResponseTimeoutEnabled,
2199 nsHttpChannelInternal_SetResponseTimeoutEnabled,
2200 nsHttpChannelInternal_GetInitialRwin,
2201 nsHttpChannelInternal_SetInitialRwin,
2202 nsHttpChannelInternal_GetApiRedirectToURI,
2203 nsHttpChannelInternal_GetAllowAltSvc,
2204 nsHttpChannelInternal_SetAllowAltSvc,
2205 nsHttpChannelInternal_GetLastModifiedTime,
2206 nsHttpChannelInternal_ForceIntercepted,
2207 nsHttpChannelInternal_GetResponseSynthesized,
2208 nsHttpChannelInternal_GetCorsIncludeCredentials,
2209 nsHttpChannelInternal_SetCorsIncludeCredentials,
2210 nsHttpChannelInternal_GetCorsMode,
2211 nsHttpChannelInternal_SetCorsMode,
2212 nsHttpChannelInternal_GetRedirectMode,
2213 nsHttpChannelInternal_SetRedirectMode,
2214 nsHttpChannelInternal_GetTopWindowURI,
2215 nsHttpChannelInternal_GetNetworkInterfaceId,
2216 nsHttpChannelInternal_SetNetworkInterfaceId,
2217 nsHttpChannelInternal_GetProxyURI,
2218 nsHttpChannelInternal_SetCorsPreflightParameters,
2219 nsHttpChannelInternal_GetBlockAuthPrompt,
2220 nsHttpChannelInternal_SetBlockAuthPrompt
2224 static void invalidate_uri(nsWineURI *This)
2226 if(This->uri) {
2227 IUri_Release(This->uri);
2228 This->uri = NULL;
2232 static BOOL ensure_uri_builder(nsWineURI *This)
2234 if(!This->is_mutable) {
2235 WARN("Not mutable URI\n");
2236 return FALSE;
2239 if(!This->uri_builder) {
2240 HRESULT hres;
2242 if(!ensure_uri(This))
2243 return FALSE;
2245 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
2246 if(FAILED(hres)) {
2247 WARN("CreateIUriBuilder failed: %08x\n", hres);
2248 return FALSE;
2252 invalidate_uri(This);
2253 return TRUE;
2256 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
2258 char *vala;
2259 BSTR val;
2260 HRESULT hres;
2262 if(!ensure_uri(This))
2263 return NS_ERROR_UNEXPECTED;
2265 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
2266 if(FAILED(hres)) {
2267 WARN("GetPropertyBSTR failed: %08x\n", hres);
2268 return NS_ERROR_UNEXPECTED;
2271 vala = heap_strdupWtoU(val);
2272 SysFreeString(val);
2273 if(!vala)
2274 return NS_ERROR_OUT_OF_MEMORY;
2276 TRACE("ret %s\n", debugstr_a(vala));
2277 nsACString_SetData(ret, vala);
2278 heap_free(vala);
2279 return NS_OK;
2282 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
2284 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
2287 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
2289 nsWineURI *This = impl_from_nsIFileURL(iface);
2291 *result = NULL;
2293 if(IsEqualGUID(&IID_nsISupports, riid)) {
2294 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2295 *result = &This->nsIFileURL_iface;
2296 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
2297 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
2298 *result = &This->nsIFileURL_iface;
2299 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
2300 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
2301 *result = &This->nsIFileURL_iface;
2302 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
2303 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
2304 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
2305 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
2306 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
2307 *result = &This->nsIStandardURL_iface;
2308 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
2309 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
2310 *result = &This->nsIStandardURL_iface;
2311 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
2312 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
2313 *result = This;
2316 if(*result) {
2317 nsIFileURL_AddRef(&This->nsIFileURL_iface);
2318 return NS_OK;
2321 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
2322 return NS_NOINTERFACE;
2325 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
2327 nsWineURI *This = impl_from_nsIFileURL(iface);
2328 LONG ref = InterlockedIncrement(&This->ref);
2330 TRACE("(%p) ref=%d\n", This, ref);
2332 return ref;
2335 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
2337 nsWineURI *This = impl_from_nsIFileURL(iface);
2338 LONG ref = InterlockedDecrement(&This->ref);
2340 TRACE("(%p) ref=%d\n", This, ref);
2342 if(!ref) {
2343 if(This->window_ref)
2344 windowref_release(This->window_ref);
2345 if(This->container)
2346 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
2347 if(This->uri)
2348 IUri_Release(This->uri);
2349 if(This->uri_builder)
2350 IUriBuilder_Release(This->uri_builder);
2351 heap_free(This->origin_charset);
2352 heap_free(This);
2355 return ref;
2358 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
2360 nsWineURI *This = impl_from_nsIFileURL(iface);
2362 TRACE("(%p)->(%p)\n", This, aSpec);
2364 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
2367 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
2369 nsWineURI *This = impl_from_nsIFileURL(iface);
2370 const char *speca;
2371 WCHAR *spec;
2372 IUri *uri;
2373 HRESULT hres;
2375 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
2377 if(!This->is_mutable)
2378 return NS_ERROR_UNEXPECTED;
2380 nsACString_GetData(aSpec, &speca);
2381 spec = heap_strdupUtoW(speca);
2382 if(!spec)
2383 return NS_ERROR_OUT_OF_MEMORY;
2385 hres = create_uri(spec, 0, &uri);
2386 heap_free(spec);
2387 if(FAILED(hres)) {
2388 WARN("create_uri failed: %08x\n", hres);
2389 return NS_ERROR_FAILURE;
2392 invalidate_uri(This);
2393 if(This->uri_builder) {
2394 IUriBuilder_Release(This->uri_builder);
2395 This->uri_builder = NULL;
2398 This->uri = uri;
2399 return NS_OK;
2402 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
2404 nsWineURI *This = impl_from_nsIFileURL(iface);
2405 IUriBuilder *uri_builder;
2406 BSTR display_uri;
2407 IUri *uri;
2408 int len;
2409 nsresult nsres;
2410 HRESULT hres;
2412 TRACE("(%p)->(%p)\n", This, aPrePath);
2414 if(!ensure_uri(This))
2415 return NS_ERROR_UNEXPECTED;
2417 hres = CreateIUriBuilder(This->uri, 0, 0, &uri_builder);
2418 if(FAILED(hres))
2419 return NS_ERROR_FAILURE;
2421 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_PATH|Uri_HAS_QUERY|Uri_HAS_FRAGMENT);
2422 if(SUCCEEDED(hres))
2423 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &uri);
2424 IUriBuilder_Release(uri_builder);
2425 if(FAILED(hres))
2426 return NS_ERROR_FAILURE;
2428 hres = IUri_GetDisplayUri(uri, &display_uri);
2429 IUri_Release(uri);
2430 if(FAILED(hres))
2431 return NS_ERROR_FAILURE;
2433 /* Remove trailing slash that may be appended as default path. */
2434 len = SysStringLen(display_uri);
2435 if(len && display_uri[len-1] == '/')
2436 display_uri[len-1] = 0;
2438 nsres = return_wstr_nsacstr(aPrePath, display_uri, -1);
2439 SysFreeString(display_uri);
2440 return nsres;
2443 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
2445 nsWineURI *This = impl_from_nsIFileURL(iface);
2446 DWORD scheme;
2447 HRESULT hres;
2449 TRACE("(%p)->(%p)\n", This, aScheme);
2451 if(!ensure_uri(This))
2452 return NS_ERROR_UNEXPECTED;
2454 hres = IUri_GetScheme(This->uri, &scheme);
2455 if(FAILED(hres)) {
2456 WARN("GetScheme failed: %08x\n", hres);
2457 return NS_ERROR_UNEXPECTED;
2460 if(scheme == URL_SCHEME_ABOUT) {
2461 nsACString_SetData(aScheme, "wine");
2462 return NS_OK;
2465 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
2468 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
2470 nsWineURI *This = impl_from_nsIFileURL(iface);
2471 const char *schemea;
2472 WCHAR *scheme;
2473 HRESULT hres;
2475 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
2477 if(!ensure_uri_builder(This))
2478 return NS_ERROR_UNEXPECTED;
2480 nsACString_GetData(aScheme, &schemea);
2481 scheme = heap_strdupUtoW(schemea);
2482 if(!scheme)
2483 return NS_ERROR_OUT_OF_MEMORY;
2485 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
2486 heap_free(scheme);
2487 if(FAILED(hres))
2488 return NS_ERROR_UNEXPECTED;
2490 return NS_OK;
2493 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
2495 nsWineURI *This = impl_from_nsIFileURL(iface);
2496 BSTR user, pass;
2497 HRESULT hres;
2499 TRACE("(%p)->(%p)\n", This, aUserPass);
2501 if(!ensure_uri(This))
2502 return NS_ERROR_UNEXPECTED;
2504 hres = IUri_GetUserName(This->uri, &user);
2505 if(FAILED(hres))
2506 return NS_ERROR_FAILURE;
2508 hres = IUri_GetPassword(This->uri, &pass);
2509 if(FAILED(hres)) {
2510 SysFreeString(user);
2511 return NS_ERROR_FAILURE;
2514 if(*user || *pass) {
2515 FIXME("Construct user:pass string\n");
2516 }else {
2517 nsACString_SetData(aUserPass, "");
2520 SysFreeString(user);
2521 SysFreeString(pass);
2522 return NS_OK;
2525 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
2527 nsWineURI *This = impl_from_nsIFileURL(iface);
2528 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
2529 const char *user_pass;
2530 HRESULT hres;
2532 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
2534 if(!ensure_uri_builder(This))
2535 return NS_ERROR_UNEXPECTED;
2537 nsACString_GetData(aUserPass, &user_pass);
2538 if(*user_pass) {
2539 WCHAR *ptr;
2541 buf = heap_strdupUtoW(user_pass);
2542 if(!buf)
2543 return NS_ERROR_OUT_OF_MEMORY;
2545 ptr = strchrW(buf, ':');
2546 if(!ptr) {
2547 user = buf;
2548 }else if(ptr != buf) {
2549 *ptr++ = 0;
2550 user = buf;
2551 if(*ptr)
2552 pass = ptr;
2553 }else {
2554 pass = buf+1;
2558 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2559 if(SUCCEEDED(hres))
2560 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2562 heap_free(buf);
2563 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2566 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2568 nsWineURI *This = impl_from_nsIFileURL(iface);
2570 TRACE("(%p)->(%p)\n", This, aUsername);
2572 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2575 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2577 nsWineURI *This = impl_from_nsIFileURL(iface);
2578 const char *usera;
2579 WCHAR *user;
2580 HRESULT hres;
2582 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2584 if(!ensure_uri_builder(This))
2585 return NS_ERROR_UNEXPECTED;
2587 nsACString_GetData(aUsername, &usera);
2588 user = heap_strdupUtoW(usera);
2589 if(!user)
2590 return NS_ERROR_OUT_OF_MEMORY;
2592 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2593 heap_free(user);
2594 if(FAILED(hres))
2595 return NS_ERROR_UNEXPECTED;
2597 return NS_OK;
2600 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2602 nsWineURI *This = impl_from_nsIFileURL(iface);
2604 TRACE("(%p)->(%p)\n", This, aPassword);
2606 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2609 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2611 nsWineURI *This = impl_from_nsIFileURL(iface);
2612 const char *passa;
2613 WCHAR *pass;
2614 HRESULT hres;
2616 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2618 if(!ensure_uri_builder(This))
2619 return NS_ERROR_UNEXPECTED;
2621 nsACString_GetData(aPassword, &passa);
2622 pass = heap_strdupUtoW(passa);
2623 if(!pass)
2624 return NS_ERROR_OUT_OF_MEMORY;
2626 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2627 heap_free(pass);
2628 if(FAILED(hres))
2629 return NS_ERROR_UNEXPECTED;
2631 return NS_OK;
2634 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2636 nsWineURI *This = impl_from_nsIFileURL(iface);
2637 const WCHAR *ptr;
2638 char *vala;
2639 BSTR val;
2640 HRESULT hres;
2642 TRACE("(%p)->(%p)\n", This, aHostPort);
2644 if(!ensure_uri(This))
2645 return NS_ERROR_UNEXPECTED;
2647 hres = IUri_GetAuthority(This->uri, &val);
2648 if(FAILED(hres)) {
2649 WARN("GetAuthority failed: %08x\n", hres);
2650 return NS_ERROR_UNEXPECTED;
2653 ptr = strchrW(val, '@');
2654 if(!ptr)
2655 ptr = val;
2657 vala = heap_strdupWtoU(ptr);
2658 SysFreeString(val);
2659 if(!vala)
2660 return NS_ERROR_OUT_OF_MEMORY;
2662 TRACE("ret %s\n", debugstr_a(vala));
2663 nsACString_SetData(aHostPort, vala);
2664 heap_free(vala);
2665 return NS_OK;
2668 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2670 nsWineURI *This = impl_from_nsIFileURL(iface);
2672 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2674 /* Not implemented by Gecko */
2675 return NS_ERROR_NOT_IMPLEMENTED;
2678 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2680 nsWineURI *This = impl_from_nsIFileURL(iface);
2682 TRACE("(%p)->(%p)\n", This, aHost);
2684 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2687 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2689 nsWineURI *This = impl_from_nsIFileURL(iface);
2690 const char *hosta;
2691 WCHAR *host;
2692 HRESULT hres;
2694 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2696 if(!ensure_uri_builder(This))
2697 return NS_ERROR_UNEXPECTED;
2699 nsACString_GetData(aHost, &hosta);
2700 host = heap_strdupUtoW(hosta);
2701 if(!host)
2702 return NS_ERROR_OUT_OF_MEMORY;
2704 hres = IUriBuilder_SetHost(This->uri_builder, host);
2705 heap_free(host);
2706 if(FAILED(hres))
2707 return NS_ERROR_UNEXPECTED;
2709 return NS_OK;
2712 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, LONG *aPort)
2714 nsWineURI *This = impl_from_nsIFileURL(iface);
2715 DWORD port;
2716 HRESULT hres;
2718 TRACE("(%p)->(%p)\n", This, aPort);
2720 if(!ensure_uri(This))
2721 return NS_ERROR_UNEXPECTED;
2723 hres = IUri_GetPort(This->uri, &port);
2724 if(FAILED(hres)) {
2725 WARN("GetPort failed: %08x\n", hres);
2726 return NS_ERROR_UNEXPECTED;
2729 *aPort = port ? port : -1;
2730 return NS_OK;
2733 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, LONG aPort)
2735 nsWineURI *This = impl_from_nsIFileURL(iface);
2736 HRESULT hres;
2738 TRACE("(%p)->(%d)\n", This, aPort);
2740 if(!ensure_uri_builder(This))
2741 return NS_ERROR_UNEXPECTED;
2743 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2744 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2747 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2749 nsWineURI *This = impl_from_nsIFileURL(iface);
2751 TRACE("(%p)->(%p)\n", This, aPath);
2753 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2756 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2758 nsWineURI *This = impl_from_nsIFileURL(iface);
2759 const char *patha;
2760 WCHAR *path;
2761 HRESULT hres;
2763 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2765 if(!ensure_uri_builder(This))
2766 return NS_ERROR_UNEXPECTED;
2768 nsACString_GetData(aPath, &patha);
2769 path = heap_strdupUtoW(patha);
2770 if(!path)
2771 return NS_ERROR_OUT_OF_MEMORY;
2773 hres = IUriBuilder_SetPath(This->uri_builder, path);
2774 heap_free(path);
2775 if(FAILED(hres))
2776 return NS_ERROR_UNEXPECTED;
2778 return NS_OK;
2781 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2783 nsWineURI *This = impl_from_nsIFileURL(iface);
2784 nsWineURI *other_obj;
2785 nsresult nsres;
2786 HRESULT hres;
2788 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2790 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2791 if(NS_FAILED(nsres)) {
2792 TRACE("Could not get nsWineURI interface\n");
2793 *_retval = FALSE;
2794 return NS_OK;
2797 if(ensure_uri(This) && ensure_uri(other_obj)) {
2798 BOOL b;
2800 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2801 if(SUCCEEDED(hres)) {
2802 *_retval = b;
2803 nsres = NS_OK;
2804 }else {
2805 nsres = NS_ERROR_FAILURE;
2807 }else {
2808 nsres = NS_ERROR_UNEXPECTED;
2811 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2812 return nsres;
2815 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2817 nsWineURI *This = impl_from_nsIFileURL(iface);
2818 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2819 BSTR scheme_name;
2820 HRESULT hres;
2822 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2824 if(!ensure_uri(This))
2825 return NS_ERROR_UNEXPECTED;
2827 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2828 if(FAILED(hres))
2829 return NS_ERROR_UNEXPECTED;
2831 MultiByteToWideChar(CP_UTF8, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2832 *_retval = !strcmpW(scheme_name, buf);
2833 SysFreeString(scheme_name);
2834 return NS_OK;
2837 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2839 nsWineURI *This = impl_from_nsIFileURL(iface);
2840 nsWineURI *wine_uri;
2841 nsresult nsres;
2843 TRACE("(%p)->(%p)\n", This, _retval);
2845 if(!ensure_uri(This))
2846 return NS_ERROR_UNEXPECTED;
2848 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL,
2849 This->container, This->origin_charset, &wine_uri);
2850 if(NS_FAILED(nsres)) {
2851 WARN("create_nsuri failed: %08x\n", nsres);
2852 return nsres;
2855 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2856 return NS_OK;
2859 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2860 nsACString *_retval)
2862 nsWineURI *This = impl_from_nsIFileURL(iface);
2863 const char *patha;
2864 IUri *new_uri;
2865 WCHAR *path;
2866 char *reta;
2867 BSTR ret;
2868 HRESULT hres;
2870 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2872 if(!ensure_uri(This))
2873 return NS_ERROR_UNEXPECTED;
2875 nsACString_GetData(aRelativePath, &patha);
2876 path = heap_strdupUtoW(patha);
2877 if(!path)
2878 return NS_ERROR_OUT_OF_MEMORY;
2880 hres = combine_url(This->uri, path, &new_uri);
2881 heap_free(path);
2882 if(FAILED(hres))
2883 return NS_ERROR_FAILURE;
2885 hres = IUri_GetDisplayUri(new_uri, &ret);
2886 IUri_Release(new_uri);
2887 if(FAILED(hres))
2888 return NS_ERROR_FAILURE;
2890 reta = heap_strdupWtoU(ret);
2891 SysFreeString(ret);
2892 if(!reta)
2893 return NS_ERROR_OUT_OF_MEMORY;
2895 TRACE("returning %s\n", debugstr_a(reta));
2896 nsACString_SetData(_retval, reta);
2897 heap_free(reta);
2898 return NS_OK;
2901 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2903 nsWineURI *This = impl_from_nsIFileURL(iface);
2905 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2907 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2910 static nsresult NSAPI nsURI_GetAsciiHostPort(nsIFileURL *iface, nsACString *aAsciiHostPort)
2912 nsWineURI *This = impl_from_nsIFileURL(iface);
2914 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHostPort);
2916 return nsIFileURL_GetHostPort(&This->nsIFileURL_iface, aAsciiHostPort);
2919 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2921 nsWineURI *This = impl_from_nsIFileURL(iface);
2923 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2925 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2928 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2930 nsWineURI *This = impl_from_nsIFileURL(iface);
2932 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2934 nsACString_SetData(aOriginCharset, This->origin_charset);
2935 return NS_OK;
2938 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2940 nsWineURI *This = impl_from_nsIFileURL(iface);
2941 char *refa = NULL;
2942 BSTR ref;
2943 HRESULT hres;
2945 TRACE("(%p)->(%p)\n", This, aRef);
2947 if(!ensure_uri(This))
2948 return NS_ERROR_UNEXPECTED;
2950 hres = IUri_GetFragment(This->uri, &ref);
2951 if(FAILED(hres))
2952 return NS_ERROR_UNEXPECTED;
2954 refa = heap_strdupWtoU(ref);
2955 SysFreeString(ref);
2956 if(ref && !refa)
2957 return NS_ERROR_OUT_OF_MEMORY;
2959 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2960 heap_free(refa);
2961 return NS_OK;
2964 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2966 nsWineURI *This = impl_from_nsIFileURL(iface);
2967 const char *refa;
2968 WCHAR *ref;
2969 HRESULT hres;
2971 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2973 if(!ensure_uri_builder(This))
2974 return NS_ERROR_UNEXPECTED;
2976 nsACString_GetData(aRef, &refa);
2977 ref = heap_strdupUtoW(refa);
2978 if(!ref)
2979 return NS_ERROR_OUT_OF_MEMORY;
2981 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2982 heap_free(ref);
2983 if(FAILED(hres))
2984 return NS_ERROR_UNEXPECTED;
2986 return NS_OK;
2989 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2991 nsWineURI *This = impl_from_nsIFileURL(iface);
2992 nsWineURI *other_obj;
2993 nsresult nsres;
2995 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2997 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2998 if(NS_FAILED(nsres)) {
2999 TRACE("Could not get nsWineURI interface\n");
3000 *_retval = FALSE;
3001 return NS_OK;
3004 if(ensure_uri(This) && ensure_uri(other_obj)) {
3005 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
3006 nsres = NS_OK;
3007 }else {
3008 nsres = NS_ERROR_UNEXPECTED;
3011 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
3012 return nsres;
3015 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
3017 nsWineURI *This = impl_from_nsIFileURL(iface);
3018 nsWineURI *wine_uri;
3019 IUri *uri;
3020 nsresult nsres;
3022 TRACE("(%p)->(%p)\n", This, _retval);
3024 if(!ensure_uri(This))
3025 return NS_ERROR_UNEXPECTED;
3027 uri = get_uri_nofrag(This->uri);
3028 if(!uri)
3029 return NS_ERROR_FAILURE;
3031 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container,
3032 This->origin_charset, &wine_uri);
3033 IUri_Release(uri);
3034 if(NS_FAILED(nsres)) {
3035 WARN("create_nsuri failed: %08x\n", nsres);
3036 return nsres;
3039 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3040 return NS_OK;
3043 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
3045 nsWineURI *This = impl_from_nsIFileURL(iface);
3047 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
3049 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
3052 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
3054 nsWineURI *This = impl_from_nsIFileURL(iface);
3055 BOOL b;
3056 HRESULT hres;
3058 TRACE("(%p)->(%p)\n", This, aHasRef);
3060 if(!ensure_uri(This))
3061 return NS_ERROR_UNEXPECTED;
3063 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
3064 if(FAILED(hres))
3065 return NS_ERROR_FAILURE;
3067 *aHasRef = b;
3068 return NS_OK;
3071 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
3073 nsWineURI *This = impl_from_nsIFileURL(iface);
3075 TRACE("(%p)->(%p)\n", This, aFilePath);
3077 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
3080 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
3082 nsWineURI *This = impl_from_nsIFileURL(iface);
3084 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
3086 if(!This->is_mutable)
3087 return NS_ERROR_UNEXPECTED;
3089 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
3092 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
3094 nsWineURI *This = impl_from_nsIFileURL(iface);
3095 WCHAR *ptr;
3096 BSTR query;
3097 nsresult nsres;
3098 HRESULT hres;
3100 TRACE("(%p)->(%p)\n", This, aQuery);
3102 if(!ensure_uri(This))
3103 return NS_ERROR_UNEXPECTED;
3105 hres = IUri_GetQuery(This->uri, &query);
3106 if(FAILED(hres))
3107 return NS_ERROR_FAILURE;
3109 ptr = query;
3110 if(ptr && *ptr == '?')
3111 ptr++;
3113 nsres = return_wstr_nsacstr(aQuery, ptr, -1);
3114 SysFreeString(query);
3115 return nsres;
3118 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
3120 nsWineURI *This = impl_from_nsIFileURL(iface);
3121 const char *querya;
3122 WCHAR *query;
3123 HRESULT hres;
3125 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
3127 if(!ensure_uri_builder(This))
3128 return NS_ERROR_UNEXPECTED;
3130 nsACString_GetData(aQuery, &querya);
3131 query = heap_strdupUtoW(querya);
3132 if(!query)
3133 return NS_ERROR_OUT_OF_MEMORY;
3135 hres = IUriBuilder_SetQuery(This->uri_builder, query);
3136 heap_free(query);
3137 if(FAILED(hres))
3138 return NS_ERROR_UNEXPECTED;
3140 return NS_OK;
3143 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
3145 const WCHAR *ptr;
3146 HRESULT hres;
3148 if(!ensure_uri(This))
3149 return NS_ERROR_UNEXPECTED;
3151 hres = IUri_GetPath(This->uri, path);
3152 if(FAILED(hres))
3153 return NS_ERROR_FAILURE;
3155 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
3156 if(*ptr == '/' || *ptr == '\\')
3157 ptr++;
3158 *file = ptr;
3160 if(ext) {
3161 ptr = strrchrW(ptr, '.');
3162 if(!ptr)
3163 ptr = *path + SysStringLen(*path);
3164 *ext = ptr;
3167 return NS_OK;
3170 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
3172 nsWineURI *This = impl_from_nsIFileURL(iface);
3173 const WCHAR *file;
3174 BSTR path;
3175 nsresult nsres;
3177 TRACE("(%p)->(%p)\n", This, aDirectory);
3179 nsres = get_uri_path(This, &path, &file, NULL);
3180 if(NS_FAILED(nsres))
3181 return nsres;
3183 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
3184 SysFreeString(path);
3185 return nsres;
3188 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
3190 nsWineURI *This = impl_from_nsIFileURL(iface);
3192 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
3194 /* Not implemented by Gecko */
3195 return NS_ERROR_NOT_IMPLEMENTED;
3198 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
3200 nsWineURI *This = impl_from_nsIFileURL(iface);
3201 const WCHAR *file;
3202 BSTR path;
3203 nsresult nsres;
3205 TRACE("(%p)->(%p)\n", This, aFileName);
3207 nsres = get_uri_path(This, &path, &file, NULL);
3208 if(NS_FAILED(nsres))
3209 return nsres;
3211 nsres = return_wstr_nsacstr(aFileName, file, -1);
3212 SysFreeString(path);
3213 return nsres;
3216 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
3218 nsWineURI *This = impl_from_nsIFileURL(iface);
3219 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
3220 return NS_ERROR_NOT_IMPLEMENTED;
3223 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
3225 nsWineURI *This = impl_from_nsIFileURL(iface);
3226 const WCHAR *file, *ext;
3227 BSTR path;
3228 nsresult nsres;
3230 TRACE("(%p)->(%p)\n", This, aFileBaseName);
3232 nsres = get_uri_path(This, &path, &file, &ext);
3233 if(NS_FAILED(nsres))
3234 return nsres;
3236 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
3237 SysFreeString(path);
3238 return nsres;
3241 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
3243 nsWineURI *This = impl_from_nsIFileURL(iface);
3244 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
3245 return NS_ERROR_NOT_IMPLEMENTED;
3248 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
3250 nsWineURI *This = impl_from_nsIFileURL(iface);
3252 TRACE("(%p)->(%p)\n", This, aFileExtension);
3254 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
3257 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
3259 nsWineURI *This = impl_from_nsIFileURL(iface);
3260 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
3261 return NS_ERROR_NOT_IMPLEMENTED;
3264 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
3266 nsWineURI *This = impl_from_nsIFileURL(iface);
3267 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
3268 return NS_ERROR_NOT_IMPLEMENTED;
3271 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
3273 nsWineURI *This = impl_from_nsIFileURL(iface);
3274 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
3275 return NS_ERROR_NOT_IMPLEMENTED;
3278 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
3280 nsWineURI *This = impl_from_nsIFileURL(iface);
3281 WCHAR path[MAX_PATH];
3282 DWORD size;
3283 HRESULT hres;
3285 TRACE("(%p)->(%p)\n", This, aFile);
3287 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
3288 if(FAILED(hres)) {
3289 WARN("CoInternetParseIUri failed: %08x\n", hres);
3290 return NS_ERROR_FAILURE;
3293 return create_nsfile(path, aFile);
3296 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
3298 nsWineURI *This = impl_from_nsIFileURL(iface);
3299 FIXME("(%p)->(%p)\n", This, aFile);
3300 return NS_ERROR_NOT_IMPLEMENTED;
3303 static const nsIFileURLVtbl nsFileURLVtbl = {
3304 nsURI_QueryInterface,
3305 nsURI_AddRef,
3306 nsURI_Release,
3307 nsURI_GetSpec,
3308 nsURI_SetSpec,
3309 nsURI_GetPrePath,
3310 nsURI_GetScheme,
3311 nsURI_SetScheme,
3312 nsURI_GetUserPass,
3313 nsURI_SetUserPass,
3314 nsURI_GetUsername,
3315 nsURI_SetUsername,
3316 nsURI_GetPassword,
3317 nsURI_SetPassword,
3318 nsURI_GetHostPort,
3319 nsURI_SetHostPort,
3320 nsURI_GetHost,
3321 nsURI_SetHost,
3322 nsURI_GetPort,
3323 nsURI_SetPort,
3324 nsURI_GetPath,
3325 nsURI_SetPath,
3326 nsURI_Equals,
3327 nsURI_SchemeIs,
3328 nsURI_Clone,
3329 nsURI_Resolve,
3330 nsURI_GetAsciiSpec,
3331 nsURI_GetAsciiHostPort,
3332 nsURI_GetAsciiHost,
3333 nsURI_GetOriginCharset,
3334 nsURL_GetRef,
3335 nsURL_SetRef,
3336 nsURI_EqualsExceptRef,
3337 nsURI_CloneIgnoreRef,
3338 nsURI_GetSpecIgnoringRef,
3339 nsURI_GetHasRef,
3340 nsURL_GetFilePath,
3341 nsURL_SetFilePath,
3342 nsURL_GetQuery,
3343 nsURL_SetQuery,
3344 nsURL_GetDirectory,
3345 nsURL_SetDirectory,
3346 nsURL_GetFileName,
3347 nsURL_SetFileName,
3348 nsURL_GetFileBaseName,
3349 nsURL_SetFileBaseName,
3350 nsURL_GetFileExtension,
3351 nsURL_SetFileExtension,
3352 nsURL_GetCommonBaseSpec,
3353 nsURL_GetRelativeSpec,
3354 nsFileURL_GetFile,
3355 nsFileURL_SetFile
3358 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
3360 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
3363 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
3364 void **result)
3366 nsWineURI *This = impl_from_nsIStandardURL(iface);
3367 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
3370 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
3372 nsWineURI *This = impl_from_nsIStandardURL(iface);
3373 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
3376 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
3378 nsWineURI *This = impl_from_nsIStandardURL(iface);
3379 return nsIFileURL_Release(&This->nsIFileURL_iface);
3382 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
3384 nsWineURI *This = impl_from_nsIStandardURL(iface);
3386 TRACE("(%p)->(%p)\n", This, aMutable);
3388 *aMutable = This->is_mutable;
3389 return NS_OK;
3392 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
3394 nsWineURI *This = impl_from_nsIStandardURL(iface);
3396 TRACE("(%p)->(%x)\n", This, aMutable);
3398 This->is_mutable = aMutable;
3399 return NS_OK;
3402 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, UINT32 aUrlType, LONG aDefaultPort,
3403 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
3405 nsWineURI *This = impl_from_nsIStandardURL(iface);
3406 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
3407 return NS_ERROR_NOT_IMPLEMENTED;
3410 static nsresult NSAPI nsStandardURL_SetDefaultPort(nsIStandardURL *iface, LONG aNewDefaultPort)
3412 nsWineURI *This = impl_from_nsIStandardURL(iface);
3413 FIXME("(%p)->(%d)\n", This, aNewDefaultPort);
3414 return NS_ERROR_NOT_IMPLEMENTED;
3417 static const nsIStandardURLVtbl nsStandardURLVtbl = {
3418 nsStandardURL_QueryInterface,
3419 nsStandardURL_AddRef,
3420 nsStandardURL_Release,
3421 nsStandardURL_GetMutable,
3422 nsStandardURL_SetMutable,
3423 nsStandardURL_Init,
3424 nsStandardURL_SetDefaultPort
3427 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container,
3428 const char *origin_charset, nsWineURI **_retval)
3430 nsWineURI *ret;
3431 HRESULT hres;
3433 ret = heap_alloc_zero(sizeof(nsWineURI));
3434 if(!ret)
3435 return NS_ERROR_OUT_OF_MEMORY;
3437 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
3438 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
3439 ret->ref = 1;
3440 ret->is_mutable = TRUE;
3442 set_uri_nscontainer(ret, container);
3443 set_uri_window(ret, window);
3445 IUri_AddRef(iuri);
3446 ret->uri = iuri;
3448 hres = IUri_GetScheme(iuri, &ret->scheme);
3449 if(FAILED(hres))
3450 ret->scheme = URL_SCHEME_UNKNOWN;
3452 if(origin_charset && *origin_charset && strcmp(origin_charset, "UTF-8")) {
3453 ret->origin_charset = heap_strdupA(origin_charset);
3454 if(!ret->origin_charset) {
3455 nsIFileURL_Release(&ret->nsIFileURL_iface);
3456 return NS_ERROR_OUT_OF_MEMORY;
3460 TRACE("retval=%p\n", ret);
3461 *_retval = ret;
3462 return NS_OK;
3465 HRESULT create_doc_uri(HTMLOuterWindow *window, IUri *iuri, nsWineURI **ret)
3467 nsWineURI *uri;
3468 nsresult nsres;
3470 nsres = create_nsuri(iuri, window, window->doc_obj ? window->doc_obj->nscontainer : NULL,
3471 NULL, &uri);
3472 if(NS_FAILED(nsres))
3473 return E_FAIL;
3475 uri->is_doc_uri = TRUE;
3477 *ret = uri;
3478 return S_OK;
3481 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
3483 nsChannel *channel;
3485 if(!ensure_uri(uri))
3486 return NS_ERROR_UNEXPECTED;
3488 channel = heap_alloc_zero(sizeof(nsChannel));
3489 if(!channel)
3490 return NS_ERROR_OUT_OF_MEMORY;
3492 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
3493 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
3494 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
3495 channel->ref = 1;
3496 channel->request_method = METHOD_GET;
3497 list_init(&channel->response_headers);
3498 list_init(&channel->request_headers);
3500 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
3501 channel->uri = uri;
3503 *ret = channel;
3504 return NS_OK;
3507 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
3509 HTMLOuterWindow *window = NULL;
3510 nsChannel *channel;
3511 nsWineURI *uri;
3512 IUri *iuri;
3513 nsresult nsres;
3514 HRESULT hres;
3516 hres = create_uri(url, 0, &iuri);
3517 if(FAILED(hres))
3518 return hres;
3520 if(orig_channel->uri->window_ref)
3521 window = orig_channel->uri->window_ref->window;
3522 nsres = create_nsuri(iuri, window, NULL, NULL, &uri);
3523 IUri_Release(iuri);
3524 if(NS_FAILED(nsres))
3525 return E_FAIL;
3527 nsres = create_nschannel(uri, &channel);
3528 nsIFileURL_Release(&uri->nsIFileURL_iface);
3529 if(NS_FAILED(nsres))
3530 return E_FAIL;
3532 if(orig_channel->load_group) {
3533 nsILoadGroup_AddRef(orig_channel->load_group);
3534 channel->load_group = orig_channel->load_group;
3537 if(orig_channel->notif_callback) {
3538 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
3539 channel->notif_callback = orig_channel->notif_callback;
3542 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
3544 if(orig_channel->request_method == METHOD_POST)
3545 FIXME("unsupported POST method\n");
3547 if(orig_channel->original_uri) {
3548 nsIURI_AddRef(orig_channel->original_uri);
3549 channel->original_uri = orig_channel->original_uri;
3552 if(orig_channel->referrer) {
3553 nsIURI_AddRef(orig_channel->referrer);
3554 channel->referrer = orig_channel->referrer;
3557 *ret = channel;
3558 return S_OK;
3561 typedef struct {
3562 nsIProtocolHandler nsIProtocolHandler_iface;
3564 LONG ref;
3566 nsIProtocolHandler *nshandler;
3567 } nsProtocolHandler;
3569 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
3571 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
3574 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3575 void **result)
3577 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3579 *result = NULL;
3581 if(IsEqualGUID(&IID_nsISupports, riid)) {
3582 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3583 *result = &This->nsIProtocolHandler_iface;
3584 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3585 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3586 *result = &This->nsIProtocolHandler_iface;
3587 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3588 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3589 return NS_NOINTERFACE;
3592 if(*result) {
3593 nsISupports_AddRef((nsISupports*)*result);
3594 return NS_OK;
3597 WARN("(%s %p)\n", debugstr_guid(riid), result);
3598 return NS_NOINTERFACE;
3601 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3603 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3604 LONG ref = InterlockedIncrement(&This->ref);
3606 TRACE("(%p) ref=%d\n", This, ref);
3608 return ref;
3611 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3613 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3614 LONG ref = InterlockedDecrement(&This->ref);
3616 TRACE("(%p) ref=%d\n", This, ref);
3618 if(!ref) {
3619 if(This->nshandler)
3620 nsIProtocolHandler_Release(This->nshandler);
3621 heap_free(This);
3624 return ref;
3627 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3629 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3631 TRACE("(%p)->(%p)\n", This, aScheme);
3633 if(This->nshandler)
3634 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3635 return NS_ERROR_NOT_IMPLEMENTED;
3638 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3639 LONG *aDefaultPort)
3641 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3643 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3645 if(This->nshandler)
3646 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3647 return NS_ERROR_NOT_IMPLEMENTED;
3650 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3651 UINT32 *aProtocolFlags)
3653 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3655 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3657 if(This->nshandler)
3658 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3659 return NS_ERROR_NOT_IMPLEMENTED;
3662 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3663 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3665 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3667 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3668 aBaseURI, _retval);
3670 if(This->nshandler)
3671 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3672 return NS_ERROR_NOT_IMPLEMENTED;
3675 static nsresult NSAPI nsProtocolHandler_NewChannel2(nsIProtocolHandler *iface,
3676 nsIURI *aURI, nsILoadInfo *aLoadInfo, nsIChannel **_retval)
3678 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3680 TRACE("(%p)->(%p %p %p)\n", This, aURI, aLoadInfo, _retval);
3682 if(This->nshandler)
3683 return nsIProtocolHandler_NewChannel2(This->nshandler, aURI, aLoadInfo, _retval);
3684 return NS_ERROR_NOT_IMPLEMENTED;
3687 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3688 nsIURI *aURI, nsIChannel **_retval)
3690 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3692 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3694 if(This->nshandler)
3695 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3696 return NS_ERROR_NOT_IMPLEMENTED;
3699 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3700 LONG port, const char *scheme, cpp_bool *_retval)
3702 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3704 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3706 if(This->nshandler)
3707 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3708 return NS_ERROR_NOT_IMPLEMENTED;
3711 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3712 nsProtocolHandler_QueryInterface,
3713 nsProtocolHandler_AddRef,
3714 nsProtocolHandler_Release,
3715 nsProtocolHandler_GetScheme,
3716 nsProtocolHandler_GetDefaultPort,
3717 nsProtocolHandler_GetProtocolFlags,
3718 nsProtocolHandler_NewURI,
3719 nsProtocolHandler_NewChannel2,
3720 nsProtocolHandler_NewChannel,
3721 nsProtocolHandler_AllowPort
3724 static nsresult NSAPI nsIOServiceHook_QueryInterface(nsIIOServiceHook *iface, nsIIDRef riid,
3725 void **result)
3727 if(IsEqualGUID(&IID_nsISupports, riid)) {
3728 TRACE("(IID_nsISupports %p)\n", result);
3729 *result = iface;
3730 }else if(IsEqualGUID(&IID_nsIIOServiceHook, riid)) {
3731 TRACE("(IID_nsIIOServiceHook %p)\n", result);
3732 *result = iface;
3733 }else {
3734 ERR("(%s %p)\n", debugstr_guid(riid), result);
3735 *result = NULL;
3736 return NS_NOINTERFACE;
3739 nsISupports_AddRef((nsISupports*)*result);
3740 return NS_OK;
3743 static nsrefcnt NSAPI nsIOServiceHook_AddRef(nsIIOServiceHook *iface)
3745 return 2;
3748 static nsrefcnt NSAPI nsIOServiceHook_Release(nsIIOServiceHook *iface)
3750 return 1;
3753 static nsresult NSAPI nsIOServiceHook_NewChannel(nsIIOServiceHook *iface, nsIURI *aURI,
3754 nsILoadInfo *aLoadInfo, nsIChannel **_retval)
3756 nsWineURI *wine_uri;
3757 nsChannel *ret;
3758 nsresult nsres;
3760 TRACE("(%p %p %p)\n", aURI, aLoadInfo, _retval);
3762 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3763 if(NS_FAILED(nsres)) {
3764 TRACE("Could not get nsWineURI: %08x\n", nsres);
3765 return NS_SUCCESS_DEFAULT_ACTION;
3768 nsres = create_nschannel(wine_uri, &ret);
3769 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3770 if(NS_FAILED(nsres))
3771 return nsres;
3773 nsIURI_AddRef(aURI);
3774 ret->original_uri = aURI;
3776 if(aLoadInfo)
3777 nsIHttpChannel_SetLoadInfo(&ret->nsIHttpChannel_iface, aLoadInfo);
3779 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3780 return NS_OK;
3783 static nsresult NSAPI nsIOServiceHook_GetProtocolHandler(nsIIOServiceHook *iface, nsIProtocolHandler *aHandler,
3784 nsIProtocolHandler **_retval)
3786 nsIExternalProtocolHandler *nsexthandler;
3787 nsProtocolHandler *ret;
3788 nsresult nsres;
3790 TRACE("(%p %p)\n", aHandler, _retval);
3792 nsres = nsIProtocolHandler_QueryInterface(aHandler, &IID_nsIExternalProtocolHandler, (void**)&nsexthandler);
3793 if(NS_FAILED(nsres)) {
3794 nsIProtocolHandler_AddRef(aHandler);
3795 *_retval = aHandler;
3796 return NS_OK;
3799 nsIExternalProtocolHandler_Release(nsexthandler);
3801 ret = heap_alloc(sizeof(nsProtocolHandler));
3802 if(!ret)
3803 return NS_ERROR_OUT_OF_MEMORY;
3805 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3806 ret->ref = 1;
3807 nsIProtocolHandler_AddRef(aHandler);
3808 ret->nshandler = aHandler;
3811 *_retval = &ret->nsIProtocolHandler_iface;
3812 TRACE("return %p\n", *_retval);
3813 return NS_OK;
3816 static BOOL is_gecko_special_uri(const char *spec)
3818 static const char *special_schemes[] = {"chrome:", "data:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3819 unsigned int i;
3821 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3822 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3823 return TRUE;
3826 if(!strncasecmp(spec, "file:", 5)) {
3827 const char *ptr = spec+5;
3828 while(*ptr == '/')
3829 ptr++;
3830 return is_gecko_path(ptr);
3833 return FALSE;
3836 static nsresult NSAPI nsIOServiceHook_NewURI(nsIIOServiceHook *iface, const nsACString *aSpec,
3837 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3839 nsWineURI *wine_uri, *base_wine_uri = NULL;
3840 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3841 HTMLOuterWindow *window = NULL;
3842 const char *spec = NULL;
3843 UINT cp = CP_UTF8;
3844 IUri *urlmon_uri;
3845 nsresult nsres;
3846 HRESULT hres;
3848 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3849 aBaseURI, _retval);
3851 nsACString_GetData(aSpec, &spec);
3852 if(is_gecko_special_uri(spec))
3853 return NS_SUCCESS_DEFAULT_ACTION;
3855 if(!strncmp(spec, "wine:", 5))
3856 spec += 5;
3858 if(aBaseURI) {
3859 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3860 if(NS_SUCCEEDED(nsres)) {
3861 if(!ensure_uri(base_wine_uri))
3862 return NS_ERROR_UNEXPECTED;
3863 if(base_wine_uri->window_ref)
3864 window = base_wine_uri->window_ref->window;
3865 }else {
3866 WARN("Could not get base nsWineURI: %08x\n", nsres);
3870 if(aOriginCharset && *aOriginCharset && strncasecmp(aOriginCharset, "utf", 3)) {
3871 BSTR charset;
3872 int len;
3874 len = MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, NULL, 0);
3875 charset = SysAllocStringLen(NULL, len-1);
3876 if(!charset)
3877 return NS_ERROR_OUT_OF_MEMORY;
3878 MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, charset, len);
3880 cp = cp_from_charset_string(charset);
3882 SysFreeString(charset);
3885 MultiByteToWideChar(cp, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3887 if(base_wine_uri) {
3888 hres = combine_url(base_wine_uri->uri, new_spec, &urlmon_uri);
3889 }else {
3890 hres = create_uri(new_spec, 0, &urlmon_uri);
3891 if(FAILED(hres))
3892 WARN("create_uri failed: %08x\n", hres);
3895 if(FAILED(hres))
3896 return NS_SUCCESS_DEFAULT_ACTION;
3898 nsres = create_nsuri(urlmon_uri, window, NULL, NULL, &wine_uri);
3899 IUri_Release(urlmon_uri);
3900 if(base_wine_uri)
3901 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3902 if(NS_FAILED(nsres))
3903 return nsres;
3905 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3906 return nsres;
3909 static const char *debugstr_protocol_flags(UINT32 flags)
3911 switch(flags) {
3912 #define X(f) case f: return #f
3913 X(URI_STD);
3914 X(URI_NORELATIVE);
3915 X(URI_NOAUTH);
3916 X(ALLOWS_PROXY);
3917 X(ALLOWS_PROXY_HTTP);
3918 X(URI_INHERITS_SECURITY_CONTEXT);
3919 X(URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT);
3920 X(URI_LOADABLE_BY_ANYONE);
3921 X(URI_DANGEROUS_TO_LOAD);
3922 X(URI_IS_UI_RESOURCE);
3923 X(URI_IS_LOCAL_FILE);
3924 X(URI_LOADABLE_BY_SUBSUMERS);
3925 X(URI_DOES_NOT_RETURN_DATA);
3926 X(URI_IS_LOCAL_RESOURCE);
3927 X(URI_OPENING_EXECUTES_SCRIPT);
3928 X(URI_NON_PERSISTABLE);
3929 X(URI_FORBIDS_COOKIE_ACCESS);
3930 X(URI_CROSS_ORIGIN_NEEDS_WEBAPPS_PERM);
3931 X(URI_SYNC_LOAD_IS_OK);
3932 X(URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT);
3933 X(URI_FETCHABLE_BY_ANYONE);
3934 #undef X
3935 default:
3936 return wine_dbg_sprintf("%08x", flags);
3940 static nsresult NSAPI nsIOServiceHook_ProtocolHasFlags(nsIIOServiceHook *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3942 TRACE("(%p %s %p)\n", aURI, debugstr_protocol_flags(aFlags), _retval);
3943 return NS_SUCCESS_DEFAULT_ACTION;
3946 static nsresult NSAPI nsIOServiceHook_URIChainHasFlags(nsIIOServiceHook *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3948 TRACE("(%p %s %p)\n", aURI, debugstr_protocol_flags(aFlags), _retval);
3950 if(aFlags == URI_DOES_NOT_RETURN_DATA) {
3951 *_retval = FALSE;
3952 return S_OK;
3955 return NS_SUCCESS_DEFAULT_ACTION;
3958 static const nsIIOServiceHookVtbl nsIOServiceHookVtbl = {
3959 nsIOServiceHook_QueryInterface,
3960 nsIOServiceHook_AddRef,
3961 nsIOServiceHook_Release,
3962 nsIOServiceHook_NewChannel,
3963 nsIOServiceHook_GetProtocolHandler,
3964 nsIOServiceHook_NewURI,
3965 nsIOServiceHook_ProtocolHasFlags,
3966 nsIOServiceHook_URIChainHasFlags
3969 static nsIIOServiceHook nsIOServiceHook = { &nsIOServiceHookVtbl };
3971 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3973 OLECHAR *new_url = NULL;
3974 WCHAR *url;
3975 BOOL ret = FALSE;
3976 HRESULT hres;
3978 if(!doc->hostui || !ensure_uri(uri))
3979 return FALSE;
3981 hres = IUri_GetDisplayUri(uri->uri, &url);
3982 if(FAILED(hres))
3983 return FALSE;
3985 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3986 if(hres == S_OK && new_url) {
3987 if(strcmpW(url, new_url)) {
3988 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3989 ret = TRUE;
3991 CoTaskMemFree(new_url);
3994 SysFreeString(url);
3995 return ret;
3998 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
4000 nsWineURI *wine_uri;
4001 nsresult nsres;
4003 *_retval = FALSE;
4005 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
4006 if(NS_FAILED(nsres)) {
4007 WARN("Could not get nsWineURI: %08x\n", nsres);
4008 return NS_ERROR_NOT_IMPLEMENTED;
4011 if(!wine_uri->is_doc_uri) {
4012 wine_uri->is_doc_uri = TRUE;
4014 if(!wine_uri->container) {
4015 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
4016 wine_uri->container = nscontainer;
4019 if(nscontainer->doc)
4020 *_retval = translate_url(nscontainer->doc, wine_uri);
4023 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
4024 return NS_OK;
4027 void init_nsio(nsIComponentManager *component_manager)
4029 nsIFactory *old_factory = NULL;
4030 nsresult nsres;
4032 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
4033 &IID_nsIFactory, (void**)&old_factory);
4034 if(NS_FAILED(nsres)) {
4035 ERR("Could not get factory: %08x\n", nsres);
4036 return;
4039 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
4040 if(NS_FAILED(nsres)) {
4041 ERR("Couldn not create nsIOService instance %08x\n", nsres);
4042 nsIFactory_Release(old_factory);
4043 return;
4046 nsres = nsIIOService_SetHook(nsio, &nsIOServiceHook);
4047 assert(nsres == NS_OK);
4050 void release_nsio(void)
4052 if(nsio) {
4053 nsIIOService_Release(nsio);
4054 nsio = NULL;