d3d10core/tests: Remove dead code.
[wine.git] / dlls / mshtml / nsio.c
blobdac97987725d1432b065075f44710c210c9efcf0
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;
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 nsIDOMWindow *nswindow;
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, &nswindow);
989 nsIWebProgress_Release(web_progress);
990 if(NS_FAILED(nsres) || !nswindow) {
991 ERR("GetDOMWindow failed: %08x\n", nsres);
992 return NULL;
995 window = nswindow_to_window(nswindow);
996 nsIDOMWindow_Release(nswindow);
998 if(window)
999 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
1000 else
1001 FIXME("NULL window for %p\n", nswindow);
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 if(aReferrer)
1292 nsIURI_AddRef(aReferrer);
1293 if(This->referrer)
1294 nsIURI_Release(This->referrer);
1295 This->referrer = aReferrer;
1296 return NS_OK;
1299 static nsresult NSAPI nsChannel_GetReferrerPolicy(nsIHttpChannel *iface, UINT32 *aReferrerPolicy)
1301 nsChannel *This = impl_from_nsIHttpChannel(iface);
1302 FIXME("(%p)->(%p)\n", This, aReferrerPolicy);
1303 return NS_ERROR_NOT_IMPLEMENTED;
1306 static nsresult NSAPI nsChannel_SetReferrerWithPolicy(nsIHttpChannel *iface, nsIURI *aReferrer, UINT32 aReferrerPolicy)
1308 nsChannel *This = impl_from_nsIHttpChannel(iface);
1309 FIXME("(%p)->(%p %x)\n", This, aReferrer, aReferrerPolicy);
1310 return NS_ERROR_NOT_IMPLEMENTED;
1313 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1314 const nsACString *aHeader, nsACString *_retval)
1316 nsChannel *This = impl_from_nsIHttpChannel(iface);
1318 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1320 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1323 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1324 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1326 nsChannel *This = impl_from_nsIHttpChannel(iface);
1328 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1330 if(aMerge)
1331 FIXME("aMerge not supported\n");
1333 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1336 static nsresult NSAPI nsChannel_SetEmptyRequestHeader(nsIHttpChannel *iface, const nsACString *aHeader)
1338 nsChannel *This = impl_from_nsIHttpChannel(iface);
1339 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aHeader));
1340 return NS_ERROR_NOT_IMPLEMENTED;
1343 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1344 nsIHttpHeaderVisitor *aVisitor)
1346 nsChannel *This = impl_from_nsIHttpChannel(iface);
1348 FIXME("(%p)->(%p)\n", This, aVisitor);
1350 return NS_ERROR_NOT_IMPLEMENTED;
1353 static nsresult NSAPI nsChannel_VisitNonDefaultRequestHeaders(nsIHttpChannel *iface, nsIHttpHeaderVisitor *aVisitor)
1355 nsChannel *This = impl_from_nsIHttpChannel(iface);
1356 FIXME("(%p)->(%p)\n", This, aVisitor);
1357 return NS_ERROR_NOT_IMPLEMENTED;
1360 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1362 nsChannel *This = impl_from_nsIHttpChannel(iface);
1364 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1366 return NS_ERROR_NOT_IMPLEMENTED;
1369 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1371 nsChannel *This = impl_from_nsIHttpChannel(iface);
1373 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1375 return NS_ERROR_NOT_IMPLEMENTED;
1378 static nsresult NSAPI nsChannel_GetAllowTLS(nsIHttpChannel *iface, cpp_bool *aAllowTLS)
1380 nsChannel *This = impl_from_nsIHttpChannel(iface);
1381 FIXME("(%p)->(%p)\n", This, aAllowTLS);
1382 return NS_ERROR_NOT_IMPLEMENTED;
1385 static nsresult NSAPI nsChannel_SetAllowTLS(nsIHttpChannel *iface, cpp_bool aAllowTLS)
1387 nsChannel *This = impl_from_nsIHttpChannel(iface);
1388 FIXME("(%p)->(%x)\n", This, aAllowTLS);
1389 return NS_ERROR_NOT_IMPLEMENTED;
1392 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, UINT32 *aRedirectionLimit)
1394 nsChannel *This = impl_from_nsIHttpChannel(iface);
1396 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1398 return NS_ERROR_NOT_IMPLEMENTED;
1401 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, UINT32 aRedirectionLimit)
1403 nsChannel *This = impl_from_nsIHttpChannel(iface);
1405 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1407 return NS_ERROR_NOT_IMPLEMENTED;
1410 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, UINT32 *aResponseStatus)
1412 nsChannel *This = impl_from_nsIHttpChannel(iface);
1414 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1416 if(This->response_status) {
1417 *aResponseStatus = This->response_status;
1418 return NS_OK;
1421 WARN("No response status\n");
1422 return NS_ERROR_UNEXPECTED;
1425 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1426 nsACString *aResponseStatusText)
1428 nsChannel *This = impl_from_nsIHttpChannel(iface);
1430 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
1432 nsACString_SetData(aResponseStatusText, This->response_status_text);
1433 return NS_OK;
1436 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1437 cpp_bool *aRequestSucceeded)
1439 nsChannel *This = impl_from_nsIHttpChannel(iface);
1441 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1443 if(!This->response_status)
1444 return NS_ERROR_NOT_AVAILABLE;
1446 *aRequestSucceeded = This->response_status/100 == 2;
1448 return NS_OK;
1451 static nsresult NSAPI nsChannel_GetIsMainDocumentChannel(nsIHttpChannel *iface, cpp_bool *aIsMainDocumentChannel)
1453 nsChannel *This = impl_from_nsIHttpChannel(iface);
1454 FIXME("(%p)->(%p)\n", This, aIsMainDocumentChannel);
1455 return NS_ERROR_NOT_IMPLEMENTED;
1458 static nsresult NSAPI nsChannel_SetIsMainDocumentChannel(nsIHttpChannel *iface, cpp_bool aIsMainDocumentChannel)
1460 nsChannel *This = impl_from_nsIHttpChannel(iface);
1461 FIXME("(%p)->(%x)\n", This, aIsMainDocumentChannel);
1462 return NS_ERROR_NOT_IMPLEMENTED;
1465 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1466 const nsACString *header, nsACString *_retval)
1468 nsChannel *This = impl_from_nsIHttpChannel(iface);
1470 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1472 return get_channel_http_header(&This->response_headers, header, _retval);
1475 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1476 const nsACString *header, const nsACString *value, cpp_bool merge)
1478 nsChannel *This = impl_from_nsIHttpChannel(iface);
1480 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1482 return NS_ERROR_NOT_IMPLEMENTED;
1485 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1486 nsIHttpHeaderVisitor *aVisitor)
1488 nsChannel *This = impl_from_nsIHttpChannel(iface);
1490 TRACE("(%p)->(%p)\n", This, aVisitor);
1492 return visit_http_headers(&This->response_headers, aVisitor);
1495 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1497 nsChannel *This = impl_from_nsIHttpChannel(iface);
1498 http_header_t *header;
1500 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1501 static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
1503 TRACE("(%p)->(%p)\n", This, _retval);
1505 header = find_http_header(&This->response_headers, cache_controlW, sizeof(cache_controlW)/sizeof(WCHAR));
1506 *_retval = header && !strcmpiW(header->data, no_storeW);
1507 return NS_OK;
1510 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1512 nsChannel *This = impl_from_nsIHttpChannel(iface);
1514 FIXME("(%p)->(%p)\n", This, _retval);
1516 return NS_ERROR_NOT_IMPLEMENTED;
1519 static nsresult NSAPI nsChannel_IsPrivateResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1521 nsChannel *This = impl_from_nsIHttpChannel(iface);
1523 FIXME("(%p)->(%p)\n", This, _retval);
1525 return NS_ERROR_NOT_IMPLEMENTED;
1528 static nsresult NSAPI nsChannel_RedirectTo(nsIHttpChannel *iface, nsIURI *aNewURI)
1530 nsChannel *This = impl_from_nsIHttpChannel(iface);
1532 FIXME("(%p)->(%p)\n", This, aNewURI);
1534 return NS_ERROR_NOT_IMPLEMENTED;
1537 static nsresult NSAPI nsHttpChannel_GetSchedulingContextID(nsIHttpChannel *iface, nsIID *aSchedulingContextID)
1539 nsChannel *This = impl_from_nsIHttpChannel(iface);
1541 FIXME("(%p)->(%p)\n", This, aSchedulingContextID);
1543 return NS_ERROR_NOT_IMPLEMENTED;
1546 static nsresult NSAPI nsHttpChannel_SetSchedulingContextID(nsIHttpChannel *iface, const nsIID aSchedulingContextID)
1548 nsChannel *This = impl_from_nsIHttpChannel(iface);
1550 FIXME("(%p)->(%s)\n", This, debugstr_guid(&aSchedulingContextID));
1552 return NS_ERROR_NOT_IMPLEMENTED;
1555 static const nsIHttpChannelVtbl nsChannelVtbl = {
1556 nsChannel_QueryInterface,
1557 nsChannel_AddRef,
1558 nsChannel_Release,
1559 nsChannel_GetName,
1560 nsChannel_IsPending,
1561 nsChannel_GetStatus,
1562 nsChannel_Cancel,
1563 nsChannel_Suspend,
1564 nsChannel_Resume,
1565 nsChannel_GetLoadGroup,
1566 nsChannel_SetLoadGroup,
1567 nsChannel_GetLoadFlags,
1568 nsChannel_SetLoadFlags,
1569 nsChannel_GetOriginalURI,
1570 nsChannel_SetOriginalURI,
1571 nsChannel_GetURI,
1572 nsChannel_GetOwner,
1573 nsChannel_SetOwner,
1574 nsChannel_GetNotificationCallbacks,
1575 nsChannel_SetNotificationCallbacks,
1576 nsChannel_GetSecurityInfo,
1577 nsChannel_GetContentType,
1578 nsChannel_SetContentType,
1579 nsChannel_GetContentCharset,
1580 nsChannel_SetContentCharset,
1581 nsChannel_GetContentLength,
1582 nsChannel_SetContentLength,
1583 nsChannel_Open,
1584 nsChannel_Open2,
1585 nsChannel_AsyncOpen,
1586 nsChannel_AsyncOpen2,
1587 nsChannel_GetContentDisposition,
1588 nsChannel_SetContentDisposition,
1589 nsChannel_GetContentDispositionFilename,
1590 nsChannel_SetContentDispositionFilename,
1591 nsChannel_GetContentDispositionHeader,
1592 nsChannel_GetLoadInfo,
1593 nsChannel_SetLoadInfo,
1594 nsChannel_GetRequestMethod,
1595 nsChannel_SetRequestMethod,
1596 nsChannel_GetReferrer,
1597 nsChannel_SetReferrer,
1598 nsChannel_GetReferrerPolicy,
1599 nsChannel_SetReferrerWithPolicy,
1600 nsChannel_GetRequestHeader,
1601 nsChannel_SetRequestHeader,
1602 nsChannel_SetEmptyRequestHeader,
1603 nsChannel_VisitRequestHeaders,
1604 nsChannel_VisitNonDefaultRequestHeaders,
1605 nsChannel_GetAllowPipelining,
1606 nsChannel_SetAllowPipelining,
1607 nsChannel_GetAllowTLS,
1608 nsChannel_SetAllowTLS,
1609 nsChannel_GetRedirectionLimit,
1610 nsChannel_SetRedirectionLimit,
1611 nsChannel_GetResponseStatus,
1612 nsChannel_GetResponseStatusText,
1613 nsChannel_GetRequestSucceeded,
1614 nsChannel_GetIsMainDocumentChannel,
1615 nsChannel_SetIsMainDocumentChannel,
1616 nsChannel_GetResponseHeader,
1617 nsChannel_SetResponseHeader,
1618 nsChannel_VisitResponseHeaders,
1619 nsChannel_IsNoStoreResponse,
1620 nsChannel_IsNoCacheResponse,
1621 nsChannel_IsPrivateResponse,
1622 nsChannel_RedirectTo,
1623 nsHttpChannel_GetSchedulingContextID,
1624 nsHttpChannel_SetSchedulingContextID
1627 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1629 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1632 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1633 void **result)
1635 nsChannel *This = impl_from_nsIUploadChannel(iface);
1636 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1639 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1641 nsChannel *This = impl_from_nsIUploadChannel(iface);
1642 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1645 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1647 nsChannel *This = impl_from_nsIUploadChannel(iface);
1648 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1651 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1652 nsIInputStream *aStream, const nsACString *aContentType, INT64 aContentLength)
1654 nsChannel *This = impl_from_nsIUploadChannel(iface);
1655 const char *content_type;
1657 static const WCHAR content_typeW[] =
1658 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1660 TRACE("(%p)->(%p %s %s)\n", This, aStream, debugstr_nsacstr(aContentType), wine_dbgstr_longlong(aContentLength));
1662 This->post_data_contains_headers = TRUE;
1664 if(aContentType) {
1665 nsACString_GetData(aContentType, &content_type);
1666 if(*content_type) {
1667 WCHAR *ct;
1669 ct = heap_strdupAtoW(content_type);
1670 if(!ct)
1671 return NS_ERROR_UNEXPECTED;
1673 set_http_header(&This->request_headers, content_typeW,
1674 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1675 heap_free(ct);
1676 This->post_data_contains_headers = FALSE;
1680 if(aContentLength != -1)
1681 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength));
1683 if(This->post_data_stream)
1684 nsIInputStream_Release(This->post_data_stream);
1685 This->post_data_stream = aStream;
1686 if(aStream)
1687 nsIInputStream_AddRef(aStream);
1689 This->request_method = METHOD_POST;
1690 return NS_OK;
1693 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1694 nsIInputStream **aUploadStream)
1696 nsChannel *This = impl_from_nsIUploadChannel(iface);
1698 TRACE("(%p)->(%p)\n", This, aUploadStream);
1700 if(This->post_data_stream)
1701 nsIInputStream_AddRef(This->post_data_stream);
1703 *aUploadStream = This->post_data_stream;
1704 return NS_OK;
1707 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1708 nsUploadChannel_QueryInterface,
1709 nsUploadChannel_AddRef,
1710 nsUploadChannel_Release,
1711 nsUploadChannel_SetUploadStream,
1712 nsUploadChannel_GetUploadStream
1715 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1717 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1720 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1721 void **result)
1723 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1724 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1727 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1729 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1730 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1733 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1735 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1736 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1739 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1741 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1743 FIXME("(%p)->()\n", This);
1745 return NS_ERROR_NOT_IMPLEMENTED;
1748 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1750 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1752 FIXME("(%p)->()\n", This);
1754 return NS_ERROR_NOT_IMPLEMENTED;
1757 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1759 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1761 FIXME("(%p)->()\n", This);
1763 return NS_ERROR_NOT_IMPLEMENTED;
1766 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1768 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1770 FIXME("(%p)->()\n", This);
1772 return NS_ERROR_NOT_IMPLEMENTED;
1775 static nsresult NSAPI nsHttpChannelInternal_TakeAllSecurityMessages(nsIHttpChannelInternal *iface, void *aMessages)
1777 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1779 FIXME("(%p)->()\n", This);
1781 return NS_ERROR_NOT_IMPLEMENTED;
1784 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1786 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1788 FIXME("(%p)->()\n", This);
1790 return NS_ERROR_NOT_IMPLEMENTED;
1793 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1795 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1797 FIXME("(%p)->()\n", This);
1799 return NS_ERROR_NOT_IMPLEMENTED;
1802 static nsresult NSAPI nsHttpChannelInternal_GetThirdPartyFlags(nsIHttpChannelInternal *iface, UINT32 *aThirdPartyFlags)
1804 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1805 FIXME("(%p)->(%p)\n", This, aThirdPartyFlags);
1806 return NS_ERROR_NOT_IMPLEMENTED;
1809 static nsresult NSAPI nsHttpChannelInternal_SetThirdPartyFlags(nsIHttpChannelInternal *iface, UINT32 aThirdPartyFlags)
1811 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1812 FIXME("(%p)->(%x)\n", This, aThirdPartyFlags);
1813 return NS_ERROR_NOT_IMPLEMENTED;
1816 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1818 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1820 FIXME("(%p)->()\n", This);
1822 return NS_ERROR_NOT_IMPLEMENTED;
1825 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1827 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1829 FIXME("(%p)->()\n", This);
1831 return NS_ERROR_NOT_IMPLEMENTED;
1834 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1836 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1838 FIXME("(%p)->(%p)\n", This, aCanceled);
1840 return NS_ERROR_NOT_IMPLEMENTED;
1843 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1845 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1847 FIXME("(%p)->(%p)\n", This, aCanceled);
1849 return NS_ERROR_NOT_IMPLEMENTED;
1852 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1854 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1856 FIXME("(%p)->(%x)\n", This, aCanceled);
1858 return NS_ERROR_NOT_IMPLEMENTED;
1861 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1863 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1865 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1867 return NS_ERROR_NOT_IMPLEMENTED;
1870 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, LONG *aLocalPort)
1872 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1874 FIXME("(%p)->(%p)\n", This, aLocalPort);
1876 return NS_ERROR_NOT_IMPLEMENTED;
1879 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1881 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1883 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1885 return NS_ERROR_NOT_IMPLEMENTED;
1888 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, LONG *aRemotePort)
1890 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1892 FIXME("(%p)->(%p)\n", This, aRemotePort);
1894 return NS_ERROR_NOT_IMPLEMENTED;
1897 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1899 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1901 FIXME("(%p)->(%p)\n", This, cacheKeys);
1903 return NS_ERROR_NOT_IMPLEMENTED;
1906 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1907 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1909 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1910 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1911 return NS_ERROR_NOT_IMPLEMENTED;
1914 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1916 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1917 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1918 return NS_ERROR_NOT_IMPLEMENTED;
1921 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1923 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1924 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1925 return NS_ERROR_NOT_IMPLEMENTED;
1928 static nsresult NSAPI nsHttpChannelInternal_GetResponseTimeoutEnabled(nsIHttpChannelInternal *iface,
1929 cpp_bool *aResponseTimeoutEnabled)
1931 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1932 FIXME("(%p)->(%p)\n", This, aResponseTimeoutEnabled);
1933 return NS_ERROR_NOT_IMPLEMENTED;
1936 static nsresult NSAPI nsHttpChannelInternal_SetResponseTimeoutEnabled(nsIHttpChannelInternal *iface,
1937 cpp_bool aResponseTimeoutEnabled)
1939 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1940 FIXME("(%p)->(%x)\n", This, aResponseTimeoutEnabled);
1941 return NS_ERROR_NOT_IMPLEMENTED;
1944 static nsresult NSAPI nsHttpChannelInternal_GetInitialRwin(nsIHttpChannelInternal *iface,
1945 UINT32 *aInitialRwin)
1947 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1948 FIXME("(%p)->(%p)\n", This, aInitialRwin);
1949 return NS_ERROR_NOT_IMPLEMENTED;
1952 static nsresult NSAPI nsHttpChannelInternal_SetInitialRwin(nsIHttpChannelInternal *iface,
1953 UINT32 aInitialRwin)
1955 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1956 FIXME("(%p)->(%x)\n", This, aInitialRwin);
1957 return NS_ERROR_NOT_IMPLEMENTED;
1960 static nsresult NSAPI nsHttpChannelInternal_GetApiRedirectToURI(nsIHttpChannelInternal *iface, nsIURI **aApiRedirectToURI)
1962 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1963 FIXME("(%p)->(%p)\n", This, aApiRedirectToURI);
1964 return NS_ERROR_NOT_IMPLEMENTED;
1967 static nsresult NSAPI nsHttpChannelInternal_GetAllowAltSvc(nsIHttpChannelInternal *iface, cpp_bool *aAllowAltSvc)
1969 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1970 FIXME("(%p)->(%p)\n", This, aAllowAltSvc);
1971 return NS_ERROR_NOT_IMPLEMENTED;
1974 static nsresult NSAPI nsHttpChannelInternal_SetAllowAltSvc(nsIHttpChannelInternal *iface, cpp_bool aAllowAltSvc)
1976 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1977 FIXME("(%p)->(%x)\n", This, aAllowAltSvc);
1978 return NS_ERROR_NOT_IMPLEMENTED;
1981 static nsresult NSAPI nsHttpChannelInternal_GetLastModifiedTime(nsIHttpChannelInternal *iface, PRTime *aLastModifiedTime)
1983 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1984 FIXME("(%p)->(%p)\n", This, aLastModifiedTime);
1985 return NS_ERROR_NOT_IMPLEMENTED;
1988 static nsresult NSAPI nsHttpChannelInternal_ForceIntercepted(nsIHttpChannelInternal *iface, UINT64 aInterceptionID)
1990 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1991 FIXME("(%p)->(%s)\n", This, wine_dbgstr_longlong(aInterceptionID));
1992 return NS_ERROR_NOT_IMPLEMENTED;
1995 static nsresult NSAPI nsHttpChannelInternal_GetResponseSynthesized(nsIHttpChannelInternal *iface, cpp_bool *ResponseSynthesized)
1997 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1998 FIXME("(%p, %p)\n", This, ResponseSynthesized);
1999 return NS_ERROR_NOT_IMPLEMENTED;
2002 static nsresult NSAPI nsHttpChannelInternal_GetCorsIncludeCredentials(nsIHttpChannelInternal *iface,
2003 cpp_bool *aCorsIncludeCredentials)
2005 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2006 FIXME("(%p)->(%p)\n", This, aCorsIncludeCredentials);
2007 return NS_ERROR_NOT_IMPLEMENTED;
2010 static nsresult NSAPI nsHttpChannelInternal_SetCorsIncludeCredentials(nsIHttpChannelInternal *iface,
2011 cpp_bool aCorsIncludeCredentials)
2013 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2014 TRACE("(%p)->(%x)\n", This, aCorsIncludeCredentials);
2015 return NS_OK;
2018 static nsresult NSAPI nsHttpChannelInternal_GetCorsMode(nsIHttpChannelInternal *iface, UINT32 *aCorsMode)
2020 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2021 FIXME("(%p)->(%p)\n", This, aCorsMode);
2022 return NS_ERROR_NOT_IMPLEMENTED;
2025 static nsresult NSAPI nsHttpChannelInternal_SetCorsMode(nsIHttpChannelInternal *iface, UINT32 aCorsMode)
2027 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2028 TRACE("(%p)->(%d)\n", This, aCorsMode);
2029 return NS_OK;
2032 static nsresult NSAPI nsHttpChannelInternal_GetRedirectMode(nsIHttpChannelInternal *iface, UINT32 *aRedirectMode)
2034 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2035 FIXME("(%p)->(%p)\n", This, aRedirectMode);
2036 return NS_ERROR_NOT_IMPLEMENTED;
2039 static nsresult NSAPI nsHttpChannelInternal_SetRedirectMode(nsIHttpChannelInternal *iface, UINT32 aRedirectMode)
2041 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2042 FIXME("(%p)->(%d)\n", This, aRedirectMode);
2043 return NS_ERROR_NOT_IMPLEMENTED;
2046 static nsresult NSAPI nsHttpChannelInternal_GetTopWindowURI(nsIHttpChannelInternal *iface, nsIURI **aTopWindowURI)
2048 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2049 FIXME("(%p)->(%p)\n", This, aTopWindowURI);
2050 return NS_ERROR_NOT_IMPLEMENTED;
2053 static nsresult NSAPI nsHttpChannelInternal_GetNetworkInterfaceId(nsIHttpChannelInternal *iface,
2054 nsACString *aNetworkInterfaceId)
2056 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2057 FIXME("(%p)->(%p)\n", This, aNetworkInterfaceId);
2058 return NS_ERROR_NOT_IMPLEMENTED;
2061 static nsresult NSAPI nsHttpChannelInternal_SetNetworkInterfaceId(nsIHttpChannelInternal *iface,
2062 const nsACString *aNetworkInterfaceId)
2064 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2065 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aNetworkInterfaceId));
2066 return NS_ERROR_NOT_IMPLEMENTED;
2069 static nsresult NSAPI nsHttpChannelInternal_GetProxyURI(nsIHttpChannelInternal *iface, nsIURI **aProxyURI)
2071 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2072 FIXME("(%p)->(%p)\n", This, aProxyURI);
2073 return NS_ERROR_NOT_IMPLEMENTED;
2076 static nsresult NSAPI nsHttpChannelInternal_SetCorsPreflightParameters(nsIHttpChannelInternal *iface,
2077 const void /*nsTArray<nsCString>*/ *unsafeHeaders, cpp_bool withCredentials, nsIPrincipal *preflightPrincipal)
2079 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2080 FIXME("(%p %p %x %p)\n", This, unsafeHeaders, withCredentials, preflightPrincipal);
2081 return NS_ERROR_NOT_IMPLEMENTED;
2084 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
2085 nsHttpChannelInternal_QueryInterface,
2086 nsHttpChannelInternal_AddRef,
2087 nsHttpChannelInternal_Release,
2088 nsHttpChannelInternal_GetDocumentURI,
2089 nsHttpChannelInternal_SetDocumentURI,
2090 nsHttpChannelInternal_GetRequestVersion,
2091 nsHttpChannelInternal_GetResponseVersion,
2092 nsHttpChannelInternal_TakeAllSecurityMessages,
2093 nsHttpChannelInternal_SetCookie,
2094 nsHttpChannelInternal_SetupFallbackChannel,
2095 nsHttpChannelInternal_GetThirdPartyFlags,
2096 nsHttpChannelInternal_SetThirdPartyFlags,
2097 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
2098 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
2099 nsHttpChannelInternal_GetCanceled,
2100 nsHttpChannelInternal_GetChannelIsForDownload,
2101 nsHttpChannelInternal_SetChannelIsForDownload,
2102 nsHttpChannelInternal_GetLocalAddress,
2103 nsHttpChannelInternal_GetLocalPort,
2104 nsHttpChannelInternal_GetRemoteAddress,
2105 nsHttpChannelInternal_GetRemotePort,
2106 nsHttpChannelInternal_SetCacheKeysRedirectChain,
2107 nsHttpChannelInternal_HTTPUpgrade,
2108 nsHttpChannelInternal_GetAllowSpdy,
2109 nsHttpChannelInternal_SetAllowSpdy,
2110 nsHttpChannelInternal_GetResponseTimeoutEnabled,
2111 nsHttpChannelInternal_SetResponseTimeoutEnabled,
2112 nsHttpChannelInternal_GetInitialRwin,
2113 nsHttpChannelInternal_SetInitialRwin,
2114 nsHttpChannelInternal_GetApiRedirectToURI,
2115 nsHttpChannelInternal_GetAllowAltSvc,
2116 nsHttpChannelInternal_SetAllowAltSvc,
2117 nsHttpChannelInternal_GetLastModifiedTime,
2118 nsHttpChannelInternal_ForceIntercepted,
2119 nsHttpChannelInternal_GetResponseSynthesized,
2120 nsHttpChannelInternal_GetCorsIncludeCredentials,
2121 nsHttpChannelInternal_SetCorsIncludeCredentials,
2122 nsHttpChannelInternal_GetCorsMode,
2123 nsHttpChannelInternal_SetCorsMode,
2124 nsHttpChannelInternal_GetRedirectMode,
2125 nsHttpChannelInternal_SetRedirectMode,
2126 nsHttpChannelInternal_GetTopWindowURI,
2127 nsHttpChannelInternal_GetNetworkInterfaceId,
2128 nsHttpChannelInternal_SetNetworkInterfaceId,
2129 nsHttpChannelInternal_GetProxyURI,
2130 nsHttpChannelInternal_SetCorsPreflightParameters
2134 static void invalidate_uri(nsWineURI *This)
2136 if(This->uri) {
2137 IUri_Release(This->uri);
2138 This->uri = NULL;
2142 static BOOL ensure_uri_builder(nsWineURI *This)
2144 if(!This->is_mutable) {
2145 WARN("Not mutable URI\n");
2146 return FALSE;
2149 if(!This->uri_builder) {
2150 HRESULT hres;
2152 if(!ensure_uri(This))
2153 return FALSE;
2155 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
2156 if(FAILED(hres)) {
2157 WARN("CreateIUriBuilder failed: %08x\n", hres);
2158 return FALSE;
2162 invalidate_uri(This);
2163 return TRUE;
2166 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
2168 char *vala;
2169 BSTR val;
2170 HRESULT hres;
2172 if(!ensure_uri(This))
2173 return NS_ERROR_UNEXPECTED;
2175 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
2176 if(FAILED(hres)) {
2177 WARN("GetPropertyBSTR failed: %08x\n", hres);
2178 return NS_ERROR_UNEXPECTED;
2181 vala = heap_strdupWtoU(val);
2182 SysFreeString(val);
2183 if(!vala)
2184 return NS_ERROR_OUT_OF_MEMORY;
2186 TRACE("ret %s\n", debugstr_a(vala));
2187 nsACString_SetData(ret, vala);
2188 heap_free(vala);
2189 return NS_OK;
2192 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
2194 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
2197 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
2199 nsWineURI *This = impl_from_nsIFileURL(iface);
2201 *result = NULL;
2203 if(IsEqualGUID(&IID_nsISupports, riid)) {
2204 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2205 *result = &This->nsIFileURL_iface;
2206 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
2207 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
2208 *result = &This->nsIFileURL_iface;
2209 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
2210 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
2211 *result = &This->nsIFileURL_iface;
2212 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
2213 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
2214 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
2215 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
2216 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
2217 *result = &This->nsIStandardURL_iface;
2218 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
2219 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
2220 *result = &This->nsIStandardURL_iface;
2221 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
2222 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
2223 *result = This;
2226 if(*result) {
2227 nsIFileURL_AddRef(&This->nsIFileURL_iface);
2228 return NS_OK;
2231 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
2232 return NS_NOINTERFACE;
2235 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
2237 nsWineURI *This = impl_from_nsIFileURL(iface);
2238 LONG ref = InterlockedIncrement(&This->ref);
2240 TRACE("(%p) ref=%d\n", This, ref);
2242 return ref;
2245 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
2247 nsWineURI *This = impl_from_nsIFileURL(iface);
2248 LONG ref = InterlockedDecrement(&This->ref);
2250 TRACE("(%p) ref=%d\n", This, ref);
2252 if(!ref) {
2253 if(This->window_ref)
2254 windowref_release(This->window_ref);
2255 if(This->container)
2256 nsIWebBrowserChrome_Release(&This->container->nsIWebBrowserChrome_iface);
2257 if(This->uri)
2258 IUri_Release(This->uri);
2259 heap_free(This->origin_charset);
2260 heap_free(This);
2263 return ref;
2266 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
2268 nsWineURI *This = impl_from_nsIFileURL(iface);
2270 TRACE("(%p)->(%p)\n", This, aSpec);
2272 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
2275 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
2277 nsWineURI *This = impl_from_nsIFileURL(iface);
2278 const char *speca;
2279 WCHAR *spec;
2280 IUri *uri;
2281 HRESULT hres;
2283 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
2285 if(!This->is_mutable)
2286 return NS_ERROR_UNEXPECTED;
2288 nsACString_GetData(aSpec, &speca);
2289 spec = heap_strdupUtoW(speca);
2290 if(!spec)
2291 return NS_ERROR_OUT_OF_MEMORY;
2293 hres = create_uri(spec, 0, &uri);
2294 heap_free(spec);
2295 if(FAILED(hres)) {
2296 WARN("create_uri failed: %08x\n", hres);
2297 return NS_ERROR_FAILURE;
2300 invalidate_uri(This);
2301 if(This->uri_builder) {
2302 IUriBuilder_Release(This->uri_builder);
2303 This->uri_builder = NULL;
2306 This->uri = uri;
2307 return NS_OK;
2310 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
2312 nsWineURI *This = impl_from_nsIFileURL(iface);
2313 IUriBuilder *uri_builder;
2314 BSTR display_uri;
2315 IUri *uri;
2316 int len;
2317 nsresult nsres;
2318 HRESULT hres;
2320 TRACE("(%p)->(%p)\n", This, aPrePath);
2322 if(!ensure_uri(This))
2323 return NS_ERROR_UNEXPECTED;
2325 hres = CreateIUriBuilder(This->uri, 0, 0, &uri_builder);
2326 if(FAILED(hres))
2327 return NS_ERROR_FAILURE;
2329 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_PATH|Uri_HAS_QUERY|Uri_HAS_FRAGMENT);
2330 if(SUCCEEDED(hres))
2331 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &uri);
2332 IUriBuilder_Release(uri_builder);
2333 if(FAILED(hres))
2334 return NS_ERROR_FAILURE;
2336 hres = IUri_GetDisplayUri(uri, &display_uri);
2337 IUri_Release(uri);
2338 if(FAILED(hres))
2339 return NS_ERROR_FAILURE;
2341 /* Remove trailing slash that may be appended as default path. */
2342 len = SysStringLen(display_uri);
2343 if(len && display_uri[len-1] == '/')
2344 display_uri[len-1] = 0;
2346 nsres = return_wstr_nsacstr(aPrePath, display_uri, -1);
2347 SysFreeString(display_uri);
2348 return nsres;
2351 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
2353 nsWineURI *This = impl_from_nsIFileURL(iface);
2354 DWORD scheme;
2355 HRESULT hres;
2357 TRACE("(%p)->(%p)\n", This, aScheme);
2359 if(!ensure_uri(This))
2360 return NS_ERROR_UNEXPECTED;
2362 hres = IUri_GetScheme(This->uri, &scheme);
2363 if(FAILED(hres)) {
2364 WARN("GetScheme failed: %08x\n", hres);
2365 return NS_ERROR_UNEXPECTED;
2368 if(scheme == URL_SCHEME_ABOUT) {
2369 nsACString_SetData(aScheme, "wine");
2370 return NS_OK;
2373 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
2376 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
2378 nsWineURI *This = impl_from_nsIFileURL(iface);
2379 const char *schemea;
2380 WCHAR *scheme;
2381 HRESULT hres;
2383 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
2385 if(!ensure_uri_builder(This))
2386 return NS_ERROR_UNEXPECTED;
2388 nsACString_GetData(aScheme, &schemea);
2389 scheme = heap_strdupUtoW(schemea);
2390 if(!scheme)
2391 return NS_ERROR_OUT_OF_MEMORY;
2393 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
2394 heap_free(scheme);
2395 if(FAILED(hres))
2396 return NS_ERROR_UNEXPECTED;
2398 return NS_OK;
2401 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
2403 nsWineURI *This = impl_from_nsIFileURL(iface);
2404 BSTR user, pass;
2405 HRESULT hres;
2407 TRACE("(%p)->(%p)\n", This, aUserPass);
2409 if(!ensure_uri(This))
2410 return NS_ERROR_UNEXPECTED;
2412 hres = IUri_GetUserName(This->uri, &user);
2413 if(FAILED(hres))
2414 return NS_ERROR_FAILURE;
2416 hres = IUri_GetPassword(This->uri, &pass);
2417 if(FAILED(hres)) {
2418 SysFreeString(user);
2419 return NS_ERROR_FAILURE;
2422 if(*user || *pass) {
2423 FIXME("Construct user:pass string\n");
2424 }else {
2425 nsACString_SetData(aUserPass, "");
2428 SysFreeString(user);
2429 SysFreeString(pass);
2430 return NS_OK;
2433 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
2435 nsWineURI *This = impl_from_nsIFileURL(iface);
2436 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
2437 const char *user_pass;
2438 HRESULT hres;
2440 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
2442 if(!ensure_uri_builder(This))
2443 return NS_ERROR_UNEXPECTED;
2445 nsACString_GetData(aUserPass, &user_pass);
2446 if(*user_pass) {
2447 WCHAR *ptr;
2449 buf = heap_strdupUtoW(user_pass);
2450 if(!buf)
2451 return NS_ERROR_OUT_OF_MEMORY;
2453 ptr = strchrW(buf, ':');
2454 if(!ptr) {
2455 user = buf;
2456 }else if(ptr != buf) {
2457 *ptr++ = 0;
2458 user = buf;
2459 if(*ptr)
2460 pass = ptr;
2461 }else {
2462 pass = buf+1;
2466 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2467 if(SUCCEEDED(hres))
2468 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2470 heap_free(buf);
2471 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2474 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2476 nsWineURI *This = impl_from_nsIFileURL(iface);
2478 TRACE("(%p)->(%p)\n", This, aUsername);
2480 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2483 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2485 nsWineURI *This = impl_from_nsIFileURL(iface);
2486 const char *usera;
2487 WCHAR *user;
2488 HRESULT hres;
2490 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2492 if(!ensure_uri_builder(This))
2493 return NS_ERROR_UNEXPECTED;
2495 nsACString_GetData(aUsername, &usera);
2496 user = heap_strdupUtoW(usera);
2497 if(!user)
2498 return NS_ERROR_OUT_OF_MEMORY;
2500 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2501 heap_free(user);
2502 if(FAILED(hres))
2503 return NS_ERROR_UNEXPECTED;
2505 return NS_OK;
2508 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2510 nsWineURI *This = impl_from_nsIFileURL(iface);
2512 TRACE("(%p)->(%p)\n", This, aPassword);
2514 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2517 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2519 nsWineURI *This = impl_from_nsIFileURL(iface);
2520 const char *passa;
2521 WCHAR *pass;
2522 HRESULT hres;
2524 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2526 if(!ensure_uri_builder(This))
2527 return NS_ERROR_UNEXPECTED;
2529 nsACString_GetData(aPassword, &passa);
2530 pass = heap_strdupUtoW(passa);
2531 if(!pass)
2532 return NS_ERROR_OUT_OF_MEMORY;
2534 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2535 heap_free(pass);
2536 if(FAILED(hres))
2537 return NS_ERROR_UNEXPECTED;
2539 return NS_OK;
2542 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2544 nsWineURI *This = impl_from_nsIFileURL(iface);
2545 const WCHAR *ptr;
2546 char *vala;
2547 BSTR val;
2548 HRESULT hres;
2550 TRACE("(%p)->(%p)\n", This, aHostPort);
2552 if(!ensure_uri(This))
2553 return NS_ERROR_UNEXPECTED;
2555 hres = IUri_GetAuthority(This->uri, &val);
2556 if(FAILED(hres)) {
2557 WARN("GetAuthority failed: %08x\n", hres);
2558 return NS_ERROR_UNEXPECTED;
2561 ptr = strchrW(val, '@');
2562 if(!ptr)
2563 ptr = val;
2565 vala = heap_strdupWtoU(ptr);
2566 SysFreeString(val);
2567 if(!vala)
2568 return NS_ERROR_OUT_OF_MEMORY;
2570 TRACE("ret %s\n", debugstr_a(vala));
2571 nsACString_SetData(aHostPort, vala);
2572 heap_free(vala);
2573 return NS_OK;
2576 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2578 nsWineURI *This = impl_from_nsIFileURL(iface);
2580 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2582 /* Not implemented by Gecko */
2583 return NS_ERROR_NOT_IMPLEMENTED;
2586 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2588 nsWineURI *This = impl_from_nsIFileURL(iface);
2590 TRACE("(%p)->(%p)\n", This, aHost);
2592 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2595 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2597 nsWineURI *This = impl_from_nsIFileURL(iface);
2598 const char *hosta;
2599 WCHAR *host;
2600 HRESULT hres;
2602 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2604 if(!ensure_uri_builder(This))
2605 return NS_ERROR_UNEXPECTED;
2607 nsACString_GetData(aHost, &hosta);
2608 host = heap_strdupUtoW(hosta);
2609 if(!host)
2610 return NS_ERROR_OUT_OF_MEMORY;
2612 hres = IUriBuilder_SetHost(This->uri_builder, host);
2613 heap_free(host);
2614 if(FAILED(hres))
2615 return NS_ERROR_UNEXPECTED;
2617 return NS_OK;
2620 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, LONG *aPort)
2622 nsWineURI *This = impl_from_nsIFileURL(iface);
2623 DWORD port;
2624 HRESULT hres;
2626 TRACE("(%p)->(%p)\n", This, aPort);
2628 if(!ensure_uri(This))
2629 return NS_ERROR_UNEXPECTED;
2631 hres = IUri_GetPort(This->uri, &port);
2632 if(FAILED(hres)) {
2633 WARN("GetPort failed: %08x\n", hres);
2634 return NS_ERROR_UNEXPECTED;
2637 *aPort = port ? port : -1;
2638 return NS_OK;
2641 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, LONG aPort)
2643 nsWineURI *This = impl_from_nsIFileURL(iface);
2644 HRESULT hres;
2646 TRACE("(%p)->(%d)\n", This, aPort);
2648 if(!ensure_uri_builder(This))
2649 return NS_ERROR_UNEXPECTED;
2651 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2652 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2655 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2657 nsWineURI *This = impl_from_nsIFileURL(iface);
2659 TRACE("(%p)->(%p)\n", This, aPath);
2661 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2664 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2666 nsWineURI *This = impl_from_nsIFileURL(iface);
2667 const char *patha;
2668 WCHAR *path;
2669 HRESULT hres;
2671 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2673 if(!ensure_uri_builder(This))
2674 return NS_ERROR_UNEXPECTED;
2676 nsACString_GetData(aPath, &patha);
2677 path = heap_strdupUtoW(patha);
2678 if(!path)
2679 return NS_ERROR_OUT_OF_MEMORY;
2681 hres = IUriBuilder_SetPath(This->uri_builder, path);
2682 heap_free(path);
2683 if(FAILED(hres))
2684 return NS_ERROR_UNEXPECTED;
2686 return NS_OK;
2689 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2691 nsWineURI *This = impl_from_nsIFileURL(iface);
2692 nsWineURI *other_obj;
2693 nsresult nsres;
2694 HRESULT hres;
2696 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2698 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2699 if(NS_FAILED(nsres)) {
2700 TRACE("Could not get nsWineURI interface\n");
2701 *_retval = FALSE;
2702 return NS_OK;
2705 if(ensure_uri(This) && ensure_uri(other_obj)) {
2706 BOOL b;
2708 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2709 if(SUCCEEDED(hres)) {
2710 *_retval = b;
2711 nsres = NS_OK;
2712 }else {
2713 nsres = NS_ERROR_FAILURE;
2715 }else {
2716 nsres = NS_ERROR_UNEXPECTED;
2719 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2720 return nsres;
2723 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2725 nsWineURI *This = impl_from_nsIFileURL(iface);
2726 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2727 BSTR scheme_name;
2728 HRESULT hres;
2730 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2732 if(!ensure_uri(This))
2733 return NS_ERROR_UNEXPECTED;
2735 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2736 if(FAILED(hres))
2737 return NS_ERROR_UNEXPECTED;
2739 MultiByteToWideChar(CP_UTF8, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR));
2740 *_retval = !strcmpW(scheme_name, buf);
2741 SysFreeString(scheme_name);
2742 return NS_OK;
2745 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2747 nsWineURI *This = impl_from_nsIFileURL(iface);
2748 nsWineURI *wine_uri;
2749 nsresult nsres;
2751 TRACE("(%p)->(%p)\n", This, _retval);
2753 if(!ensure_uri(This))
2754 return NS_ERROR_UNEXPECTED;
2756 nsres = create_nsuri(This->uri, This->window_ref ? This->window_ref->window : NULL,
2757 This->container, This->origin_charset, &wine_uri);
2758 if(NS_FAILED(nsres)) {
2759 WARN("create_nsuri failed: %08x\n", nsres);
2760 return nsres;
2763 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2764 return NS_OK;
2767 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2768 nsACString *_retval)
2770 nsWineURI *This = impl_from_nsIFileURL(iface);
2771 const char *patha;
2772 IUri *new_uri;
2773 WCHAR *path;
2774 char *reta;
2775 BSTR ret;
2776 HRESULT hres;
2778 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2780 if(!ensure_uri(This))
2781 return NS_ERROR_UNEXPECTED;
2783 nsACString_GetData(aRelativePath, &patha);
2784 path = heap_strdupUtoW(patha);
2785 if(!path)
2786 return NS_ERROR_OUT_OF_MEMORY;
2788 hres = combine_url(This->uri, path, &new_uri);
2789 heap_free(path);
2790 if(FAILED(hres))
2791 return NS_ERROR_FAILURE;
2793 hres = IUri_GetDisplayUri(new_uri, &ret);
2794 IUri_Release(new_uri);
2795 if(FAILED(hres))
2796 return NS_ERROR_FAILURE;
2798 reta = heap_strdupWtoU(ret);
2799 SysFreeString(ret);
2800 if(!reta)
2801 return NS_ERROR_OUT_OF_MEMORY;
2803 TRACE("returning %s\n", debugstr_a(reta));
2804 nsACString_SetData(_retval, reta);
2805 heap_free(reta);
2806 return NS_OK;
2809 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2811 nsWineURI *This = impl_from_nsIFileURL(iface);
2813 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2815 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2818 static nsresult NSAPI nsURI_GetAsciiHostPort(nsIFileURL *iface, nsACString *aAsciiHostPort)
2820 nsWineURI *This = impl_from_nsIFileURL(iface);
2822 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHostPort);
2824 return nsIFileURL_GetHostPort(&This->nsIFileURL_iface, aAsciiHostPort);
2827 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2829 nsWineURI *This = impl_from_nsIFileURL(iface);
2831 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2833 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2836 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2838 nsWineURI *This = impl_from_nsIFileURL(iface);
2840 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2842 nsACString_SetData(aOriginCharset, This->origin_charset);
2843 return NS_OK;
2846 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2848 nsWineURI *This = impl_from_nsIFileURL(iface);
2849 char *refa = NULL;
2850 BSTR ref;
2851 HRESULT hres;
2853 TRACE("(%p)->(%p)\n", This, aRef);
2855 if(!ensure_uri(This))
2856 return NS_ERROR_UNEXPECTED;
2858 hres = IUri_GetFragment(This->uri, &ref);
2859 if(FAILED(hres))
2860 return NS_ERROR_UNEXPECTED;
2862 refa = heap_strdupWtoU(ref);
2863 SysFreeString(ref);
2864 if(ref && !refa)
2865 return NS_ERROR_OUT_OF_MEMORY;
2867 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2868 heap_free(refa);
2869 return NS_OK;
2872 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2874 nsWineURI *This = impl_from_nsIFileURL(iface);
2875 const char *refa;
2876 WCHAR *ref;
2877 HRESULT hres;
2879 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2881 if(!ensure_uri_builder(This))
2882 return NS_ERROR_UNEXPECTED;
2884 nsACString_GetData(aRef, &refa);
2885 ref = heap_strdupUtoW(refa);
2886 if(!ref)
2887 return NS_ERROR_OUT_OF_MEMORY;
2889 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2890 heap_free(ref);
2891 if(FAILED(hres))
2892 return NS_ERROR_UNEXPECTED;
2894 return NS_OK;
2897 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2899 nsWineURI *This = impl_from_nsIFileURL(iface);
2900 nsWineURI *other_obj;
2901 nsresult nsres;
2903 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2905 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2906 if(NS_FAILED(nsres)) {
2907 TRACE("Could not get nsWineURI interface\n");
2908 *_retval = FALSE;
2909 return NS_OK;
2912 if(ensure_uri(This) && ensure_uri(other_obj)) {
2913 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2914 nsres = NS_OK;
2915 }else {
2916 nsres = NS_ERROR_UNEXPECTED;
2919 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2920 return nsres;
2923 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2925 nsWineURI *This = impl_from_nsIFileURL(iface);
2926 nsWineURI *wine_uri;
2927 IUri *uri;
2928 nsresult nsres;
2930 TRACE("(%p)->(%p)\n", This, _retval);
2932 if(!ensure_uri(This))
2933 return NS_ERROR_UNEXPECTED;
2935 uri = get_uri_nofrag(This->uri);
2936 if(!uri)
2937 return NS_ERROR_FAILURE;
2939 nsres = create_nsuri(uri, This->window_ref ? This->window_ref->window : NULL, This->container,
2940 This->origin_charset, &wine_uri);
2941 IUri_Release(uri);
2942 if(NS_FAILED(nsres)) {
2943 WARN("create_nsuri failed: %08x\n", nsres);
2944 return nsres;
2947 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2948 return NS_OK;
2951 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2953 nsWineURI *This = impl_from_nsIFileURL(iface);
2955 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2957 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2960 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2962 nsWineURI *This = impl_from_nsIFileURL(iface);
2963 BOOL b;
2964 HRESULT hres;
2966 TRACE("(%p)->(%p)\n", This, aHasRef);
2968 if(!ensure_uri(This))
2969 return NS_ERROR_UNEXPECTED;
2971 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2972 if(FAILED(hres))
2973 return NS_ERROR_FAILURE;
2975 *aHasRef = b;
2976 return NS_OK;
2979 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2981 nsWineURI *This = impl_from_nsIFileURL(iface);
2983 TRACE("(%p)->(%p)\n", This, aFilePath);
2985 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2988 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2990 nsWineURI *This = impl_from_nsIFileURL(iface);
2992 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2994 if(!This->is_mutable)
2995 return NS_ERROR_UNEXPECTED;
2997 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
3000 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
3002 nsWineURI *This = impl_from_nsIFileURL(iface);
3003 WCHAR *ptr;
3004 BSTR query;
3005 nsresult nsres;
3006 HRESULT hres;
3008 TRACE("(%p)->(%p)\n", This, aQuery);
3010 if(!ensure_uri(This))
3011 return NS_ERROR_UNEXPECTED;
3013 hres = IUri_GetQuery(This->uri, &query);
3014 if(FAILED(hres))
3015 return NS_ERROR_FAILURE;
3017 ptr = query;
3018 if(ptr && *ptr == '?')
3019 ptr++;
3021 nsres = return_wstr_nsacstr(aQuery, ptr, -1);
3022 SysFreeString(query);
3023 return nsres;
3026 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
3028 nsWineURI *This = impl_from_nsIFileURL(iface);
3029 const char *querya;
3030 WCHAR *query;
3031 HRESULT hres;
3033 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
3035 if(!ensure_uri_builder(This))
3036 return NS_ERROR_UNEXPECTED;
3038 nsACString_GetData(aQuery, &querya);
3039 query = heap_strdupUtoW(querya);
3040 if(!query)
3041 return NS_ERROR_OUT_OF_MEMORY;
3043 hres = IUriBuilder_SetQuery(This->uri_builder, query);
3044 heap_free(query);
3045 if(FAILED(hres))
3046 return NS_ERROR_UNEXPECTED;
3048 return NS_OK;
3051 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
3053 const WCHAR *ptr;
3054 HRESULT hres;
3056 if(!ensure_uri(This))
3057 return NS_ERROR_UNEXPECTED;
3059 hres = IUri_GetPath(This->uri, path);
3060 if(FAILED(hres))
3061 return NS_ERROR_FAILURE;
3063 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
3064 if(*ptr == '/' || *ptr == '\\')
3065 ptr++;
3066 *file = ptr;
3068 if(ext) {
3069 ptr = strrchrW(ptr, '.');
3070 if(!ptr)
3071 ptr = *path + SysStringLen(*path);
3072 *ext = ptr;
3075 return NS_OK;
3078 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
3080 nsWineURI *This = impl_from_nsIFileURL(iface);
3081 const WCHAR *file;
3082 BSTR path;
3083 nsresult nsres;
3085 TRACE("(%p)->(%p)\n", This, aDirectory);
3087 nsres = get_uri_path(This, &path, &file, NULL);
3088 if(NS_FAILED(nsres))
3089 return nsres;
3091 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
3092 SysFreeString(path);
3093 return nsres;
3096 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
3098 nsWineURI *This = impl_from_nsIFileURL(iface);
3100 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
3102 /* Not implemented by Gecko */
3103 return NS_ERROR_NOT_IMPLEMENTED;
3106 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
3108 nsWineURI *This = impl_from_nsIFileURL(iface);
3109 const WCHAR *file;
3110 BSTR path;
3111 nsresult nsres;
3113 TRACE("(%p)->(%p)\n", This, aFileName);
3115 nsres = get_uri_path(This, &path, &file, NULL);
3116 if(NS_FAILED(nsres))
3117 return nsres;
3119 nsres = return_wstr_nsacstr(aFileName, file, -1);
3120 SysFreeString(path);
3121 return nsres;
3124 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
3126 nsWineURI *This = impl_from_nsIFileURL(iface);
3127 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
3128 return NS_ERROR_NOT_IMPLEMENTED;
3131 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
3133 nsWineURI *This = impl_from_nsIFileURL(iface);
3134 const WCHAR *file, *ext;
3135 BSTR path;
3136 nsresult nsres;
3138 TRACE("(%p)->(%p)\n", This, aFileBaseName);
3140 nsres = get_uri_path(This, &path, &file, &ext);
3141 if(NS_FAILED(nsres))
3142 return nsres;
3144 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
3145 SysFreeString(path);
3146 return nsres;
3149 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
3151 nsWineURI *This = impl_from_nsIFileURL(iface);
3152 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
3153 return NS_ERROR_NOT_IMPLEMENTED;
3156 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
3158 nsWineURI *This = impl_from_nsIFileURL(iface);
3160 TRACE("(%p)->(%p)\n", This, aFileExtension);
3162 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
3165 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
3167 nsWineURI *This = impl_from_nsIFileURL(iface);
3168 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
3169 return NS_ERROR_NOT_IMPLEMENTED;
3172 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
3174 nsWineURI *This = impl_from_nsIFileURL(iface);
3175 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
3176 return NS_ERROR_NOT_IMPLEMENTED;
3179 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
3181 nsWineURI *This = impl_from_nsIFileURL(iface);
3182 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
3183 return NS_ERROR_NOT_IMPLEMENTED;
3186 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
3188 nsWineURI *This = impl_from_nsIFileURL(iface);
3189 WCHAR path[MAX_PATH];
3190 DWORD size;
3191 HRESULT hres;
3193 TRACE("(%p)->(%p)\n", This, aFile);
3195 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, sizeof(path)/sizeof(WCHAR), &size, 0);
3196 if(FAILED(hres)) {
3197 WARN("CoInternetParseIUri failed: %08x\n", hres);
3198 return NS_ERROR_FAILURE;
3201 return create_nsfile(path, aFile);
3204 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
3206 nsWineURI *This = impl_from_nsIFileURL(iface);
3207 FIXME("(%p)->(%p)\n", This, aFile);
3208 return NS_ERROR_NOT_IMPLEMENTED;
3211 static const nsIFileURLVtbl nsFileURLVtbl = {
3212 nsURI_QueryInterface,
3213 nsURI_AddRef,
3214 nsURI_Release,
3215 nsURI_GetSpec,
3216 nsURI_SetSpec,
3217 nsURI_GetPrePath,
3218 nsURI_GetScheme,
3219 nsURI_SetScheme,
3220 nsURI_GetUserPass,
3221 nsURI_SetUserPass,
3222 nsURI_GetUsername,
3223 nsURI_SetUsername,
3224 nsURI_GetPassword,
3225 nsURI_SetPassword,
3226 nsURI_GetHostPort,
3227 nsURI_SetHostPort,
3228 nsURI_GetHost,
3229 nsURI_SetHost,
3230 nsURI_GetPort,
3231 nsURI_SetPort,
3232 nsURI_GetPath,
3233 nsURI_SetPath,
3234 nsURI_Equals,
3235 nsURI_SchemeIs,
3236 nsURI_Clone,
3237 nsURI_Resolve,
3238 nsURI_GetAsciiSpec,
3239 nsURI_GetAsciiHostPort,
3240 nsURI_GetAsciiHost,
3241 nsURI_GetOriginCharset,
3242 nsURL_GetRef,
3243 nsURL_SetRef,
3244 nsURI_EqualsExceptRef,
3245 nsURI_CloneIgnoreRef,
3246 nsURI_GetSpecIgnoringRef,
3247 nsURI_GetHasRef,
3248 nsURL_GetFilePath,
3249 nsURL_SetFilePath,
3250 nsURL_GetQuery,
3251 nsURL_SetQuery,
3252 nsURL_GetDirectory,
3253 nsURL_SetDirectory,
3254 nsURL_GetFileName,
3255 nsURL_SetFileName,
3256 nsURL_GetFileBaseName,
3257 nsURL_SetFileBaseName,
3258 nsURL_GetFileExtension,
3259 nsURL_SetFileExtension,
3260 nsURL_GetCommonBaseSpec,
3261 nsURL_GetRelativeSpec,
3262 nsFileURL_GetFile,
3263 nsFileURL_SetFile
3266 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
3268 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
3271 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
3272 void **result)
3274 nsWineURI *This = impl_from_nsIStandardURL(iface);
3275 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
3278 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
3280 nsWineURI *This = impl_from_nsIStandardURL(iface);
3281 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
3284 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
3286 nsWineURI *This = impl_from_nsIStandardURL(iface);
3287 return nsIFileURL_Release(&This->nsIFileURL_iface);
3290 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
3292 nsWineURI *This = impl_from_nsIStandardURL(iface);
3294 TRACE("(%p)->(%p)\n", This, aMutable);
3296 *aMutable = This->is_mutable;
3297 return NS_OK;
3300 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
3302 nsWineURI *This = impl_from_nsIStandardURL(iface);
3304 TRACE("(%p)->(%x)\n", This, aMutable);
3306 This->is_mutable = aMutable;
3307 return NS_OK;
3310 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, UINT32 aUrlType, LONG aDefaultPort,
3311 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
3313 nsWineURI *This = impl_from_nsIStandardURL(iface);
3314 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
3315 return NS_ERROR_NOT_IMPLEMENTED;
3318 static const nsIStandardURLVtbl nsStandardURLVtbl = {
3319 nsStandardURL_QueryInterface,
3320 nsStandardURL_AddRef,
3321 nsStandardURL_Release,
3322 nsStandardURL_GetMutable,
3323 nsStandardURL_SetMutable,
3324 nsStandardURL_Init
3327 static nsresult create_nsuri(IUri *iuri, HTMLOuterWindow *window, NSContainer *container,
3328 const char *origin_charset, nsWineURI **_retval)
3330 nsWineURI *ret;
3331 HRESULT hres;
3333 ret = heap_alloc_zero(sizeof(nsWineURI));
3334 if(!ret)
3335 return NS_ERROR_OUT_OF_MEMORY;
3337 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
3338 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
3339 ret->ref = 1;
3340 ret->is_mutable = TRUE;
3342 set_uri_nscontainer(ret, container);
3343 set_uri_window(ret, window);
3345 IUri_AddRef(iuri);
3346 ret->uri = iuri;
3348 hres = IUri_GetScheme(iuri, &ret->scheme);
3349 if(FAILED(hres))
3350 ret->scheme = URL_SCHEME_UNKNOWN;
3352 if(origin_charset && *origin_charset && strcmp(origin_charset, "UTF-8")) {
3353 ret->origin_charset = heap_strdupA(origin_charset);
3354 if(!ret->origin_charset) {
3355 nsIFileURL_Release(&ret->nsIFileURL_iface);
3356 return NS_ERROR_OUT_OF_MEMORY;
3360 TRACE("retval=%p\n", ret);
3361 *_retval = ret;
3362 return NS_OK;
3365 HRESULT create_doc_uri(HTMLOuterWindow *window, IUri *iuri, nsWineURI **ret)
3367 nsWineURI *uri;
3368 nsresult nsres;
3370 nsres = create_nsuri(iuri, window, window->doc_obj->nscontainer, NULL, &uri);
3371 if(NS_FAILED(nsres))
3372 return E_FAIL;
3374 uri->is_doc_uri = TRUE;
3376 *ret = uri;
3377 return S_OK;
3380 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
3382 nsChannel *channel;
3384 if(!ensure_uri(uri))
3385 return NS_ERROR_UNEXPECTED;
3387 channel = heap_alloc_zero(sizeof(nsChannel));
3388 if(!channel)
3389 return NS_ERROR_OUT_OF_MEMORY;
3391 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
3392 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
3393 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
3394 channel->ref = 1;
3395 channel->request_method = METHOD_GET;
3396 list_init(&channel->response_headers);
3397 list_init(&channel->request_headers);
3399 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
3400 channel->uri = uri;
3402 *ret = channel;
3403 return NS_OK;
3406 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
3408 HTMLOuterWindow *window = NULL;
3409 nsChannel *channel;
3410 nsWineURI *uri;
3411 IUri *iuri;
3412 nsresult nsres;
3413 HRESULT hres;
3415 hres = create_uri(url, 0, &iuri);
3416 if(FAILED(hres))
3417 return hres;
3419 if(orig_channel->uri->window_ref)
3420 window = orig_channel->uri->window_ref->window;
3421 nsres = create_nsuri(iuri, window, NULL, NULL, &uri);
3422 IUri_Release(iuri);
3423 if(NS_FAILED(nsres))
3424 return E_FAIL;
3426 nsres = create_nschannel(uri, &channel);
3427 nsIFileURL_Release(&uri->nsIFileURL_iface);
3428 if(NS_FAILED(nsres))
3429 return E_FAIL;
3431 if(orig_channel->load_group) {
3432 nsILoadGroup_AddRef(orig_channel->load_group);
3433 channel->load_group = orig_channel->load_group;
3436 if(orig_channel->notif_callback) {
3437 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
3438 channel->notif_callback = orig_channel->notif_callback;
3441 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
3443 if(orig_channel->request_method == METHOD_POST)
3444 FIXME("unsupported POST method\n");
3446 if(orig_channel->original_uri) {
3447 nsIURI_AddRef(orig_channel->original_uri);
3448 channel->original_uri = orig_channel->original_uri;
3451 if(orig_channel->referrer) {
3452 nsIURI_AddRef(orig_channel->referrer);
3453 channel->referrer = orig_channel->referrer;
3456 *ret = channel;
3457 return S_OK;
3460 typedef struct {
3461 nsIProtocolHandler nsIProtocolHandler_iface;
3463 LONG ref;
3465 nsIProtocolHandler *nshandler;
3466 } nsProtocolHandler;
3468 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
3470 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
3473 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3474 void **result)
3476 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3478 *result = NULL;
3480 if(IsEqualGUID(&IID_nsISupports, riid)) {
3481 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3482 *result = &This->nsIProtocolHandler_iface;
3483 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3484 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3485 *result = &This->nsIProtocolHandler_iface;
3486 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3487 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3488 return NS_NOINTERFACE;
3491 if(*result) {
3492 nsISupports_AddRef((nsISupports*)*result);
3493 return NS_OK;
3496 WARN("(%s %p)\n", debugstr_guid(riid), result);
3497 return NS_NOINTERFACE;
3500 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3502 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3503 LONG ref = InterlockedIncrement(&This->ref);
3505 TRACE("(%p) ref=%d\n", This, ref);
3507 return ref;
3510 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3512 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3513 LONG ref = InterlockedDecrement(&This->ref);
3515 TRACE("(%p) ref=%d\n", This, ref);
3517 if(!ref) {
3518 if(This->nshandler)
3519 nsIProtocolHandler_Release(This->nshandler);
3520 heap_free(This);
3523 return ref;
3526 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3528 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3530 TRACE("(%p)->(%p)\n", This, aScheme);
3532 if(This->nshandler)
3533 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3534 return NS_ERROR_NOT_IMPLEMENTED;
3537 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3538 LONG *aDefaultPort)
3540 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3542 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3544 if(This->nshandler)
3545 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3546 return NS_ERROR_NOT_IMPLEMENTED;
3549 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3550 UINT32 *aProtocolFlags)
3552 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3554 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3556 if(This->nshandler)
3557 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3558 return NS_ERROR_NOT_IMPLEMENTED;
3561 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3562 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3564 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3566 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3567 aBaseURI, _retval);
3569 if(This->nshandler)
3570 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3571 return NS_ERROR_NOT_IMPLEMENTED;
3574 static nsresult NSAPI nsProtocolHandler_NewChannel2(nsIProtocolHandler *iface,
3575 nsIURI *aURI, nsILoadInfo *aLoadInfo, nsIChannel **_retval)
3577 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3579 TRACE("(%p)->(%p %p %p)\n", This, aURI, aLoadInfo, _retval);
3581 if(This->nshandler)
3582 return nsIProtocolHandler_NewChannel2(This->nshandler, aURI, aLoadInfo, _retval);
3583 return NS_ERROR_NOT_IMPLEMENTED;
3586 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3587 nsIURI *aURI, nsIChannel **_retval)
3589 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3591 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3593 if(This->nshandler)
3594 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3595 return NS_ERROR_NOT_IMPLEMENTED;
3598 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3599 LONG port, const char *scheme, cpp_bool *_retval)
3601 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3603 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3605 if(This->nshandler)
3606 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3607 return NS_ERROR_NOT_IMPLEMENTED;
3610 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3611 nsProtocolHandler_QueryInterface,
3612 nsProtocolHandler_AddRef,
3613 nsProtocolHandler_Release,
3614 nsProtocolHandler_GetScheme,
3615 nsProtocolHandler_GetDefaultPort,
3616 nsProtocolHandler_GetProtocolFlags,
3617 nsProtocolHandler_NewURI,
3618 nsProtocolHandler_NewChannel2,
3619 nsProtocolHandler_NewChannel,
3620 nsProtocolHandler_AllowPort
3623 static nsresult NSAPI nsIOServiceHook_QueryInterface(nsIIOServiceHook *iface, nsIIDRef riid,
3624 void **result)
3626 if(IsEqualGUID(&IID_nsISupports, riid)) {
3627 TRACE("(IID_nsISupports %p)\n", result);
3628 *result = iface;
3629 }else if(IsEqualGUID(&IID_nsIIOServiceHook, riid)) {
3630 TRACE("(IID_nsIIOServiceHook %p)\n", result);
3631 *result = iface;
3632 }else {
3633 ERR("(%s %p)\n", debugstr_guid(riid), result);
3634 *result = NULL;
3635 return NS_NOINTERFACE;
3638 nsISupports_AddRef((nsISupports*)*result);
3639 return NS_OK;
3642 static nsrefcnt NSAPI nsIOServiceHook_AddRef(nsIIOServiceHook *iface)
3644 return 2;
3647 static nsrefcnt NSAPI nsIOServiceHook_Release(nsIIOServiceHook *iface)
3649 return 1;
3652 static nsresult NSAPI nsIOServiceHook_NewChannel(nsIIOServiceHook *iface, nsIURI *aURI,
3653 nsILoadInfo *aLoadInfo, nsIChannel **_retval)
3655 nsWineURI *wine_uri;
3656 nsChannel *ret;
3657 nsresult nsres;
3659 TRACE("(%p %p %p)\n", aURI, aLoadInfo, _retval);
3661 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3662 if(NS_FAILED(nsres)) {
3663 TRACE("Could not get nsWineURI: %08x\n", nsres);
3664 return NS_SUCCESS_DEFAULT_ACTION;
3667 nsres = create_nschannel(wine_uri, &ret);
3668 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3669 if(NS_FAILED(nsres))
3670 return nsres;
3672 nsIURI_AddRef(aURI);
3673 ret->original_uri = aURI;
3675 if(aLoadInfo)
3676 nsIHttpChannel_SetLoadInfo(&ret->nsIHttpChannel_iface, aLoadInfo);
3678 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3679 return NS_OK;
3682 static nsresult NSAPI nsIOServiceHook_GetProtocolHandler(nsIIOServiceHook *iface, nsIProtocolHandler *aHandler,
3683 nsIProtocolHandler **_retval)
3685 nsIExternalProtocolHandler *nsexthandler;
3686 nsProtocolHandler *ret;
3687 nsresult nsres;
3689 TRACE("(%p %p)\n", aHandler, _retval);
3691 nsres = nsIProtocolHandler_QueryInterface(aHandler, &IID_nsIExternalProtocolHandler, (void**)&nsexthandler);
3692 if(NS_FAILED(nsres)) {
3693 nsIProtocolHandler_AddRef(aHandler);
3694 *_retval = aHandler;
3695 return NS_OK;
3698 nsIExternalProtocolHandler_Release(nsexthandler);
3700 ret = heap_alloc(sizeof(nsProtocolHandler));
3701 if(!ret)
3702 return NS_ERROR_OUT_OF_MEMORY;
3704 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3705 ret->ref = 1;
3706 nsIProtocolHandler_AddRef(aHandler);
3707 ret->nshandler = aHandler;
3710 *_retval = &ret->nsIProtocolHandler_iface;
3711 TRACE("return %p\n", *_retval);
3712 return NS_OK;
3715 static BOOL is_gecko_special_uri(const char *spec)
3717 static const char *special_schemes[] = {"chrome:", "data:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3718 unsigned int i;
3720 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
3721 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
3722 return TRUE;
3725 if(!strncasecmp(spec, "file:", 5)) {
3726 const char *ptr = spec+5;
3727 while(*ptr == '/')
3728 ptr++;
3729 return is_gecko_path(ptr);
3732 return FALSE;
3735 static nsresult NSAPI nsIOServiceHook_NewURI(nsIIOServiceHook *iface, const nsACString *aSpec,
3736 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3738 nsWineURI *wine_uri, *base_wine_uri = NULL;
3739 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3740 HTMLOuterWindow *window = NULL;
3741 const char *spec = NULL;
3742 UINT cp = CP_UTF8;
3743 IUri *urlmon_uri;
3744 nsresult nsres;
3745 HRESULT hres;
3747 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3748 aBaseURI, _retval);
3750 nsACString_GetData(aSpec, &spec);
3751 if(is_gecko_special_uri(spec))
3752 return NS_SUCCESS_DEFAULT_ACTION;
3754 if(!strncmp(spec, "wine:", 5))
3755 spec += 5;
3757 if(aBaseURI) {
3758 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3759 if(NS_SUCCEEDED(nsres)) {
3760 if(!ensure_uri(base_wine_uri))
3761 return NS_ERROR_UNEXPECTED;
3762 if(base_wine_uri->window_ref)
3763 window = base_wine_uri->window_ref->window;
3764 }else {
3765 WARN("Could not get base nsWineURI: %08x\n", nsres);
3769 if(aOriginCharset && *aOriginCharset && strncasecmp(aOriginCharset, "utf", 3)) {
3770 BSTR charset;
3771 int len;
3773 len = MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, NULL, 0);
3774 charset = SysAllocStringLen(NULL, len-1);
3775 if(!charset)
3776 return NS_ERROR_OUT_OF_MEMORY;
3777 MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, charset, len);
3779 cp = cp_from_charset_string(charset);
3781 SysFreeString(charset);
3784 MultiByteToWideChar(cp, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
3786 if(base_wine_uri) {
3787 hres = combine_url(base_wine_uri->uri, new_spec, &urlmon_uri);
3788 }else {
3789 hres = create_uri(new_spec, 0, &urlmon_uri);
3790 if(FAILED(hres))
3791 WARN("create_uri failed: %08x\n", hres);
3794 if(FAILED(hres))
3795 return NS_SUCCESS_DEFAULT_ACTION;
3797 nsres = create_nsuri(urlmon_uri, window, NULL, NULL, &wine_uri);
3798 IUri_Release(urlmon_uri);
3799 if(base_wine_uri)
3800 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3801 if(NS_FAILED(nsres))
3802 return nsres;
3804 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3805 return nsres;
3808 static const char *debugstr_protocol_flags(UINT32 flags)
3810 switch(flags) {
3811 #define X(f) case f: return #f
3812 X(URI_STD);
3813 X(URI_NORELATIVE);
3814 X(URI_NOAUTH);
3815 X(ALLOWS_PROXY);
3816 X(ALLOWS_PROXY_HTTP);
3817 X(URI_INHERITS_SECURITY_CONTEXT);
3818 X(URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT);
3819 X(URI_LOADABLE_BY_ANYONE);
3820 X(URI_DANGEROUS_TO_LOAD);
3821 X(URI_IS_UI_RESOURCE);
3822 X(URI_IS_LOCAL_FILE);
3823 X(URI_LOADABLE_BY_SUBSUMERS);
3824 X(URI_DOES_NOT_RETURN_DATA);
3825 X(URI_IS_LOCAL_RESOURCE);
3826 X(URI_OPENING_EXECUTES_SCRIPT);
3827 X(URI_NON_PERSISTABLE);
3828 X(URI_FORBIDS_COOKIE_ACCESS);
3829 X(URI_CROSS_ORIGIN_NEEDS_WEBAPPS_PERM);
3830 X(URI_SYNC_LOAD_IS_OK);
3831 X(URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT);
3832 X(URI_FETCHABLE_BY_ANYONE);
3833 #undef X
3834 default:
3835 return wine_dbg_sprintf("%08x", flags);
3839 static nsresult NSAPI nsIOServiceHook_ProtocolHasFlags(nsIIOServiceHook *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3841 TRACE("(%p %s %p)\n", aURI, debugstr_protocol_flags(aFlags), _retval);
3842 return NS_SUCCESS_DEFAULT_ACTION;
3845 static nsresult NSAPI nsIOServiceHook_URIChainHasFlags(nsIIOServiceHook *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3847 TRACE("(%p %s %p)\n", aURI, debugstr_protocol_flags(aFlags), _retval);
3849 if(aFlags == URI_DOES_NOT_RETURN_DATA) {
3850 *_retval = FALSE;
3851 return S_OK;
3854 return NS_SUCCESS_DEFAULT_ACTION;
3857 static const nsIIOServiceHookVtbl nsIOServiceHookVtbl = {
3858 nsIOServiceHook_QueryInterface,
3859 nsIOServiceHook_AddRef,
3860 nsIOServiceHook_Release,
3861 nsIOServiceHook_NewChannel,
3862 nsIOServiceHook_GetProtocolHandler,
3863 nsIOServiceHook_NewURI,
3864 nsIOServiceHook_ProtocolHasFlags,
3865 nsIOServiceHook_URIChainHasFlags
3868 static nsIIOServiceHook nsIOServiceHook = { &nsIOServiceHookVtbl };
3870 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
3872 OLECHAR *new_url = NULL;
3873 WCHAR *url;
3874 BOOL ret = FALSE;
3875 HRESULT hres;
3877 if(!doc->hostui || !ensure_uri(uri))
3878 return FALSE;
3880 hres = IUri_GetDisplayUri(uri->uri, &url);
3881 if(FAILED(hres))
3882 return FALSE;
3884 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
3885 if(hres == S_OK && new_url) {
3886 if(strcmpW(url, new_url)) {
3887 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
3888 ret = TRUE;
3890 CoTaskMemFree(new_url);
3893 SysFreeString(url);
3894 return ret;
3897 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, cpp_bool *_retval)
3899 nsWineURI *wine_uri;
3900 nsresult nsres;
3902 *_retval = FALSE;
3904 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
3905 if(NS_FAILED(nsres)) {
3906 WARN("Could not get nsWineURI: %08x\n", nsres);
3907 return NS_ERROR_NOT_IMPLEMENTED;
3910 if(!wine_uri->is_doc_uri) {
3911 wine_uri->is_doc_uri = TRUE;
3913 if(!wine_uri->container) {
3914 nsIWebBrowserChrome_AddRef(&nscontainer->nsIWebBrowserChrome_iface);
3915 wine_uri->container = nscontainer;
3918 if(nscontainer->doc)
3919 *_retval = translate_url(nscontainer->doc, wine_uri);
3922 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3923 return NS_OK;
3926 void init_nsio(nsIComponentManager *component_manager)
3928 nsIFactory *old_factory = NULL;
3929 nsresult nsres;
3931 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3932 &IID_nsIFactory, (void**)&old_factory);
3933 if(NS_FAILED(nsres)) {
3934 ERR("Could not get factory: %08x\n", nsres);
3935 return;
3938 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3939 if(NS_FAILED(nsres)) {
3940 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3941 nsIFactory_Release(old_factory);
3942 return;
3945 nsres = nsIIOService_SetHook(nsio, &nsIOServiceHook);
3946 assert(nsres == NS_OK);
3949 void release_nsio(void)
3951 if(nsio) {
3952 nsIIOService_Release(nsio);
3953 nsio = NULL;