gdi32: Try to parse font names without FreeType.
[wine/zf.git] / dlls / mshtml / nsio.c
blobee709645873ea5e1dc2297bf901f1f2a56a85b8b
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 <stdarg.h>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "winternl.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "wininet.h"
32 #include "shlwapi.h"
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
37 #include "binding.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID =
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static const IID IID_nsWineURI =
47 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
49 static nsIIOService *nsio = NULL;
51 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
53 struct nsWineURI {
54 nsIFileURL nsIFileURL_iface; /* For non-file URL objects, it's just nsIURL */
55 nsIStandardURL nsIStandardURL_iface;
57 LONG ref;
59 nsChannelBSC *channel_bsc;
60 IUri *uri;
61 IUriBuilder *uri_builder;
62 BOOL is_mutable;
63 DWORD scheme;
66 static BOOL ensure_uri(nsWineURI *This)
68 HRESULT hres;
70 assert(This->uri || This->uri_builder);
72 if(!This->uri) {
73 hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
74 if(FAILED(hres)) {
75 WARN("CreateUriSimple failed: %08x\n", hres);
76 return FALSE;
80 return TRUE;
83 IUri *nsuri_get_uri(nsWineURI *nsuri)
85 if(!ensure_uri(nsuri))
86 return NULL;
88 IUri_AddRef(nsuri->uri);
89 return nsuri->uri;
92 IUri *get_uri_nofrag(IUri *uri)
94 IUriBuilder *uri_builder;
95 IUri *ret;
96 BOOL b;
97 HRESULT hres;
99 hres = IUri_HasProperty(uri, Uri_PROPERTY_FRAGMENT, &b);
100 if(SUCCEEDED(hres) && !b) {
101 IUri_AddRef(uri);
102 return uri;
105 hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
106 if(FAILED(hres))
107 return NULL;
109 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_FRAGMENT);
110 if(SUCCEEDED(hres))
111 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &ret);
112 IUriBuilder_Release(uri_builder);
113 if(FAILED(hres))
114 return NULL;
116 return ret;
119 static BOOL compare_ignoring_frag(IUri *uri1, IUri *uri2)
121 IUri *uri_nofrag1, *uri_nofrag2;
122 BOOL ret = FALSE;
124 uri_nofrag1 = get_uri_nofrag(uri1);
125 if(!uri_nofrag1)
126 return FALSE;
128 uri_nofrag2 = get_uri_nofrag(uri2);
129 if(uri_nofrag2) {
130 IUri_IsEqual(uri_nofrag1, uri_nofrag2, &ret);
131 IUri_Release(uri_nofrag2);
134 IUri_Release(uri_nofrag1);
135 return ret;
138 static HRESULT combine_url(IUri *base_uri, const WCHAR *rel_url, IUri **ret)
140 IUri *uri_nofrag;
141 HRESULT hres;
143 uri_nofrag = get_uri_nofrag(base_uri);
144 if(!uri_nofrag)
145 return E_FAIL;
147 hres = CoInternetCombineUrlEx(uri_nofrag, rel_url, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
148 ret, 0);
149 IUri_Release(uri_nofrag);
150 if(FAILED(hres))
151 WARN("CoInternetCombineUrlEx failed: %08x\n", hres);
152 return hres;
155 static nsresult create_nsuri(IUri*,nsWineURI**);
157 static const char *debugstr_nsacstr(const nsACString *nsstr)
159 const char *data;
161 nsACString_GetData(nsstr, &data);
162 return debugstr_a(data);
165 static nsresult return_wstr_nsacstr(nsACString *ret_str, const WCHAR *str, int len)
167 char *stra;
168 int lena;
170 TRACE("returning %s\n", debugstr_wn(str, len));
172 if(!*str) {
173 nsACString_SetData(ret_str, "");
174 return NS_OK;
177 lena = WideCharToMultiByte(CP_UTF8, 0, str, len, NULL, 0, NULL, NULL);
178 stra = heap_alloc(lena+1);
179 if(!stra)
180 return NS_ERROR_OUT_OF_MEMORY;
182 WideCharToMultiByte(CP_UTF8, 0, str, len, stra, lena, NULL, NULL);
183 stra[lena] = 0;
185 nsACString_SetData(ret_str, stra);
186 heap_free(stra);
187 return NS_OK;
190 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
192 const WCHAR *ptr = nsuri;
194 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
196 if(!wcsncmp(nsuri, wine_prefixW, ARRAY_SIZE(wine_prefixW)))
197 ptr += ARRAY_SIZE(wine_prefixW);
199 if(*ptr || ret_empty) {
200 *ret = SysAllocString(ptr);
201 if(!*ret)
202 return E_OUTOFMEMORY;
203 }else {
204 *ret = NULL;
207 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
208 return S_OK;
211 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, BSTR url)
213 IOleCommandTarget *cmdtrg = NULL;
214 HRESULT hres;
216 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
217 if(SUCCEEDED(hres)) {
218 VARIANT varUrl, varRes;
220 V_VT(&varUrl) = VT_BSTR;
221 V_BSTR(&varUrl) = url;
222 V_VT(&varRes) = VT_BOOL;
224 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
226 IOleCommandTarget_Release(cmdtrg);
228 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
229 TRACE("got VARIANT_FALSE, do not load\n");
230 return FALSE;
234 return TRUE;
237 static nsresult before_async_open(nsChannel *channel, GeckoBrowser *container, BOOL *cancel)
239 HTMLDocumentObj *doc = container->doc;
240 BSTR display_uri;
241 HRESULT hres;
243 if(!doc->client) {
244 *cancel = TRUE;
245 return NS_OK;
248 hres = IUri_GetDisplayUri(channel->uri->uri, &display_uri);
249 if(FAILED(hres))
250 return NS_ERROR_FAILURE;
252 if(doc->hostui) {
253 OLECHAR *new_url;
254 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, display_uri, &new_url);
255 if(hres == S_OK && new_url) {
256 if(wcscmp(display_uri, new_url)) {
257 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(display_uri), debugstr_w(new_url));
258 CoTaskMemFree(new_url);
259 *cancel = TRUE;
260 return NS_OK;
262 CoTaskMemFree(new_url);
266 if(!exec_shldocvw_67(doc, display_uri)) {
267 SysFreeString(display_uri);
268 *cancel = FALSE;
269 return NS_OK;
272 hres = hlink_frame_navigate(&doc->basedoc, display_uri, channel, 0, cancel);
273 SysFreeString(display_uri);
274 if(FAILED(hres))
275 *cancel = TRUE;
276 return NS_OK;
279 HRESULT load_nsuri(HTMLOuterWindow *window, nsWineURI *uri, nsIInputStream *post_stream,
280 nsChannelBSC *channelbsc, DWORD flags)
282 nsIWebNavigation *web_navigation;
283 nsIDocShellLoadInfo *load_info;
284 nsIDocShell *doc_shell;
285 HTMLDocumentNode *doc;
286 nsresult nsres;
288 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
289 if(NS_FAILED(nsres)) {
290 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
291 return E_FAIL;
294 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
295 nsIWebNavigation_Release(web_navigation);
296 if(NS_FAILED(nsres)) {
297 ERR("Could not get nsIDocShell: %08x\n", nsres);
298 return E_FAIL;
301 nsres = nsIDocShell_CreateLoadInfo(doc_shell, &load_info);
302 if(NS_FAILED(nsres)) {
303 nsIDocShell_Release(doc_shell);
304 return E_FAIL;
307 nsres = nsIDocShellLoadInfo_SetLoadType(load_info, (flags & LOAD_FLAGS_BYPASS_CACHE) ? loadNormalBypassCache : loadNormal);
308 assert(nsres == NS_OK);
310 if(post_stream) {
311 nsres = nsIDocShellLoadInfo_SetPostDataStream(load_info, post_stream);
312 assert(nsres == NS_OK);
315 if(window->uri_nofrag) {
316 nsWineURI *referrer_uri;
317 nsres = create_nsuri(window->uri_nofrag, &referrer_uri);
318 if(NS_SUCCEEDED(nsres)) {
319 nsres = nsIDocShellLoadInfo_SetReferrer(load_info, (nsIURI*)&referrer_uri->nsIFileURL_iface);
320 assert(nsres == NS_OK);
321 nsIFileURL_Release(&referrer_uri->nsIFileURL_iface);
325 uri->channel_bsc = channelbsc;
326 doc = window->base.inner_window->doc;
327 doc->skip_mutation_notif = TRUE;
328 nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)&uri->nsIFileURL_iface, load_info, flags, FALSE);
329 if(doc == window->base.inner_window->doc)
330 doc->skip_mutation_notif = FALSE;
331 uri->channel_bsc = NULL;
332 nsIDocShell_Release(doc_shell);
333 nsIDocShellLoadInfo_Release(load_info);
334 if(NS_FAILED(nsres)) {
335 WARN("LoadURI failed: %08x\n", nsres);
336 return E_FAIL;
339 return S_OK;
342 static inline BOOL is_http_channel(nsChannel *This)
344 return This->uri->scheme == URL_SCHEME_HTTP || This->uri->scheme == URL_SCHEME_HTTPS;
347 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
349 http_header_t *iter;
351 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
352 if(!wcsnicmp(iter->header, name, len) && !iter->header[len])
353 return iter;
356 return NULL;
359 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
360 nsACString *_retval)
362 const char *header_namea;
363 http_header_t *header;
364 WCHAR *header_name;
365 char *data;
367 nsACString_GetData(header_name_str, &header_namea);
368 header_name = heap_strdupAtoW(header_namea);
369 if(!header_name)
370 return NS_ERROR_UNEXPECTED;
372 header = find_http_header(headers, header_name, lstrlenW(header_name));
373 heap_free(header_name);
374 if(!header)
375 return NS_ERROR_NOT_AVAILABLE;
377 data = heap_strdupWtoA(header->data);
378 if(!data)
379 return NS_ERROR_UNEXPECTED;
381 TRACE("%s -> %s\n", debugstr_a(header_namea), debugstr_a(data));
382 nsACString_SetData(_retval, data);
383 heap_free(data);
384 return NS_OK;
387 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
388 const WCHAR *value, int value_len)
390 http_header_t *header;
392 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
394 header = find_http_header(headers, name, name_len);
395 if(header) {
396 WCHAR *new_data;
398 new_data = heap_strndupW(value, value_len);
399 if(!new_data)
400 return E_OUTOFMEMORY;
402 heap_free(header->data);
403 header->data = new_data;
404 }else {
405 header = heap_alloc(sizeof(http_header_t));
406 if(!header)
407 return E_OUTOFMEMORY;
409 header->header = heap_strndupW(name, name_len);
410 header->data = heap_strndupW(value, value_len);
411 if(!header->header || !header->data) {
412 heap_free(header->header);
413 heap_free(header->data);
414 heap_free(header);
415 return E_OUTOFMEMORY;
418 list_add_tail(headers, &header->entry);
421 return S_OK;
424 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
425 const nsACString *value_str)
427 const char *namea, *valuea;
428 WCHAR *name, *value;
429 HRESULT hres;
431 nsACString_GetData(name_str, &namea);
432 name = heap_strdupAtoW(namea);
433 if(!name)
434 return NS_ERROR_UNEXPECTED;
436 nsACString_GetData(value_str, &valuea);
437 value = heap_strdupAtoW(valuea);
438 if(!value) {
439 heap_free(name);
440 return NS_ERROR_UNEXPECTED;
443 hres = set_http_header(headers, name, lstrlenW(name), value, lstrlenW(value));
445 heap_free(name);
446 heap_free(value);
447 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
450 static nsresult visit_http_headers(struct list *headers, nsIHttpHeaderVisitor *visitor)
452 nsACString header_str, value_str;
453 char *header, *value;
454 http_header_t *iter;
455 nsresult nsres;
457 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
458 header = heap_strdupWtoA(iter->header);
459 if(!header)
460 return NS_ERROR_OUT_OF_MEMORY;
462 value = heap_strdupWtoA(iter->data);
463 if(!value) {
464 heap_free(header);
465 return NS_ERROR_OUT_OF_MEMORY;
468 nsACString_InitDepend(&header_str, header);
469 nsACString_InitDepend(&value_str, value);
470 nsres = nsIHttpHeaderVisitor_VisitHeader(visitor, &header_str, &value_str);
471 nsACString_Finish(&header_str);
472 nsACString_Finish(&value_str);
473 heap_free(header);
474 heap_free(value);
475 if(NS_FAILED(nsres))
476 break;
479 return NS_OK;
482 static void free_http_headers(struct list *list)
484 http_header_t *iter, *iter_next;
486 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
487 list_remove(&iter->entry);
488 heap_free(iter->header);
489 heap_free(iter->data);
490 heap_free(iter);
494 static inline nsChannel *impl_from_nsIHttpChannel(nsIHttpChannel *iface)
496 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannel_iface);
499 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
501 nsChannel *This = impl_from_nsIHttpChannel(iface);
503 if(IsEqualGUID(&IID_nsISupports, riid)) {
504 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
505 *result = &This->nsIHttpChannel_iface;
506 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
507 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
508 *result = &This->nsIHttpChannel_iface;
509 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
510 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
511 *result = &This->nsIHttpChannel_iface;
512 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
513 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
514 *result = is_http_channel(This) ? &This->nsIHttpChannel_iface : NULL;
515 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
516 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
517 *result = &This->nsIUploadChannel_iface;
518 }else if(IsEqualGUID(&IID_nsIFormPOSTActionChannel, riid)) {
519 TRACE("(%p)->(IID_nsIFormPOSTActionChannel %p)\n", This, result);
520 *result = &This->nsIUploadChannel_iface;
521 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
522 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
523 *result = is_http_channel(This) ? &This->nsIHttpChannelInternal_iface : NULL;
524 }else {
525 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
526 *result = NULL;
529 if(*result) {
530 nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
531 return NS_OK;
534 return NS_NOINTERFACE;
537 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
539 nsChannel *This = impl_from_nsIHttpChannel(iface);
540 nsrefcnt ref = InterlockedIncrement(&This->ref);
542 TRACE("(%p) ref=%d\n", This, ref);
544 return ref;
547 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
549 nsChannel *This = impl_from_nsIHttpChannel(iface);
550 LONG ref = InterlockedDecrement(&This->ref);
552 if(!ref) {
553 nsIFileURL_Release(&This->uri->nsIFileURL_iface);
554 if(This->owner)
555 nsISupports_Release(This->owner);
556 if(This->post_data_stream)
557 nsIInputStream_Release(This->post_data_stream);
558 if(This->load_group)
559 nsILoadGroup_Release(This->load_group);
560 if(This->notif_callback)
561 nsIInterfaceRequestor_Release(This->notif_callback);
562 if(This->original_uri)
563 nsIURI_Release(This->original_uri);
564 if(This->referrer)
565 nsIURI_Release(This->referrer);
567 free_http_headers(&This->response_headers);
568 free_http_headers(&This->request_headers);
570 heap_free(This->content_type);
571 heap_free(This->charset);
572 heap_free(This);
575 return ref;
578 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
580 nsChannel *This = impl_from_nsIHttpChannel(iface);
582 TRACE("(%p)->(%p)\n", This, aName);
584 return nsIFileURL_GetSpec(&This->uri->nsIFileURL_iface, aName);
587 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, cpp_bool *_retval)
589 nsChannel *This = impl_from_nsIHttpChannel(iface);
591 FIXME("(%p)->(%p)\n", This, _retval);
593 return NS_ERROR_NOT_IMPLEMENTED;
596 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
598 nsChannel *This = impl_from_nsIHttpChannel(iface);
600 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
602 return *aStatus = NS_OK;
605 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
607 nsChannel *This = impl_from_nsIHttpChannel(iface);
609 TRACE("(%p)->(%08x)\n", This, aStatus);
611 if(This->binding && This->binding->bsc.binding)
612 IBinding_Abort(This->binding->bsc.binding);
613 else
614 WARN("No binding to cancel\n");
615 return NS_OK;
618 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
620 nsChannel *This = impl_from_nsIHttpChannel(iface);
622 FIXME("(%p)\n", This);
624 return NS_ERROR_NOT_IMPLEMENTED;
627 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
629 nsChannel *This = impl_from_nsIHttpChannel(iface);
631 FIXME("(%p)\n", This);
633 return NS_ERROR_NOT_IMPLEMENTED;
636 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
638 nsChannel *This = impl_from_nsIHttpChannel(iface);
640 TRACE("(%p)->(%p)\n", This, aLoadGroup);
642 if(This->load_group)
643 nsILoadGroup_AddRef(This->load_group);
645 *aLoadGroup = This->load_group;
646 return NS_OK;
649 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
651 nsChannel *This = impl_from_nsIHttpChannel(iface);
653 TRACE("(%p)->(%p)\n", This, aLoadGroup);
655 if(This->load_group)
656 nsILoadGroup_Release(This->load_group);
657 if(aLoadGroup)
658 nsILoadGroup_AddRef(aLoadGroup);
659 This->load_group = aLoadGroup;
661 return NS_OK;
664 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
666 nsChannel *This = impl_from_nsIHttpChannel(iface);
668 TRACE("(%p)->(%p)\n", This, aLoadFlags);
670 *aLoadFlags = This->load_flags;
671 return NS_OK;
674 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
676 nsChannel *This = impl_from_nsIHttpChannel(iface);
678 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
680 This->load_flags = aLoadFlags;
681 return NS_OK;
684 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
686 nsChannel *This = impl_from_nsIHttpChannel(iface);
688 TRACE("(%p)->(%p)\n", This, aOriginalURI);
690 if(This->original_uri)
691 nsIURI_AddRef(This->original_uri);
693 *aOriginalURI = This->original_uri;
694 return NS_OK;
697 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
699 nsChannel *This = impl_from_nsIHttpChannel(iface);
701 TRACE("(%p)->(%p)\n", This, aOriginalURI);
703 if(This->original_uri)
704 nsIURI_Release(This->original_uri);
706 nsIURI_AddRef(aOriginalURI);
707 This->original_uri = aOriginalURI;
708 return NS_OK;
711 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
713 nsChannel *This = impl_from_nsIHttpChannel(iface);
715 TRACE("(%p)->(%p)\n", This, aURI);
717 nsIFileURL_AddRef(&This->uri->nsIFileURL_iface);
718 *aURI = (nsIURI*)&This->uri->nsIFileURL_iface;
720 return NS_OK;
723 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
725 nsChannel *This = impl_from_nsIHttpChannel(iface);
727 TRACE("(%p)->(%p)\n", This, aOwner);
729 if(This->owner)
730 nsISupports_AddRef(This->owner);
731 *aOwner = This->owner;
733 return NS_OK;
736 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
738 nsChannel *This = impl_from_nsIHttpChannel(iface);
740 TRACE("(%p)->(%p)\n", This, aOwner);
742 if(aOwner)
743 nsISupports_AddRef(aOwner);
744 if(This->owner)
745 nsISupports_Release(This->owner);
746 This->owner = aOwner;
748 return NS_OK;
751 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
752 nsIInterfaceRequestor **aNotificationCallbacks)
754 nsChannel *This = impl_from_nsIHttpChannel(iface);
756 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
758 if(This->notif_callback)
759 nsIInterfaceRequestor_AddRef(This->notif_callback);
760 *aNotificationCallbacks = This->notif_callback;
762 return NS_OK;
765 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
766 nsIInterfaceRequestor *aNotificationCallbacks)
768 nsChannel *This = impl_from_nsIHttpChannel(iface);
770 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
772 if(This->notif_callback)
773 nsIInterfaceRequestor_Release(This->notif_callback);
774 if(aNotificationCallbacks)
775 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
777 This->notif_callback = aNotificationCallbacks;
779 return NS_OK;
782 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
784 nsChannel *This = impl_from_nsIHttpChannel(iface);
786 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
788 return NS_ERROR_NOT_IMPLEMENTED;
791 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
793 nsChannel *This = impl_from_nsIHttpChannel(iface);
795 TRACE("(%p)->(%p)\n", This, aContentType);
797 if(This->content_type) {
798 nsACString_SetData(aContentType, This->content_type);
799 return S_OK;
802 if(This->load_flags & LOAD_DOCUMENT_URI) {
803 WARN("Document channel with no MIME set. Assuming text/html\n");
804 nsACString_SetData(aContentType, "text/html");
805 return S_OK;
808 WARN("unknown type\n");
809 return NS_ERROR_FAILURE;
812 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
813 const nsACString *aContentType)
815 nsChannel *This = impl_from_nsIHttpChannel(iface);
816 const char *content_type;
818 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
820 nsACString_GetData(aContentType, &content_type);
821 heap_free(This->content_type);
822 This->content_type = heap_strdupA(content_type);
824 return NS_OK;
827 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
828 nsACString *aContentCharset)
830 nsChannel *This = impl_from_nsIHttpChannel(iface);
832 TRACE("(%p)->(%p)\n", This, aContentCharset);
834 if(This->charset) {
835 nsACString_SetData(aContentCharset, This->charset);
836 return NS_OK;
839 nsACString_SetData(aContentCharset, "");
840 return NS_OK;
843 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
844 const nsACString *aContentCharset)
846 nsChannel *This = impl_from_nsIHttpChannel(iface);
847 const char *data;
848 char *charset;
850 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
852 nsACString_GetData(aContentCharset, &data);
853 charset = heap_strdupA(data);
854 if(!charset)
855 return NS_ERROR_OUT_OF_MEMORY;
857 heap_free(This->charset);
858 This->charset = charset;
859 return NS_OK;
862 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, INT64 *aContentLength)
864 nsChannel *This = impl_from_nsIHttpChannel(iface);
866 FIXME("(%p)->(%p)\n", This, aContentLength);
868 return NS_ERROR_NOT_IMPLEMENTED;
871 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, INT64 aContentLength)
873 nsChannel *This = impl_from_nsIHttpChannel(iface);
875 FIXME("(%p)->(%s)\n", This, wine_dbgstr_longlong(aContentLength));
877 return NS_ERROR_NOT_IMPLEMENTED;
880 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
882 nsChannel *This = impl_from_nsIHttpChannel(iface);
884 FIXME("(%p)->(%p)\n", This, _retval);
886 return NS_ERROR_NOT_IMPLEMENTED;
889 static nsresult NSAPI nsChannel_Open2(nsIHttpChannel *iface, nsIInputStream **_retval)
891 nsChannel *This = impl_from_nsIHttpChannel(iface);
893 FIXME("(%p)->(%p)\n", This, _retval);
895 return NS_ERROR_NOT_IMPLEMENTED;
898 static HTMLOuterWindow *get_channel_window(nsChannel *This)
900 nsIWebProgress *web_progress = NULL;
901 mozIDOMWindowProxy *mozwindow;
902 HTMLOuterWindow *window;
903 nsresult nsres;
905 if(This->load_group) {
906 nsIRequestObserver *req_observer;
908 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
909 if(NS_FAILED(nsres)) {
910 ERR("GetGroupObserver failed: %08x\n", nsres);
911 return NULL;
914 if(req_observer) {
915 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
916 nsIRequestObserver_Release(req_observer);
917 if(NS_FAILED(nsres)) {
918 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
919 return NULL;
924 if(!web_progress && This->notif_callback) {
925 nsres = nsIInterfaceRequestor_GetInterface(This->notif_callback, &IID_nsIWebProgress, (void**)&web_progress);
926 if(NS_FAILED(nsres)) {
927 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres);
928 return NULL;
932 if(!web_progress) {
933 ERR("Could not find nsIWebProgress\n");
934 return NULL;
937 nsres = nsIWebProgress_GetDOMWindow(web_progress, &mozwindow);
938 nsIWebProgress_Release(web_progress);
939 if(NS_FAILED(nsres) || !mozwindow) {
940 ERR("GetDOMWindow failed: %08x\n", nsres);
941 return NULL;
944 window = mozwindow_to_window(mozwindow);
945 mozIDOMWindowProxy_Release(mozwindow);
947 if(window)
948 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
949 else
950 FIXME("NULL window for %p\n", mozwindow);
951 return window;
954 typedef struct {
955 task_t header;
956 HTMLInnerWindow *window;
957 nsChannelBSC *bscallback;
958 } start_binding_task_t;
960 static void start_binding_proc(task_t *_task)
962 start_binding_task_t *task = (start_binding_task_t*)_task;
964 start_binding(task->window, (BSCallback*)task->bscallback, NULL);
967 static void start_binding_task_destr(task_t *_task)
969 start_binding_task_t *task = (start_binding_task_t*)_task;
971 IBindStatusCallback_Release(&task->bscallback->bsc.IBindStatusCallback_iface);
972 heap_free(task);
975 static nsresult async_open(nsChannel *This, HTMLOuterWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
976 nsISupports *context)
978 nsChannelBSC *bscallback;
979 IMoniker *mon = NULL;
980 HRESULT hres;
982 hres = CreateURLMonikerEx2(NULL, This->uri->uri, &mon, 0);
983 if(FAILED(hres)) {
984 WARN("CreateURLMoniker failed: %08x\n", hres);
985 return NS_ERROR_UNEXPECTED;
988 if(is_doc_channel)
989 set_current_mon(window, mon, BINDING_NAVIGATED);
991 hres = create_channelbsc(mon, NULL, NULL, 0, is_doc_channel, &bscallback);
992 IMoniker_Release(mon);
993 if(FAILED(hres))
994 return NS_ERROR_UNEXPECTED;
996 channelbsc_set_channel(bscallback, This, listener, context);
998 if(is_doc_channel) {
999 hres = create_pending_window(window, bscallback);
1000 if(SUCCEEDED(hres))
1001 async_start_doc_binding(window, window->pending_window);
1002 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1003 if(FAILED(hres))
1004 return NS_ERROR_UNEXPECTED;
1005 }else {
1006 start_binding_task_t *task;
1008 task = heap_alloc(sizeof(start_binding_task_t));
1009 if(!task) {
1010 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
1011 return NS_ERROR_OUT_OF_MEMORY;
1014 task->window = window->base.inner_window;
1015 task->bscallback = bscallback;
1016 hres = push_task(&task->header, start_binding_proc, start_binding_task_destr, window->base.inner_window->task_magic);
1017 if(FAILED(hres))
1018 return NS_ERROR_OUT_OF_MEMORY;
1021 return NS_OK;
1024 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
1025 nsISupports *aContext)
1027 nsChannel *This = impl_from_nsIHttpChannel(iface);
1028 HTMLOuterWindow *window = NULL;
1029 BOOL is_document_channel;
1030 BOOL cancel = FALSE;
1031 nsresult nsres = NS_OK;
1033 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
1035 if(!ensure_uri(This->uri))
1036 return NS_ERROR_FAILURE;
1038 if(TRACE_ON(mshtml)) {
1039 HRESULT hres;
1040 BSTR uri_str;
1042 hres = IUri_GetDisplayUri(This->uri->uri, &uri_str);
1043 if(SUCCEEDED(hres)) {
1044 TRACE("opening %s\n", debugstr_w(uri_str));
1045 SysFreeString(uri_str);
1046 }else {
1047 WARN("GetDisplayUri failed: %08x\n", hres);
1051 window = get_channel_window(This);
1052 if(!window) {
1053 ERR("window = NULL\n");
1054 return NS_ERROR_UNEXPECTED;
1057 is_document_channel = !!(This->load_flags & LOAD_DOCUMENT_URI);
1059 if(is_document_channel) {
1060 if(This->uri->channel_bsc) {
1061 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1062 cancel = TRUE;
1065 if(is_main_content_window(window)) {
1066 if(!This->uri->channel_bsc) {
1067 /* top window navigation initiated by Gecko */
1068 nsres = before_async_open(This, window->browser, &cancel);
1069 if(NS_SUCCEEDED(nsres) && cancel) {
1070 TRACE("canceled\n");
1071 nsres = NS_BINDING_ABORTED;
1073 }else if(window->browser->doc->mime) {
1074 heap_free(This->content_type);
1075 This->content_type = heap_strdupWtoA(window->browser->doc->mime);
1080 if(!cancel)
1081 nsres = async_open(This, window, is_document_channel, aListener, aContext);
1083 if(NS_SUCCEEDED(nsres) && This->load_group) {
1084 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)&This->nsIHttpChannel_iface,
1085 aContext);
1086 if(NS_FAILED(nsres))
1087 ERR("AddRequest failed: %08x\n", nsres);
1090 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
1091 return nsres;
1094 static nsresult NSAPI nsChannel_AsyncOpen2(nsIHttpChannel *iface, nsIStreamListener *aListener)
1096 nsChannel *This = impl_from_nsIHttpChannel(iface);
1097 FIXME("(%p)->(%p)\n", This, aListener);
1098 return nsIHttpChannel_AsyncOpen(&This->nsIHttpChannel_iface, aListener, NULL);
1101 static nsresult NSAPI nsChannel_GetContentDisposition(nsIHttpChannel *iface, UINT32 *aContentDisposition)
1103 nsChannel *This = impl_from_nsIHttpChannel(iface);
1104 TRACE("(%p)->(%p) unimplemented\n", This, aContentDisposition);
1105 return NS_ERROR_NOT_IMPLEMENTED;
1108 static nsresult NSAPI nsChannel_SetContentDisposition(nsIHttpChannel *iface, UINT32 aContentDisposition)
1110 nsChannel *This = impl_from_nsIHttpChannel(iface);
1111 FIXME("(%p)->(%u)\n", This, aContentDisposition);
1112 return NS_ERROR_NOT_IMPLEMENTED;
1115 static nsresult NSAPI nsChannel_GetContentDispositionFilename(nsIHttpChannel *iface, nsAString *aContentDispositionFilename)
1117 nsChannel *This = impl_from_nsIHttpChannel(iface);
1118 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1119 return NS_ERROR_NOT_IMPLEMENTED;
1122 static nsresult NSAPI nsChannel_SetContentDispositionFilename(nsIHttpChannel *iface, const nsAString *aContentDispositionFilename)
1124 nsChannel *This = impl_from_nsIHttpChannel(iface);
1125 FIXME("(%p)->(%p)\n", This, aContentDispositionFilename);
1126 return NS_ERROR_NOT_IMPLEMENTED;
1129 static nsresult NSAPI nsChannel_GetContentDispositionHeader(nsIHttpChannel *iface, nsACString *aContentDispositionHeader)
1131 nsChannel *This = impl_from_nsIHttpChannel(iface);
1132 TRACE("(%p)->(%p) unimplemented\n", This, aContentDispositionHeader);
1133 return NS_ERROR_NOT_IMPLEMENTED;
1136 static nsresult NSAPI nsChannel_GetLoadInfo(nsIHttpChannel *iface, nsILoadInfo **aLoadInfo)
1138 nsChannel *This = impl_from_nsIHttpChannel(iface);
1140 TRACE("(%p)->(%p)\n", This, aLoadInfo);
1142 if(This->load_info)
1143 nsISupports_AddRef(This->load_info);
1144 *aLoadInfo = This->load_info;
1145 return NS_OK;
1148 static nsresult NSAPI nsChannel_SetLoadInfo(nsIHttpChannel *iface, nsILoadInfo *aLoadInfo)
1150 nsChannel *This = impl_from_nsIHttpChannel(iface);
1152 TRACE("(%p)->(%p)\n", This, aLoadInfo);
1154 if(This->load_info)
1155 nsISupports_Release(This->load_info);
1156 This->load_info = aLoadInfo;
1157 if(This->load_info)
1158 nsISupports_AddRef(This->load_info);
1159 return NS_OK;
1162 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1164 nsChannel *This = impl_from_nsIHttpChannel(iface);
1166 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1168 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1169 return NS_OK;
1172 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1173 const nsACString *aRequestMethod)
1175 nsChannel *This = impl_from_nsIHttpChannel(iface);
1176 const char *method;
1177 unsigned i;
1179 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1181 nsACString_GetData(aRequestMethod, &method);
1182 for(i=0; i < ARRAY_SIZE(request_method_strings); i++) {
1183 if(!stricmp(method, request_method_strings[i])) {
1184 This->request_method = i;
1185 return NS_OK;
1189 ERR("Invalid method %s\n", debugstr_a(method));
1190 return NS_ERROR_UNEXPECTED;
1193 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1195 nsChannel *This = impl_from_nsIHttpChannel(iface);
1197 TRACE("(%p)->(%p)\n", This, aReferrer);
1199 if(This->referrer)
1200 nsIURI_AddRef(This->referrer);
1201 *aReferrer = This->referrer;
1202 return NS_OK;
1205 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1207 nsChannel *This = impl_from_nsIHttpChannel(iface);
1209 TRACE("(%p)->(%p)\n", This, aReferrer);
1211 return nsIHttpChannel_SetReferrerWithPolicy(&This->nsIHttpChannel_iface, aReferrer, 0);
1214 static nsresult NSAPI nsChannel_GetReferrerPolicy(nsIHttpChannel *iface, UINT32 *aReferrerPolicy)
1216 nsChannel *This = impl_from_nsIHttpChannel(iface);
1217 TRACE("(%p)->(%p) unimplemented\n", This, aReferrerPolicy);
1218 return NS_ERROR_NOT_IMPLEMENTED;
1221 static nsresult NSAPI nsChannel_SetReferrerWithPolicy(nsIHttpChannel *iface, nsIURI *aReferrer, UINT32 aReferrerPolicy)
1223 nsChannel *This = impl_from_nsIHttpChannel(iface);
1224 DWORD channel_scheme, referrer_scheme;
1225 nsWineURI *referrer;
1226 BSTR referrer_uri;
1227 nsresult nsres;
1228 HRESULT hres;
1230 static const WCHAR refererW[] = {'R','e','f','e','r','e','r'};
1232 TRACE("(%p)->(%p %d)\n", This, aReferrer, aReferrerPolicy);
1234 if(aReferrerPolicy)
1235 FIXME("refferer policy %d not implemented\n", aReferrerPolicy);
1237 if(This->referrer) {
1238 nsIURI_Release(This->referrer);
1239 This->referrer = NULL;
1241 if(!aReferrer)
1242 return NS_OK;
1244 nsres = nsIURI_QueryInterface(aReferrer, &IID_nsWineURI, (void**)&referrer);
1245 if(NS_FAILED(nsres))
1246 return NS_OK;
1248 if(!ensure_uri(referrer)) {
1249 nsIFileURL_Release(&referrer->nsIFileURL_iface);
1250 return NS_ERROR_UNEXPECTED;
1253 if(!ensure_uri(This->uri) || FAILED(IUri_GetScheme(This->uri->uri, &channel_scheme)))
1254 channel_scheme = INTERNET_SCHEME_UNKNOWN;
1256 if(FAILED(IUri_GetScheme(referrer->uri, &referrer_scheme)))
1257 referrer_scheme = INTERNET_SCHEME_UNKNOWN;
1259 if(referrer_scheme == INTERNET_SCHEME_HTTPS && channel_scheme != INTERNET_SCHEME_HTTPS) {
1260 TRACE("Ignoring https referrer on non-https channel\n");
1261 nsIFileURL_Release(&referrer->nsIFileURL_iface);
1262 return NS_OK;
1265 hres = IUri_GetDisplayUri(referrer->uri, &referrer_uri);
1266 if(SUCCEEDED(hres)) {
1267 set_http_header(&This->request_headers, refererW, ARRAY_SIZE(refererW), referrer_uri, SysStringLen(referrer_uri));
1268 SysFreeString(referrer_uri);
1271 This->referrer = (nsIURI*)&referrer->nsIFileURL_iface;
1272 return NS_OK;
1275 static nsresult NSAPI nsHttpChannel_GetProtocolVersion(nsIHttpChannel *iface, nsACString *aProtocolVersion)
1277 nsChannel *This = impl_from_nsIHttpChannel(iface);
1278 FIXME("(%p)->(%p)\n", This, aProtocolVersion);
1279 return NS_ERROR_NOT_IMPLEMENTED;
1282 static nsresult NSAPI nsHttpChannel_GetTransferSize(nsIHttpChannel *iface, UINT64 *aTransferSize)
1284 nsChannel *This = impl_from_nsIHttpChannel(iface);
1285 FIXME("(%p)->(%p)\n", This, aTransferSize);
1286 return NS_ERROR_NOT_IMPLEMENTED;
1289 static nsresult NSAPI nsHttpChannel_GetDecodedBodySize(nsIHttpChannel *iface, UINT64 *aDecodedBodySize)
1291 nsChannel *This = impl_from_nsIHttpChannel(iface);
1292 FIXME("(%p)->(%p)\n", This, aDecodedBodySize);
1293 return NS_ERROR_NOT_IMPLEMENTED;
1296 static nsresult NSAPI nsHttpChannel_GetEncodedBodySize(nsIHttpChannel *iface, UINT64 *aEncodedBodySize)
1298 nsChannel *This = impl_from_nsIHttpChannel(iface);
1299 FIXME("(%p)->(%p)\n", This, aEncodedBodySize);
1300 return NS_ERROR_NOT_IMPLEMENTED;
1303 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1304 const nsACString *aHeader, nsACString *_retval)
1306 nsChannel *This = impl_from_nsIHttpChannel(iface);
1308 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1310 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1313 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1314 const nsACString *aHeader, const nsACString *aValue, cpp_bool aMerge)
1316 nsChannel *This = impl_from_nsIHttpChannel(iface);
1318 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1320 if(aMerge)
1321 FIXME("aMerge not supported\n");
1323 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1326 static nsresult NSAPI nsChannel_SetEmptyRequestHeader(nsIHttpChannel *iface, const nsACString *aHeader)
1328 nsChannel *This = impl_from_nsIHttpChannel(iface);
1329 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aHeader));
1330 return NS_ERROR_NOT_IMPLEMENTED;
1333 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1334 nsIHttpHeaderVisitor *aVisitor)
1336 nsChannel *This = impl_from_nsIHttpChannel(iface);
1338 FIXME("(%p)->(%p)\n", This, aVisitor);
1340 return NS_ERROR_NOT_IMPLEMENTED;
1343 static nsresult NSAPI nsChannel_VisitNonDefaultRequestHeaders(nsIHttpChannel *iface, nsIHttpHeaderVisitor *aVisitor)
1345 nsChannel *This = impl_from_nsIHttpChannel(iface);
1346 FIXME("(%p)->(%p)\n", This, aVisitor);
1347 return NS_ERROR_NOT_IMPLEMENTED;
1350 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, cpp_bool *aAllowPipelining)
1352 nsChannel *This = impl_from_nsIHttpChannel(iface);
1354 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1356 return NS_ERROR_NOT_IMPLEMENTED;
1359 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, cpp_bool aAllowPipelining)
1361 nsChannel *This = impl_from_nsIHttpChannel(iface);
1363 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1365 return NS_ERROR_NOT_IMPLEMENTED;
1368 static nsresult NSAPI nsChannel_GetAllowTLS(nsIHttpChannel *iface, cpp_bool *aAllowTLS)
1370 nsChannel *This = impl_from_nsIHttpChannel(iface);
1371 FIXME("(%p)->(%p)\n", This, aAllowTLS);
1372 return NS_ERROR_NOT_IMPLEMENTED;
1375 static nsresult NSAPI nsChannel_SetAllowTLS(nsIHttpChannel *iface, cpp_bool aAllowTLS)
1377 nsChannel *This = impl_from_nsIHttpChannel(iface);
1378 FIXME("(%p)->(%x)\n", This, aAllowTLS);
1379 return NS_ERROR_NOT_IMPLEMENTED;
1382 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, UINT32 *aRedirectionLimit)
1384 nsChannel *This = impl_from_nsIHttpChannel(iface);
1386 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1388 return NS_ERROR_NOT_IMPLEMENTED;
1391 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, UINT32 aRedirectionLimit)
1393 nsChannel *This = impl_from_nsIHttpChannel(iface);
1395 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1397 return NS_ERROR_NOT_IMPLEMENTED;
1400 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, UINT32 *aResponseStatus)
1402 nsChannel *This = impl_from_nsIHttpChannel(iface);
1404 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1406 if(This->response_status) {
1407 *aResponseStatus = This->response_status;
1408 return NS_OK;
1411 WARN("No response status\n");
1412 return NS_ERROR_UNEXPECTED;
1415 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1416 nsACString *aResponseStatusText)
1418 nsChannel *This = impl_from_nsIHttpChannel(iface);
1420 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
1422 nsACString_SetData(aResponseStatusText, This->response_status_text);
1423 return NS_OK;
1426 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1427 cpp_bool *aRequestSucceeded)
1429 nsChannel *This = impl_from_nsIHttpChannel(iface);
1431 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1433 if(!This->response_status)
1434 return NS_ERROR_NOT_AVAILABLE;
1436 *aRequestSucceeded = This->response_status/100 == 2;
1438 return NS_OK;
1441 static nsresult NSAPI nsChannel_GetIsMainDocumentChannel(nsIHttpChannel *iface, cpp_bool *aIsMainDocumentChannel)
1443 nsChannel *This = impl_from_nsIHttpChannel(iface);
1444 FIXME("(%p)->(%p)\n", This, aIsMainDocumentChannel);
1445 return NS_ERROR_NOT_IMPLEMENTED;
1448 static nsresult NSAPI nsChannel_SetIsMainDocumentChannel(nsIHttpChannel *iface, cpp_bool aIsMainDocumentChannel)
1450 nsChannel *This = impl_from_nsIHttpChannel(iface);
1451 FIXME("(%p)->(%x)\n", This, aIsMainDocumentChannel);
1452 return NS_ERROR_NOT_IMPLEMENTED;
1455 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1456 const nsACString *header, nsACString *_retval)
1458 nsChannel *This = impl_from_nsIHttpChannel(iface);
1460 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1462 return get_channel_http_header(&This->response_headers, header, _retval);
1465 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1466 const nsACString *header, const nsACString *value, cpp_bool merge)
1468 nsChannel *This = impl_from_nsIHttpChannel(iface);
1470 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1472 return NS_ERROR_NOT_IMPLEMENTED;
1475 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1476 nsIHttpHeaderVisitor *aVisitor)
1478 nsChannel *This = impl_from_nsIHttpChannel(iface);
1480 TRACE("(%p)->(%p)\n", This, aVisitor);
1482 return visit_http_headers(&This->response_headers, aVisitor);
1485 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1487 nsChannel *This = impl_from_nsIHttpChannel(iface);
1488 http_header_t *header;
1490 static const WCHAR cache_controlW[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1492 TRACE("(%p)->(%p)\n", This, _retval);
1494 header = find_http_header(&This->response_headers, cache_controlW, ARRAY_SIZE(cache_controlW));
1495 *_retval = header && !wcsicmp(header->data, L"no-store");
1496 return NS_OK;
1499 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1501 nsChannel *This = impl_from_nsIHttpChannel(iface);
1503 FIXME("(%p)->(%p)\n", This, _retval);
1505 return NS_ERROR_NOT_IMPLEMENTED;
1508 static nsresult NSAPI nsChannel_IsPrivateResponse(nsIHttpChannel *iface, cpp_bool *_retval)
1510 nsChannel *This = impl_from_nsIHttpChannel(iface);
1512 FIXME("(%p)->(%p)\n", This, _retval);
1514 return NS_ERROR_NOT_IMPLEMENTED;
1517 static nsresult NSAPI nsChannel_RedirectTo(nsIHttpChannel *iface, nsIURI *aTargetURI)
1519 nsChannel *This = impl_from_nsIHttpChannel(iface);
1521 FIXME("(%p)->(%p)\n", This, aTargetURI);
1523 return NS_ERROR_NOT_IMPLEMENTED;
1526 static nsresult NSAPI nsHttpChannel_GetSchedulingContextID(nsIHttpChannel *iface, nsIID *aSchedulingContextID)
1528 nsChannel *This = impl_from_nsIHttpChannel(iface);
1530 FIXME("(%p)->(%p)\n", This, aSchedulingContextID);
1532 return NS_ERROR_NOT_IMPLEMENTED;
1535 static nsresult NSAPI nsHttpChannel_SetSchedulingContextID(nsIHttpChannel *iface, const nsIID aSchedulingContextID)
1537 nsChannel *This = impl_from_nsIHttpChannel(iface);
1539 FIXME("(%p)->(%s)\n", This, debugstr_guid(&aSchedulingContextID));
1541 return NS_ERROR_NOT_IMPLEMENTED;
1544 static const nsIHttpChannelVtbl nsChannelVtbl = {
1545 nsChannel_QueryInterface,
1546 nsChannel_AddRef,
1547 nsChannel_Release,
1548 nsChannel_GetName,
1549 nsChannel_IsPending,
1550 nsChannel_GetStatus,
1551 nsChannel_Cancel,
1552 nsChannel_Suspend,
1553 nsChannel_Resume,
1554 nsChannel_GetLoadGroup,
1555 nsChannel_SetLoadGroup,
1556 nsChannel_GetLoadFlags,
1557 nsChannel_SetLoadFlags,
1558 nsChannel_GetOriginalURI,
1559 nsChannel_SetOriginalURI,
1560 nsChannel_GetURI,
1561 nsChannel_GetOwner,
1562 nsChannel_SetOwner,
1563 nsChannel_GetNotificationCallbacks,
1564 nsChannel_SetNotificationCallbacks,
1565 nsChannel_GetSecurityInfo,
1566 nsChannel_GetContentType,
1567 nsChannel_SetContentType,
1568 nsChannel_GetContentCharset,
1569 nsChannel_SetContentCharset,
1570 nsChannel_GetContentLength,
1571 nsChannel_SetContentLength,
1572 nsChannel_Open,
1573 nsChannel_Open2,
1574 nsChannel_AsyncOpen,
1575 nsChannel_AsyncOpen2,
1576 nsChannel_GetContentDisposition,
1577 nsChannel_SetContentDisposition,
1578 nsChannel_GetContentDispositionFilename,
1579 nsChannel_SetContentDispositionFilename,
1580 nsChannel_GetContentDispositionHeader,
1581 nsChannel_GetLoadInfo,
1582 nsChannel_SetLoadInfo,
1583 nsChannel_GetRequestMethod,
1584 nsChannel_SetRequestMethod,
1585 nsChannel_GetReferrer,
1586 nsChannel_SetReferrer,
1587 nsChannel_GetReferrerPolicy,
1588 nsChannel_SetReferrerWithPolicy,
1589 nsHttpChannel_GetProtocolVersion,
1590 nsHttpChannel_GetTransferSize,
1591 nsHttpChannel_GetDecodedBodySize,
1592 nsHttpChannel_GetEncodedBodySize,
1593 nsChannel_GetRequestHeader,
1594 nsChannel_SetRequestHeader,
1595 nsChannel_SetEmptyRequestHeader,
1596 nsChannel_VisitRequestHeaders,
1597 nsChannel_VisitNonDefaultRequestHeaders,
1598 nsChannel_GetAllowPipelining,
1599 nsChannel_SetAllowPipelining,
1600 nsChannel_GetAllowTLS,
1601 nsChannel_SetAllowTLS,
1602 nsChannel_GetRedirectionLimit,
1603 nsChannel_SetRedirectionLimit,
1604 nsChannel_GetResponseStatus,
1605 nsChannel_GetResponseStatusText,
1606 nsChannel_GetRequestSucceeded,
1607 nsChannel_GetIsMainDocumentChannel,
1608 nsChannel_SetIsMainDocumentChannel,
1609 nsChannel_GetResponseHeader,
1610 nsChannel_SetResponseHeader,
1611 nsChannel_VisitResponseHeaders,
1612 nsChannel_IsNoStoreResponse,
1613 nsChannel_IsNoCacheResponse,
1614 nsChannel_IsPrivateResponse,
1615 nsChannel_RedirectTo,
1616 nsHttpChannel_GetSchedulingContextID,
1617 nsHttpChannel_SetSchedulingContextID
1620 static inline nsChannel *impl_from_nsIUploadChannel(nsIUploadChannel *iface)
1622 return CONTAINING_RECORD(iface, nsChannel, nsIUploadChannel_iface);
1625 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1626 void **result)
1628 nsChannel *This = impl_from_nsIUploadChannel(iface);
1629 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1632 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1634 nsChannel *This = impl_from_nsIUploadChannel(iface);
1635 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1638 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1640 nsChannel *This = impl_from_nsIUploadChannel(iface);
1641 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1644 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1645 nsIInputStream *aStream, const nsACString *aContentType, INT64 aContentLength)
1647 nsChannel *This = impl_from_nsIUploadChannel(iface);
1648 const char *content_type;
1650 static const WCHAR content_typeW[] =
1651 {'C','o','n','t','e','n','t','-','T','y','p','e'};
1653 TRACE("(%p)->(%p %s %s)\n", This, aStream, debugstr_nsacstr(aContentType), wine_dbgstr_longlong(aContentLength));
1655 This->post_data_contains_headers = TRUE;
1657 if(aContentType) {
1658 nsACString_GetData(aContentType, &content_type);
1659 if(*content_type) {
1660 WCHAR *ct;
1662 ct = heap_strdupAtoW(content_type);
1663 if(!ct)
1664 return NS_ERROR_UNEXPECTED;
1666 set_http_header(&This->request_headers, content_typeW, ARRAY_SIZE(content_typeW), ct, lstrlenW(ct));
1667 heap_free(ct);
1668 This->post_data_contains_headers = FALSE;
1672 if(aContentLength != -1)
1673 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength));
1675 if(This->post_data_stream)
1676 nsIInputStream_Release(This->post_data_stream);
1677 This->post_data_stream = aStream;
1678 if(aStream)
1679 nsIInputStream_AddRef(aStream);
1681 This->request_method = METHOD_POST;
1682 return NS_OK;
1685 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1686 nsIInputStream **aUploadStream)
1688 nsChannel *This = impl_from_nsIUploadChannel(iface);
1690 TRACE("(%p)->(%p)\n", This, aUploadStream);
1692 if(This->post_data_stream)
1693 nsIInputStream_AddRef(This->post_data_stream);
1695 *aUploadStream = This->post_data_stream;
1696 return NS_OK;
1699 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1700 nsUploadChannel_QueryInterface,
1701 nsUploadChannel_AddRef,
1702 nsUploadChannel_Release,
1703 nsUploadChannel_SetUploadStream,
1704 nsUploadChannel_GetUploadStream
1707 static inline nsChannel *impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal *iface)
1709 return CONTAINING_RECORD(iface, nsChannel, nsIHttpChannelInternal_iface);
1712 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1713 void **result)
1715 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1716 return nsIHttpChannel_QueryInterface(&This->nsIHttpChannel_iface, riid, result);
1719 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1721 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1722 return nsIHttpChannel_AddRef(&This->nsIHttpChannel_iface);
1725 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1727 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1728 return nsIHttpChannel_Release(&This->nsIHttpChannel_iface);
1731 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1733 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1735 FIXME("(%p)->()\n", This);
1737 return NS_ERROR_NOT_IMPLEMENTED;
1740 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1742 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1744 TRACE("(%p)->() unimplemented\n", This);
1746 return NS_ERROR_NOT_IMPLEMENTED;
1749 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1751 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1753 FIXME("(%p)->()\n", This);
1755 return NS_ERROR_NOT_IMPLEMENTED;
1758 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, UINT32 *major, UINT32 *minor)
1760 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1762 FIXME("(%p)->()\n", This);
1764 return NS_ERROR_NOT_IMPLEMENTED;
1767 static nsresult NSAPI nsHttpChannelInternal_TakeAllSecurityMessages(nsIHttpChannelInternal *iface, void *aMessages)
1769 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1771 TRACE("(%p)->(%p) unimplemented\n", This, aMessages);
1773 return NS_ERROR_NOT_IMPLEMENTED;
1776 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1778 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1780 FIXME("(%p)->()\n", This);
1782 return NS_ERROR_NOT_IMPLEMENTED;
1785 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1787 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1789 FIXME("(%p)->()\n", This);
1791 return NS_ERROR_NOT_IMPLEMENTED;
1794 static nsresult NSAPI nsHttpChannelInternal_GetThirdPartyFlags(nsIHttpChannelInternal *iface, UINT32 *aThirdPartyFlags)
1796 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1797 FIXME("(%p)->(%p)\n", This, aThirdPartyFlags);
1798 return NS_ERROR_NOT_IMPLEMENTED;
1801 static nsresult NSAPI nsHttpChannelInternal_SetThirdPartyFlags(nsIHttpChannelInternal *iface, UINT32 aThirdPartyFlags)
1803 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1804 FIXME("(%p)->(%x)\n", This, aThirdPartyFlags);
1805 return NS_ERROR_NOT_IMPLEMENTED;
1808 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool *aForceThirdPartyCookie)
1810 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1812 FIXME("(%p)->()\n", This);
1814 return NS_ERROR_NOT_IMPLEMENTED;
1817 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, cpp_bool aForceThirdPartyCookie)
1819 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1821 FIXME("(%p)->()\n", This);
1823 return NS_ERROR_NOT_IMPLEMENTED;
1826 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1828 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1830 FIXME("(%p)->(%p)\n", This, aCanceled);
1832 return NS_ERROR_NOT_IMPLEMENTED;
1835 static nsresult NSAPI nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool *aCanceled)
1837 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1839 FIXME("(%p)->(%p)\n", This, aCanceled);
1841 return NS_ERROR_NOT_IMPLEMENTED;
1844 static nsresult NSAPI nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal *iface, cpp_bool aCanceled)
1846 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1848 FIXME("(%p)->(%x)\n", This, aCanceled);
1850 return NS_ERROR_NOT_IMPLEMENTED;
1853 static nsresult NSAPI nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal *iface, nsACString *aLocalAddress)
1855 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1857 FIXME("(%p)->(%p)\n", This, aLocalAddress);
1859 return NS_ERROR_NOT_IMPLEMENTED;
1862 static nsresult NSAPI nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal *iface, LONG *aLocalPort)
1864 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1866 FIXME("(%p)->(%p)\n", This, aLocalPort);
1868 return NS_ERROR_NOT_IMPLEMENTED;
1871 static nsresult NSAPI nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal *iface, nsACString *aRemoteAddress)
1873 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1875 FIXME("(%p)->(%p)\n", This, aRemoteAddress);
1877 return NS_ERROR_NOT_IMPLEMENTED;
1880 static nsresult NSAPI nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal *iface, LONG *aRemotePort)
1882 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1884 FIXME("(%p)->(%p)\n", This, aRemotePort);
1886 return NS_ERROR_NOT_IMPLEMENTED;
1889 static nsresult NSAPI nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal *iface, void *cacheKeys)
1891 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1893 FIXME("(%p)->(%p)\n", This, cacheKeys);
1895 return NS_ERROR_NOT_IMPLEMENTED;
1898 static nsresult NSAPI nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal *iface,
1899 const nsACString *aProtocolName, nsIHttpUpgradeListener *aListener)
1901 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1902 FIXME("(%p)->(%s %p)\n", This, debugstr_nsacstr(aProtocolName), aListener);
1903 return NS_ERROR_NOT_IMPLEMENTED;
1906 static nsresult NSAPI nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool *aAllowSpdy)
1908 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1909 FIXME("(%p)->(%p)\n", This, aAllowSpdy);
1910 return NS_ERROR_NOT_IMPLEMENTED;
1913 static nsresult NSAPI nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal *iface, cpp_bool aAllowSpdy)
1915 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1916 FIXME("(%p)->(%x)\n", This, aAllowSpdy);
1917 return NS_ERROR_NOT_IMPLEMENTED;
1920 static nsresult NSAPI nsHttpChannelInternal_GetResponseTimeoutEnabled(nsIHttpChannelInternal *iface,
1921 cpp_bool *aResponseTimeoutEnabled)
1923 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1924 FIXME("(%p)->(%p)\n", This, aResponseTimeoutEnabled);
1925 return NS_ERROR_NOT_IMPLEMENTED;
1928 static nsresult NSAPI nsHttpChannelInternal_SetResponseTimeoutEnabled(nsIHttpChannelInternal *iface,
1929 cpp_bool aResponseTimeoutEnabled)
1931 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1932 FIXME("(%p)->(%x)\n", This, aResponseTimeoutEnabled);
1933 return NS_ERROR_NOT_IMPLEMENTED;
1936 static nsresult NSAPI nsHttpChannelInternal_GetInitialRwin(nsIHttpChannelInternal *iface,
1937 UINT32 *aInitialRwin)
1939 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1940 FIXME("(%p)->(%p)\n", This, aInitialRwin);
1941 return NS_ERROR_NOT_IMPLEMENTED;
1944 static nsresult NSAPI nsHttpChannelInternal_SetInitialRwin(nsIHttpChannelInternal *iface,
1945 UINT32 aInitialRwin)
1947 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1948 FIXME("(%p)->(%x)\n", This, aInitialRwin);
1949 return NS_ERROR_NOT_IMPLEMENTED;
1952 static nsresult NSAPI nsHttpChannelInternal_GetApiRedirectToURI(nsIHttpChannelInternal *iface, nsIURI **aApiRedirectToURI)
1954 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1955 FIXME("(%p)->(%p)\n", This, aApiRedirectToURI);
1956 return NS_ERROR_NOT_IMPLEMENTED;
1959 static nsresult NSAPI nsHttpChannelInternal_GetAllowAltSvc(nsIHttpChannelInternal *iface, cpp_bool *aAllowAltSvc)
1961 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1962 FIXME("(%p)->(%p)\n", This, aAllowAltSvc);
1963 return NS_ERROR_NOT_IMPLEMENTED;
1966 static nsresult NSAPI nsHttpChannelInternal_SetAllowAltSvc(nsIHttpChannelInternal *iface, cpp_bool aAllowAltSvc)
1968 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1969 FIXME("(%p)->(%x)\n", This, aAllowAltSvc);
1970 return NS_ERROR_NOT_IMPLEMENTED;
1973 static nsresult NSAPI nsHttpChannelInternal_GetLastModifiedTime(nsIHttpChannelInternal *iface, PRTime *aLastModifiedTime)
1975 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1976 FIXME("(%p)->(%p)\n", This, aLastModifiedTime);
1977 return NS_ERROR_NOT_IMPLEMENTED;
1980 static nsresult NSAPI nsHttpChannelInternal_ForceIntercepted(nsIHttpChannelInternal *iface, UINT64 aInterceptionID)
1982 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1983 FIXME("(%p)->(%s)\n", This, wine_dbgstr_longlong(aInterceptionID));
1984 return NS_ERROR_NOT_IMPLEMENTED;
1987 static nsresult NSAPI nsHttpChannelInternal_GetResponseSynthesized(nsIHttpChannelInternal *iface, cpp_bool *ResponseSynthesized)
1989 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1990 FIXME("(%p, %p)\n", This, ResponseSynthesized);
1991 return NS_ERROR_NOT_IMPLEMENTED;
1994 static nsresult NSAPI nsHttpChannelInternal_GetCorsIncludeCredentials(nsIHttpChannelInternal *iface,
1995 cpp_bool *aCorsIncludeCredentials)
1997 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
1998 FIXME("(%p)->(%p)\n", This, aCorsIncludeCredentials);
1999 return NS_ERROR_NOT_IMPLEMENTED;
2002 static nsresult NSAPI nsHttpChannelInternal_SetCorsIncludeCredentials(nsIHttpChannelInternal *iface,
2003 cpp_bool aCorsIncludeCredentials)
2005 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2006 TRACE("(%p)->(%x)\n", This, aCorsIncludeCredentials);
2007 return NS_OK;
2010 static nsresult NSAPI nsHttpChannelInternal_GetCorsMode(nsIHttpChannelInternal *iface, UINT32 *aCorsMode)
2012 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2013 FIXME("(%p)->(%p)\n", This, aCorsMode);
2014 return NS_ERROR_NOT_IMPLEMENTED;
2017 static nsresult NSAPI nsHttpChannelInternal_SetCorsMode(nsIHttpChannelInternal *iface, UINT32 aCorsMode)
2019 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2020 TRACE("(%p)->(%d)\n", This, aCorsMode);
2021 return NS_OK;
2024 static nsresult NSAPI nsHttpChannelInternal_GetRedirectMode(nsIHttpChannelInternal *iface, UINT32 *aRedirectMode)
2026 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2027 FIXME("(%p)->(%p)\n", This, aRedirectMode);
2028 return NS_ERROR_NOT_IMPLEMENTED;
2031 static nsresult NSAPI nsHttpChannelInternal_SetRedirectMode(nsIHttpChannelInternal *iface, UINT32 aRedirectMode)
2033 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2034 TRACE("(%p)->(%d) unimplemented\n", This, aRedirectMode);
2035 return NS_ERROR_NOT_IMPLEMENTED;
2038 static nsresult NSAPI nsHttpChannelInternal_GetTopWindowURI(nsIHttpChannelInternal *iface, nsIURI **aTopWindowURI)
2040 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2041 FIXME("(%p)->(%p)\n", This, aTopWindowURI);
2042 return NS_ERROR_NOT_IMPLEMENTED;
2045 static nsresult NSAPI nsHttpChannelInternal_GetNetworkInterfaceId(nsIHttpChannelInternal *iface,
2046 nsACString *aNetworkInterfaceId)
2048 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2049 FIXME("(%p)->(%p)\n", This, aNetworkInterfaceId);
2050 return NS_ERROR_NOT_IMPLEMENTED;
2053 static nsresult NSAPI nsHttpChannelInternal_SetNetworkInterfaceId(nsIHttpChannelInternal *iface,
2054 const nsACString *aNetworkInterfaceId)
2056 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2057 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aNetworkInterfaceId));
2058 return NS_ERROR_NOT_IMPLEMENTED;
2061 static nsresult NSAPI nsHttpChannelInternal_GetProxyURI(nsIHttpChannelInternal *iface, nsIURI **aProxyURI)
2063 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2064 FIXME("(%p)->(%p)\n", This, aProxyURI);
2065 return NS_ERROR_NOT_IMPLEMENTED;
2068 static nsresult NSAPI nsHttpChannelInternal_SetCorsPreflightParameters(nsIHttpChannelInternal *iface,
2069 const void /*nsTArray<nsCString>*/ *unsafeHeaders)
2071 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2072 FIXME("(%p)->(%p)\n", This, unsafeHeaders);
2073 return NS_ERROR_NOT_IMPLEMENTED;
2076 static nsresult NSAPI nsHttpChannelInternal_GetBlockAuthPrompt(nsIHttpChannelInternal *iface, cpp_bool *aBlockAuthPrompt)
2078 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2079 FIXME("(%p)->(%p)\n", This, aBlockAuthPrompt);
2080 return NS_ERROR_NOT_IMPLEMENTED;
2083 static nsresult NSAPI nsHttpChannelInternal_SetBlockAuthPrompt(nsIHttpChannelInternal *iface, cpp_bool aBlockAuthPrompt)
2085 nsChannel *This = impl_from_nsIHttpChannelInternal(iface);
2086 FIXME("(%p)->(%x)\n", This, aBlockAuthPrompt);
2087 return NS_ERROR_NOT_IMPLEMENTED;
2090 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
2091 nsHttpChannelInternal_QueryInterface,
2092 nsHttpChannelInternal_AddRef,
2093 nsHttpChannelInternal_Release,
2094 nsHttpChannelInternal_GetDocumentURI,
2095 nsHttpChannelInternal_SetDocumentURI,
2096 nsHttpChannelInternal_GetRequestVersion,
2097 nsHttpChannelInternal_GetResponseVersion,
2098 nsHttpChannelInternal_TakeAllSecurityMessages,
2099 nsHttpChannelInternal_SetCookie,
2100 nsHttpChannelInternal_SetupFallbackChannel,
2101 nsHttpChannelInternal_GetThirdPartyFlags,
2102 nsHttpChannelInternal_SetThirdPartyFlags,
2103 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
2104 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
2105 nsHttpChannelInternal_GetCanceled,
2106 nsHttpChannelInternal_GetChannelIsForDownload,
2107 nsHttpChannelInternal_SetChannelIsForDownload,
2108 nsHttpChannelInternal_GetLocalAddress,
2109 nsHttpChannelInternal_GetLocalPort,
2110 nsHttpChannelInternal_GetRemoteAddress,
2111 nsHttpChannelInternal_GetRemotePort,
2112 nsHttpChannelInternal_SetCacheKeysRedirectChain,
2113 nsHttpChannelInternal_HTTPUpgrade,
2114 nsHttpChannelInternal_GetAllowSpdy,
2115 nsHttpChannelInternal_SetAllowSpdy,
2116 nsHttpChannelInternal_GetResponseTimeoutEnabled,
2117 nsHttpChannelInternal_SetResponseTimeoutEnabled,
2118 nsHttpChannelInternal_GetInitialRwin,
2119 nsHttpChannelInternal_SetInitialRwin,
2120 nsHttpChannelInternal_GetApiRedirectToURI,
2121 nsHttpChannelInternal_GetAllowAltSvc,
2122 nsHttpChannelInternal_SetAllowAltSvc,
2123 nsHttpChannelInternal_GetLastModifiedTime,
2124 nsHttpChannelInternal_ForceIntercepted,
2125 nsHttpChannelInternal_GetResponseSynthesized,
2126 nsHttpChannelInternal_GetCorsIncludeCredentials,
2127 nsHttpChannelInternal_SetCorsIncludeCredentials,
2128 nsHttpChannelInternal_GetCorsMode,
2129 nsHttpChannelInternal_SetCorsMode,
2130 nsHttpChannelInternal_GetRedirectMode,
2131 nsHttpChannelInternal_SetRedirectMode,
2132 nsHttpChannelInternal_GetTopWindowURI,
2133 nsHttpChannelInternal_GetNetworkInterfaceId,
2134 nsHttpChannelInternal_SetNetworkInterfaceId,
2135 nsHttpChannelInternal_GetProxyURI,
2136 nsHttpChannelInternal_SetCorsPreflightParameters,
2137 nsHttpChannelInternal_GetBlockAuthPrompt,
2138 nsHttpChannelInternal_SetBlockAuthPrompt
2142 static void invalidate_uri(nsWineURI *This)
2144 if(This->uri) {
2145 IUri_Release(This->uri);
2146 This->uri = NULL;
2150 static BOOL ensure_uri_builder(nsWineURI *This)
2152 if(!This->is_mutable) {
2153 WARN("Not mutable URI\n");
2154 return FALSE;
2157 if(!This->uri_builder) {
2158 HRESULT hres;
2160 if(!ensure_uri(This))
2161 return FALSE;
2163 hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
2164 if(FAILED(hres)) {
2165 WARN("CreateIUriBuilder failed: %08x\n", hres);
2166 return FALSE;
2170 invalidate_uri(This);
2171 return TRUE;
2174 static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
2176 char *vala;
2177 BSTR val;
2178 HRESULT hres;
2180 if(!ensure_uri(This))
2181 return NS_ERROR_UNEXPECTED;
2183 hres = IUri_GetPropertyBSTR(This->uri, prop, &val, 0);
2184 if(FAILED(hres)) {
2185 WARN("GetPropertyBSTR failed: %08x\n", hres);
2186 return NS_ERROR_UNEXPECTED;
2189 vala = heap_strdupWtoU(val);
2190 SysFreeString(val);
2191 if(!vala)
2192 return NS_ERROR_OUT_OF_MEMORY;
2194 TRACE("ret %s\n", debugstr_a(vala));
2195 nsACString_SetData(ret, vala);
2196 heap_free(vala);
2197 return NS_OK;
2200 static inline nsWineURI *impl_from_nsIFileURL(nsIFileURL *iface)
2202 return CONTAINING_RECORD(iface, nsWineURI, nsIFileURL_iface);
2205 static nsresult NSAPI nsURI_QueryInterface(nsIFileURL *iface, nsIIDRef riid, void **result)
2207 nsWineURI *This = impl_from_nsIFileURL(iface);
2209 *result = NULL;
2211 if(IsEqualGUID(&IID_nsISupports, riid)) {
2212 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2213 *result = &This->nsIFileURL_iface;
2214 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
2215 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
2216 *result = &This->nsIFileURL_iface;
2217 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
2218 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
2219 *result = &This->nsIFileURL_iface;
2220 }else if(IsEqualGUID(&IID_nsIFileURL, riid)) {
2221 TRACE("(%p)->(IID_nsIFileURL %p)\n", This, result);
2222 *result = This->scheme == URL_SCHEME_FILE ? &This->nsIFileURL_iface : NULL;
2223 }else if(IsEqualGUID(&IID_nsIMutable, riid)) {
2224 TRACE("(%p)->(IID_nsIMutable %p)\n", This, result);
2225 *result = &This->nsIStandardURL_iface;
2226 }else if(IsEqualGUID(&IID_nsIStandardURL, riid)) {
2227 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This, result);
2228 *result = &This->nsIStandardURL_iface;
2229 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
2230 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
2231 *result = This;
2234 if(*result) {
2235 nsIFileURL_AddRef(&This->nsIFileURL_iface);
2236 return NS_OK;
2239 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
2240 return NS_NOINTERFACE;
2243 static nsrefcnt NSAPI nsURI_AddRef(nsIFileURL *iface)
2245 nsWineURI *This = impl_from_nsIFileURL(iface);
2246 LONG ref = InterlockedIncrement(&This->ref);
2248 TRACE("(%p) ref=%d\n", This, ref);
2250 return ref;
2253 static nsrefcnt NSAPI nsURI_Release(nsIFileURL *iface)
2255 nsWineURI *This = impl_from_nsIFileURL(iface);
2256 LONG ref = InterlockedDecrement(&This->ref);
2258 TRACE("(%p) ref=%d\n", This, ref);
2260 if(!ref) {
2261 if(This->uri)
2262 IUri_Release(This->uri);
2263 if(This->uri_builder)
2264 IUriBuilder_Release(This->uri_builder);
2265 heap_free(This);
2268 return ref;
2271 static nsresult NSAPI nsURI_GetSpec(nsIFileURL *iface, nsACString *aSpec)
2273 nsWineURI *This = impl_from_nsIFileURL(iface);
2275 TRACE("(%p)->(%p)\n", This, aSpec);
2277 return get_uri_string(This, Uri_PROPERTY_DISPLAY_URI, aSpec);
2280 static nsresult NSAPI nsURI_SetSpec(nsIFileURL *iface, const nsACString *aSpec)
2282 nsWineURI *This = impl_from_nsIFileURL(iface);
2283 const char *speca;
2284 WCHAR *spec;
2285 IUri *uri;
2286 HRESULT hres;
2288 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aSpec));
2290 if(!This->is_mutable)
2291 return NS_ERROR_UNEXPECTED;
2293 nsACString_GetData(aSpec, &speca);
2294 spec = heap_strdupUtoW(speca);
2295 if(!spec)
2296 return NS_ERROR_OUT_OF_MEMORY;
2298 hres = create_uri(spec, 0, &uri);
2299 heap_free(spec);
2300 if(FAILED(hres)) {
2301 WARN("create_uri failed: %08x\n", hres);
2302 return NS_ERROR_FAILURE;
2305 invalidate_uri(This);
2306 if(This->uri_builder) {
2307 IUriBuilder_Release(This->uri_builder);
2308 This->uri_builder = NULL;
2311 This->uri = uri;
2312 return NS_OK;
2315 static nsresult NSAPI nsURI_GetPrePath(nsIFileURL *iface, nsACString *aPrePath)
2317 nsWineURI *This = impl_from_nsIFileURL(iface);
2318 IUriBuilder *uri_builder;
2319 BSTR display_uri;
2320 IUri *uri;
2321 int len;
2322 nsresult nsres;
2323 HRESULT hres;
2325 TRACE("(%p)->(%p)\n", This, aPrePath);
2327 if(!ensure_uri(This))
2328 return NS_ERROR_UNEXPECTED;
2330 hres = CreateIUriBuilder(This->uri, 0, 0, &uri_builder);
2331 if(FAILED(hres))
2332 return NS_ERROR_FAILURE;
2334 hres = IUriBuilder_RemoveProperties(uri_builder, Uri_HAS_PATH|Uri_HAS_QUERY|Uri_HAS_FRAGMENT);
2335 if(SUCCEEDED(hres))
2336 hres = IUriBuilder_CreateUriSimple(uri_builder, 0, 0, &uri);
2337 IUriBuilder_Release(uri_builder);
2338 if(FAILED(hres))
2339 return NS_ERROR_FAILURE;
2341 hres = IUri_GetDisplayUri(uri, &display_uri);
2342 IUri_Release(uri);
2343 if(FAILED(hres))
2344 return NS_ERROR_FAILURE;
2346 /* Remove trailing slash that may be appended as default path. */
2347 len = SysStringLen(display_uri);
2348 if(len && display_uri[len-1] == '/')
2349 display_uri[len-1] = 0;
2351 nsres = return_wstr_nsacstr(aPrePath, display_uri, -1);
2352 SysFreeString(display_uri);
2353 return nsres;
2356 static nsresult NSAPI nsURI_GetScheme(nsIFileURL *iface, nsACString *aScheme)
2358 nsWineURI *This = impl_from_nsIFileURL(iface);
2359 DWORD scheme;
2360 HRESULT hres;
2362 TRACE("(%p)->(%p)\n", This, aScheme);
2364 if(!ensure_uri(This))
2365 return NS_ERROR_UNEXPECTED;
2367 hres = IUri_GetScheme(This->uri, &scheme);
2368 if(FAILED(hres)) {
2369 WARN("GetScheme failed: %08x\n", hres);
2370 return NS_ERROR_UNEXPECTED;
2373 if(scheme == URL_SCHEME_ABOUT) {
2374 nsACString_SetData(aScheme, "wine");
2375 return NS_OK;
2378 return get_uri_string(This, Uri_PROPERTY_SCHEME_NAME, aScheme);
2381 static nsresult NSAPI nsURI_SetScheme(nsIFileURL *iface, const nsACString *aScheme)
2383 nsWineURI *This = impl_from_nsIFileURL(iface);
2384 const char *schemea;
2385 WCHAR *scheme;
2386 HRESULT hres;
2388 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
2390 if(!ensure_uri_builder(This))
2391 return NS_ERROR_UNEXPECTED;
2393 nsACString_GetData(aScheme, &schemea);
2394 scheme = heap_strdupUtoW(schemea);
2395 if(!scheme)
2396 return NS_ERROR_OUT_OF_MEMORY;
2398 hres = IUriBuilder_SetSchemeName(This->uri_builder, scheme);
2399 heap_free(scheme);
2400 if(FAILED(hres))
2401 return NS_ERROR_UNEXPECTED;
2403 return NS_OK;
2406 static nsresult NSAPI nsURI_GetUserPass(nsIFileURL *iface, nsACString *aUserPass)
2408 nsWineURI *This = impl_from_nsIFileURL(iface);
2409 BSTR user, pass;
2410 HRESULT hres;
2412 TRACE("(%p)->(%p)\n", This, aUserPass);
2414 if(!ensure_uri(This))
2415 return NS_ERROR_UNEXPECTED;
2417 hres = IUri_GetUserName(This->uri, &user);
2418 if(FAILED(hres))
2419 return NS_ERROR_FAILURE;
2421 hres = IUri_GetPassword(This->uri, &pass);
2422 if(FAILED(hres)) {
2423 SysFreeString(user);
2424 return NS_ERROR_FAILURE;
2427 if(*user || *pass) {
2428 FIXME("Construct user:pass string\n");
2429 }else {
2430 nsACString_SetData(aUserPass, "");
2433 SysFreeString(user);
2434 SysFreeString(pass);
2435 return NS_OK;
2438 static nsresult NSAPI nsURI_SetUserPass(nsIFileURL *iface, const nsACString *aUserPass)
2440 nsWineURI *This = impl_from_nsIFileURL(iface);
2441 WCHAR *user = NULL, *pass = NULL, *buf = NULL;
2442 const char *user_pass;
2443 HRESULT hres;
2445 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
2447 if(!ensure_uri_builder(This))
2448 return NS_ERROR_UNEXPECTED;
2450 nsACString_GetData(aUserPass, &user_pass);
2451 if(*user_pass) {
2452 WCHAR *ptr;
2454 buf = heap_strdupUtoW(user_pass);
2455 if(!buf)
2456 return NS_ERROR_OUT_OF_MEMORY;
2458 ptr = wcschr(buf, ':');
2459 if(!ptr) {
2460 user = buf;
2461 }else if(ptr != buf) {
2462 *ptr++ = 0;
2463 user = buf;
2464 if(*ptr)
2465 pass = ptr;
2466 }else {
2467 pass = buf+1;
2471 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2472 if(SUCCEEDED(hres))
2473 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2475 heap_free(buf);
2476 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2479 static nsresult NSAPI nsURI_GetUsername(nsIFileURL *iface, nsACString *aUsername)
2481 nsWineURI *This = impl_from_nsIFileURL(iface);
2483 TRACE("(%p)->(%p)\n", This, aUsername);
2485 return get_uri_string(This, Uri_PROPERTY_USER_NAME, aUsername);
2488 static nsresult NSAPI nsURI_SetUsername(nsIFileURL *iface, const nsACString *aUsername)
2490 nsWineURI *This = impl_from_nsIFileURL(iface);
2491 const char *usera;
2492 WCHAR *user;
2493 HRESULT hres;
2495 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
2497 if(!ensure_uri_builder(This))
2498 return NS_ERROR_UNEXPECTED;
2500 nsACString_GetData(aUsername, &usera);
2501 user = heap_strdupUtoW(usera);
2502 if(!user)
2503 return NS_ERROR_OUT_OF_MEMORY;
2505 hres = IUriBuilder_SetUserName(This->uri_builder, user);
2506 heap_free(user);
2507 if(FAILED(hres))
2508 return NS_ERROR_UNEXPECTED;
2510 return NS_OK;
2513 static nsresult NSAPI nsURI_GetPassword(nsIFileURL *iface, nsACString *aPassword)
2515 nsWineURI *This = impl_from_nsIFileURL(iface);
2517 TRACE("(%p)->(%p)\n", This, aPassword);
2519 return get_uri_string(This, Uri_PROPERTY_PASSWORD, aPassword);
2522 static nsresult NSAPI nsURI_SetPassword(nsIFileURL *iface, const nsACString *aPassword)
2524 nsWineURI *This = impl_from_nsIFileURL(iface);
2525 const char *passa;
2526 WCHAR *pass;
2527 HRESULT hres;
2529 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
2531 if(!ensure_uri_builder(This))
2532 return NS_ERROR_UNEXPECTED;
2534 nsACString_GetData(aPassword, &passa);
2535 pass = heap_strdupUtoW(passa);
2536 if(!pass)
2537 return NS_ERROR_OUT_OF_MEMORY;
2539 hres = IUriBuilder_SetPassword(This->uri_builder, pass);
2540 heap_free(pass);
2541 if(FAILED(hres))
2542 return NS_ERROR_UNEXPECTED;
2544 return NS_OK;
2547 static nsresult NSAPI nsURI_GetHostPort(nsIFileURL *iface, nsACString *aHostPort)
2549 nsWineURI *This = impl_from_nsIFileURL(iface);
2550 const WCHAR *ptr;
2551 char *vala;
2552 BSTR val;
2553 HRESULT hres;
2555 TRACE("(%p)->(%p)\n", This, aHostPort);
2557 if(!ensure_uri(This))
2558 return NS_ERROR_UNEXPECTED;
2560 hres = IUri_GetAuthority(This->uri, &val);
2561 if(FAILED(hres)) {
2562 WARN("GetAuthority failed: %08x\n", hres);
2563 return NS_ERROR_UNEXPECTED;
2566 ptr = wcschr(val, '@');
2567 if(!ptr)
2568 ptr = val;
2570 vala = heap_strdupWtoU(ptr);
2571 SysFreeString(val);
2572 if(!vala)
2573 return NS_ERROR_OUT_OF_MEMORY;
2575 TRACE("ret %s\n", debugstr_a(vala));
2576 nsACString_SetData(aHostPort, vala);
2577 heap_free(vala);
2578 return NS_OK;
2581 static nsresult NSAPI nsURI_SetHostPort(nsIFileURL *iface, const nsACString *aHostPort)
2583 nsWineURI *This = impl_from_nsIFileURL(iface);
2585 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
2587 /* Not implemented by Gecko */
2588 return NS_ERROR_NOT_IMPLEMENTED;
2591 static nsresult NSAPI nsURI_GetHost(nsIFileURL *iface, nsACString *aHost)
2593 nsWineURI *This = impl_from_nsIFileURL(iface);
2595 TRACE("(%p)->(%p)\n", This, aHost);
2597 return get_uri_string(This, Uri_PROPERTY_HOST, aHost);
2600 static nsresult NSAPI nsURI_SetHost(nsIFileURL *iface, const nsACString *aHost)
2602 nsWineURI *This = impl_from_nsIFileURL(iface);
2603 const char *hosta;
2604 WCHAR *host;
2605 HRESULT hres;
2607 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
2609 if(!ensure_uri_builder(This))
2610 return NS_ERROR_UNEXPECTED;
2612 nsACString_GetData(aHost, &hosta);
2613 host = heap_strdupUtoW(hosta);
2614 if(!host)
2615 return NS_ERROR_OUT_OF_MEMORY;
2617 hres = IUriBuilder_SetHost(This->uri_builder, host);
2618 heap_free(host);
2619 if(FAILED(hres))
2620 return NS_ERROR_UNEXPECTED;
2622 return NS_OK;
2625 static nsresult NSAPI nsURI_GetPort(nsIFileURL *iface, LONG *aPort)
2627 nsWineURI *This = impl_from_nsIFileURL(iface);
2628 DWORD port;
2629 HRESULT hres;
2631 TRACE("(%p)->(%p)\n", This, aPort);
2633 if(!ensure_uri(This))
2634 return NS_ERROR_UNEXPECTED;
2636 hres = IUri_GetPort(This->uri, &port);
2637 if(FAILED(hres)) {
2638 WARN("GetPort failed: %08x\n", hres);
2639 return NS_ERROR_UNEXPECTED;
2642 *aPort = port ? port : -1;
2643 return NS_OK;
2646 static nsresult NSAPI nsURI_SetPort(nsIFileURL *iface, LONG aPort)
2648 nsWineURI *This = impl_from_nsIFileURL(iface);
2649 HRESULT hres;
2651 TRACE("(%p)->(%d)\n", This, aPort);
2653 if(!ensure_uri_builder(This))
2654 return NS_ERROR_UNEXPECTED;
2656 hres = IUriBuilder_SetPort(This->uri_builder, aPort != -1, aPort);
2657 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_FAILURE;
2660 static nsresult NSAPI nsURI_GetPath(nsIFileURL *iface, nsACString *aPath)
2662 nsWineURI *This = impl_from_nsIFileURL(iface);
2664 TRACE("(%p)->(%p)\n", This, aPath);
2666 return get_uri_string(This, Uri_PROPERTY_PATH, aPath);
2669 static nsresult NSAPI nsURI_SetPath(nsIFileURL *iface, const nsACString *aPath)
2671 nsWineURI *This = impl_from_nsIFileURL(iface);
2672 const char *patha;
2673 WCHAR *path;
2674 HRESULT hres;
2676 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
2678 if(!ensure_uri_builder(This))
2679 return NS_ERROR_UNEXPECTED;
2681 nsACString_GetData(aPath, &patha);
2682 path = heap_strdupUtoW(patha);
2683 if(!path)
2684 return NS_ERROR_OUT_OF_MEMORY;
2686 hres = IUriBuilder_SetPath(This->uri_builder, path);
2687 heap_free(path);
2688 if(FAILED(hres))
2689 return NS_ERROR_UNEXPECTED;
2691 return NS_OK;
2694 static nsresult NSAPI nsURI_Equals(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2696 nsWineURI *This = impl_from_nsIFileURL(iface);
2697 nsWineURI *other_obj;
2698 nsresult nsres;
2699 HRESULT hres;
2701 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2703 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2704 if(NS_FAILED(nsres)) {
2705 TRACE("Could not get nsWineURI interface\n");
2706 *_retval = FALSE;
2707 return NS_OK;
2710 if(ensure_uri(This) && ensure_uri(other_obj)) {
2711 BOOL b;
2713 hres = IUri_IsEqual(This->uri, other_obj->uri, &b);
2714 if(SUCCEEDED(hres)) {
2715 *_retval = b;
2716 nsres = NS_OK;
2717 }else {
2718 nsres = NS_ERROR_FAILURE;
2720 }else {
2721 nsres = NS_ERROR_UNEXPECTED;
2724 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2725 return nsres;
2728 static nsresult NSAPI nsURI_SchemeIs(nsIFileURL *iface, const char *scheme, cpp_bool *_retval)
2730 nsWineURI *This = impl_from_nsIFileURL(iface);
2731 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
2732 BSTR scheme_name;
2733 HRESULT hres;
2735 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
2737 if(!ensure_uri(This))
2738 return NS_ERROR_UNEXPECTED;
2740 hres = IUri_GetSchemeName(This->uri, &scheme_name);
2741 if(FAILED(hres))
2742 return NS_ERROR_UNEXPECTED;
2744 MultiByteToWideChar(CP_UTF8, 0, scheme, -1, buf, ARRAY_SIZE(buf));
2745 *_retval = !wcscmp(scheme_name, buf);
2746 SysFreeString(scheme_name);
2747 return NS_OK;
2750 static nsresult NSAPI nsURI_Clone(nsIFileURL *iface, nsIURI **_retval)
2752 nsWineURI *This = impl_from_nsIFileURL(iface);
2753 nsWineURI *wine_uri;
2754 nsresult nsres;
2756 TRACE("(%p)->(%p)\n", This, _retval);
2758 if(!ensure_uri(This))
2759 return NS_ERROR_UNEXPECTED;
2761 nsres = create_nsuri(This->uri, &wine_uri);
2762 if(NS_FAILED(nsres)) {
2763 WARN("create_nsuri failed: %08x\n", nsres);
2764 return nsres;
2767 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2768 return NS_OK;
2771 static nsresult NSAPI nsURI_Resolve(nsIFileURL *iface, const nsACString *aRelativePath,
2772 nsACString *_retval)
2774 nsWineURI *This = impl_from_nsIFileURL(iface);
2775 const char *patha;
2776 IUri *new_uri;
2777 WCHAR *path;
2778 char *reta;
2779 BSTR ret;
2780 HRESULT hres;
2782 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
2784 if(!ensure_uri(This))
2785 return NS_ERROR_UNEXPECTED;
2787 nsACString_GetData(aRelativePath, &patha);
2788 path = heap_strdupUtoW(patha);
2789 if(!path)
2790 return NS_ERROR_OUT_OF_MEMORY;
2792 hres = combine_url(This->uri, path, &new_uri);
2793 heap_free(path);
2794 if(FAILED(hres))
2795 return NS_ERROR_FAILURE;
2797 hres = IUri_GetDisplayUri(new_uri, &ret);
2798 IUri_Release(new_uri);
2799 if(FAILED(hres))
2800 return NS_ERROR_FAILURE;
2802 reta = heap_strdupWtoU(ret);
2803 SysFreeString(ret);
2804 if(!reta)
2805 return NS_ERROR_OUT_OF_MEMORY;
2807 TRACE("returning %s\n", debugstr_a(reta));
2808 nsACString_SetData(_retval, reta);
2809 heap_free(reta);
2810 return NS_OK;
2813 static nsresult NSAPI nsURI_GetAsciiSpec(nsIFileURL *iface, nsACString *aAsciiSpec)
2815 nsWineURI *This = impl_from_nsIFileURL(iface);
2817 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2819 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aAsciiSpec);
2822 static nsresult NSAPI nsURI_GetAsciiHostPort(nsIFileURL *iface, nsACString *aAsciiHostPort)
2824 nsWineURI *This = impl_from_nsIFileURL(iface);
2826 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHostPort);
2828 return nsIFileURL_GetHostPort(&This->nsIFileURL_iface, aAsciiHostPort);
2831 static nsresult NSAPI nsURI_GetAsciiHost(nsIFileURL *iface, nsACString *aAsciiHost)
2833 nsWineURI *This = impl_from_nsIFileURL(iface);
2835 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This, aAsciiHost);
2837 return get_uri_string(This, Uri_PROPERTY_HOST, aAsciiHost);
2840 static nsresult NSAPI nsURI_GetOriginCharset(nsIFileURL *iface, nsACString *aOriginCharset)
2842 nsWineURI *This = impl_from_nsIFileURL(iface);
2844 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2846 nsACString_SetData(aOriginCharset, NULL); /* assume utf-8, we store URI as utf-16 anyway */
2847 return NS_OK;
2850 static nsresult NSAPI nsURL_GetRef(nsIFileURL *iface, nsACString *aRef)
2852 nsWineURI *This = impl_from_nsIFileURL(iface);
2853 char *refa = NULL;
2854 BSTR ref;
2855 HRESULT hres;
2857 TRACE("(%p)->(%p)\n", This, aRef);
2859 if(!ensure_uri(This))
2860 return NS_ERROR_UNEXPECTED;
2862 hres = IUri_GetFragment(This->uri, &ref);
2863 if(FAILED(hres))
2864 return NS_ERROR_UNEXPECTED;
2866 refa = heap_strdupWtoU(ref);
2867 SysFreeString(ref);
2868 if(ref && !refa)
2869 return NS_ERROR_OUT_OF_MEMORY;
2871 nsACString_SetData(aRef, refa && *refa == '#' ? refa+1 : refa);
2872 heap_free(refa);
2873 return NS_OK;
2876 static nsresult NSAPI nsURL_SetRef(nsIFileURL *iface, const nsACString *aRef)
2878 nsWineURI *This = impl_from_nsIFileURL(iface);
2879 const char *refa;
2880 WCHAR *ref;
2881 HRESULT hres;
2883 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2885 if(!ensure_uri_builder(This))
2886 return NS_ERROR_UNEXPECTED;
2888 nsACString_GetData(aRef, &refa);
2889 ref = heap_strdupUtoW(refa);
2890 if(!ref)
2891 return NS_ERROR_OUT_OF_MEMORY;
2893 hres = IUriBuilder_SetFragment(This->uri_builder, ref);
2894 heap_free(ref);
2895 if(FAILED(hres))
2896 return NS_ERROR_UNEXPECTED;
2898 return NS_OK;
2901 static nsresult NSAPI nsURI_EqualsExceptRef(nsIFileURL *iface, nsIURI *other, cpp_bool *_retval)
2903 nsWineURI *This = impl_from_nsIFileURL(iface);
2904 nsWineURI *other_obj;
2905 nsresult nsres;
2907 TRACE("(%p)->(%p %p)\n", This, other, _retval);
2909 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&other_obj);
2910 if(NS_FAILED(nsres)) {
2911 TRACE("Could not get nsWineURI interface\n");
2912 *_retval = FALSE;
2913 return NS_OK;
2916 if(ensure_uri(This) && ensure_uri(other_obj)) {
2917 *_retval = compare_ignoring_frag(This->uri, other_obj->uri);
2918 nsres = NS_OK;
2919 }else {
2920 nsres = NS_ERROR_UNEXPECTED;
2923 nsIFileURL_Release(&other_obj->nsIFileURL_iface);
2924 return nsres;
2927 static nsresult NSAPI nsURI_CloneIgnoreRef(nsIFileURL *iface, nsIURI **_retval)
2929 nsWineURI *This = impl_from_nsIFileURL(iface);
2930 nsWineURI *wine_uri;
2931 IUri *uri;
2932 nsresult nsres;
2934 TRACE("(%p)->(%p)\n", This, _retval);
2936 if(!ensure_uri(This))
2937 return NS_ERROR_UNEXPECTED;
2939 uri = get_uri_nofrag(This->uri);
2940 if(!uri)
2941 return NS_ERROR_FAILURE;
2943 nsres = create_nsuri(uri, &wine_uri);
2944 IUri_Release(uri);
2945 if(NS_FAILED(nsres)) {
2946 WARN("create_nsuri failed: %08x\n", nsres);
2947 return nsres;
2950 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
2951 return NS_OK;
2954 static nsresult NSAPI nsURI_GetSpecIgnoringRef(nsIFileURL *iface, nsACString *aSpecIgnoringRef)
2956 nsWineURI *This = impl_from_nsIFileURL(iface);
2958 FIXME("(%p)->(%p)\n", This, aSpecIgnoringRef);
2960 return nsIFileURL_GetSpec(&This->nsIFileURL_iface, aSpecIgnoringRef);
2963 static nsresult NSAPI nsURI_GetHasRef(nsIFileURL *iface, cpp_bool *aHasRef)
2965 nsWineURI *This = impl_from_nsIFileURL(iface);
2966 BOOL b;
2967 HRESULT hres;
2969 TRACE("(%p)->(%p)\n", This, aHasRef);
2971 if(!ensure_uri(This))
2972 return NS_ERROR_UNEXPECTED;
2974 hres = IUri_HasProperty(This->uri, Uri_PROPERTY_FRAGMENT, &b);
2975 if(FAILED(hres))
2976 return NS_ERROR_FAILURE;
2978 *aHasRef = b;
2979 return NS_OK;
2982 static nsresult NSAPI nsURL_GetFilePath(nsIFileURL *iface, nsACString *aFilePath)
2984 nsWineURI *This = impl_from_nsIFileURL(iface);
2986 TRACE("(%p)->(%p)\n", This, aFilePath);
2988 return nsIFileURL_GetPath(&This->nsIFileURL_iface, aFilePath);
2991 static nsresult NSAPI nsURL_SetFilePath(nsIFileURL *iface, const nsACString *aFilePath)
2993 nsWineURI *This = impl_from_nsIFileURL(iface);
2995 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2997 if(!This->is_mutable)
2998 return NS_ERROR_UNEXPECTED;
3000 return nsIFileURL_SetPath(&This->nsIFileURL_iface, aFilePath);
3003 static nsresult NSAPI nsURL_GetQuery(nsIFileURL *iface, nsACString *aQuery)
3005 nsWineURI *This = impl_from_nsIFileURL(iface);
3006 WCHAR *ptr;
3007 BSTR query;
3008 nsresult nsres;
3009 HRESULT hres;
3011 TRACE("(%p)->(%p)\n", This, aQuery);
3013 if(!ensure_uri(This))
3014 return NS_ERROR_UNEXPECTED;
3016 hres = IUri_GetQuery(This->uri, &query);
3017 if(FAILED(hres))
3018 return NS_ERROR_FAILURE;
3020 ptr = query;
3021 if(ptr && *ptr == '?')
3022 ptr++;
3024 nsres = return_wstr_nsacstr(aQuery, ptr, -1);
3025 SysFreeString(query);
3026 return nsres;
3029 static nsresult NSAPI nsURL_SetQuery(nsIFileURL *iface, const nsACString *aQuery)
3031 nsWineURI *This = impl_from_nsIFileURL(iface);
3032 const char *querya;
3033 WCHAR *query;
3034 HRESULT hres;
3036 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
3038 if(!ensure_uri_builder(This))
3039 return NS_ERROR_UNEXPECTED;
3041 nsACString_GetData(aQuery, &querya);
3042 query = heap_strdupUtoW(querya);
3043 if(!query)
3044 return NS_ERROR_OUT_OF_MEMORY;
3046 hres = IUriBuilder_SetQuery(This->uri_builder, query);
3047 heap_free(query);
3048 if(FAILED(hres))
3049 return NS_ERROR_UNEXPECTED;
3051 return NS_OK;
3054 static nsresult get_uri_path(nsWineURI *This, BSTR *path, const WCHAR **file, const WCHAR **ext)
3056 const WCHAR *ptr;
3057 HRESULT hres;
3059 if(!ensure_uri(This))
3060 return NS_ERROR_UNEXPECTED;
3062 hres = IUri_GetPath(This->uri, path);
3063 if(FAILED(hres))
3064 return NS_ERROR_FAILURE;
3066 for(ptr = *path + SysStringLen(*path)-1; ptr > *path && *ptr != '/' && *ptr != '\\'; ptr--);
3067 if(*ptr == '/' || *ptr == '\\')
3068 ptr++;
3069 *file = ptr;
3071 if(ext) {
3072 ptr = wcsrchr(ptr, '.');
3073 if(!ptr)
3074 ptr = *path + SysStringLen(*path);
3075 *ext = ptr;
3078 return NS_OK;
3081 static nsresult NSAPI nsURL_GetDirectory(nsIFileURL *iface, nsACString *aDirectory)
3083 nsWineURI *This = impl_from_nsIFileURL(iface);
3084 const WCHAR *file;
3085 BSTR path;
3086 nsresult nsres;
3088 TRACE("(%p)->(%p)\n", This, aDirectory);
3090 nsres = get_uri_path(This, &path, &file, NULL);
3091 if(NS_FAILED(nsres))
3092 return nsres;
3094 nsres = return_wstr_nsacstr(aDirectory, path, file-path);
3095 SysFreeString(path);
3096 return nsres;
3099 static nsresult NSAPI nsURL_SetDirectory(nsIFileURL *iface, const nsACString *aDirectory)
3101 nsWineURI *This = impl_from_nsIFileURL(iface);
3103 WARN("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
3105 /* Not implemented by Gecko */
3106 return NS_ERROR_NOT_IMPLEMENTED;
3109 static nsresult NSAPI nsURL_GetFileName(nsIFileURL *iface, nsACString *aFileName)
3111 nsWineURI *This = impl_from_nsIFileURL(iface);
3112 const WCHAR *file;
3113 BSTR path;
3114 nsresult nsres;
3116 TRACE("(%p)->(%p)\n", This, aFileName);
3118 nsres = get_uri_path(This, &path, &file, NULL);
3119 if(NS_FAILED(nsres))
3120 return nsres;
3122 nsres = return_wstr_nsacstr(aFileName, file, -1);
3123 SysFreeString(path);
3124 return nsres;
3127 static nsresult NSAPI nsURL_SetFileName(nsIFileURL *iface, const nsACString *aFileName)
3129 nsWineURI *This = impl_from_nsIFileURL(iface);
3130 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
3131 return NS_ERROR_NOT_IMPLEMENTED;
3134 static nsresult NSAPI nsURL_GetFileBaseName(nsIFileURL *iface, nsACString *aFileBaseName)
3136 nsWineURI *This = impl_from_nsIFileURL(iface);
3137 const WCHAR *file, *ext;
3138 BSTR path;
3139 nsresult nsres;
3141 TRACE("(%p)->(%p)\n", This, aFileBaseName);
3143 nsres = get_uri_path(This, &path, &file, &ext);
3144 if(NS_FAILED(nsres))
3145 return nsres;
3147 nsres = return_wstr_nsacstr(aFileBaseName, file, ext-file);
3148 SysFreeString(path);
3149 return nsres;
3152 static nsresult NSAPI nsURL_SetFileBaseName(nsIFileURL *iface, const nsACString *aFileBaseName)
3154 nsWineURI *This = impl_from_nsIFileURL(iface);
3155 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
3156 return NS_ERROR_NOT_IMPLEMENTED;
3159 static nsresult NSAPI nsURL_GetFileExtension(nsIFileURL *iface, nsACString *aFileExtension)
3161 nsWineURI *This = impl_from_nsIFileURL(iface);
3163 TRACE("(%p)->(%p)\n", This, aFileExtension);
3165 return get_uri_string(This, Uri_PROPERTY_EXTENSION, aFileExtension);
3168 static nsresult NSAPI nsURL_SetFileExtension(nsIFileURL *iface, const nsACString *aFileExtension)
3170 nsWineURI *This = impl_from_nsIFileURL(iface);
3171 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
3172 return NS_ERROR_NOT_IMPLEMENTED;
3175 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
3177 nsWineURI *This = impl_from_nsIFileURL(iface);
3178 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
3179 return NS_ERROR_NOT_IMPLEMENTED;
3182 static nsresult NSAPI nsURL_GetRelativeSpec(nsIFileURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
3184 nsWineURI *This = impl_from_nsIFileURL(iface);
3185 FIXME("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
3186 return NS_ERROR_NOT_IMPLEMENTED;
3189 static nsresult NSAPI nsFileURL_GetFile(nsIFileURL *iface, nsIFile **aFile)
3191 nsWineURI *This = impl_from_nsIFileURL(iface);
3192 WCHAR path[MAX_PATH];
3193 DWORD size;
3194 HRESULT hres;
3196 TRACE("(%p)->(%p)\n", This, aFile);
3198 hres = CoInternetParseIUri(This->uri, PARSE_PATH_FROM_URL, 0, path, ARRAY_SIZE(path), &size, 0);
3199 if(FAILED(hres)) {
3200 WARN("CoInternetParseIUri failed: %08x\n", hres);
3201 return NS_ERROR_FAILURE;
3204 return create_nsfile(path, aFile);
3207 static nsresult NSAPI nsFileURL_SetFile(nsIFileURL *iface, nsIFile *aFile)
3209 nsWineURI *This = impl_from_nsIFileURL(iface);
3210 FIXME("(%p)->(%p)\n", This, aFile);
3211 return NS_ERROR_NOT_IMPLEMENTED;
3214 static const nsIFileURLVtbl nsFileURLVtbl = {
3215 nsURI_QueryInterface,
3216 nsURI_AddRef,
3217 nsURI_Release,
3218 nsURI_GetSpec,
3219 nsURI_SetSpec,
3220 nsURI_GetPrePath,
3221 nsURI_GetScheme,
3222 nsURI_SetScheme,
3223 nsURI_GetUserPass,
3224 nsURI_SetUserPass,
3225 nsURI_GetUsername,
3226 nsURI_SetUsername,
3227 nsURI_GetPassword,
3228 nsURI_SetPassword,
3229 nsURI_GetHostPort,
3230 nsURI_SetHostPort,
3231 nsURI_GetHost,
3232 nsURI_SetHost,
3233 nsURI_GetPort,
3234 nsURI_SetPort,
3235 nsURI_GetPath,
3236 nsURI_SetPath,
3237 nsURI_Equals,
3238 nsURI_SchemeIs,
3239 nsURI_Clone,
3240 nsURI_Resolve,
3241 nsURI_GetAsciiSpec,
3242 nsURI_GetAsciiHostPort,
3243 nsURI_GetAsciiHost,
3244 nsURI_GetOriginCharset,
3245 nsURL_GetRef,
3246 nsURL_SetRef,
3247 nsURI_EqualsExceptRef,
3248 nsURI_CloneIgnoreRef,
3249 nsURI_GetSpecIgnoringRef,
3250 nsURI_GetHasRef,
3251 nsURL_GetFilePath,
3252 nsURL_SetFilePath,
3253 nsURL_GetQuery,
3254 nsURL_SetQuery,
3255 nsURL_GetDirectory,
3256 nsURL_SetDirectory,
3257 nsURL_GetFileName,
3258 nsURL_SetFileName,
3259 nsURL_GetFileBaseName,
3260 nsURL_SetFileBaseName,
3261 nsURL_GetFileExtension,
3262 nsURL_SetFileExtension,
3263 nsURL_GetCommonBaseSpec,
3264 nsURL_GetRelativeSpec,
3265 nsFileURL_GetFile,
3266 nsFileURL_SetFile
3269 static inline nsWineURI *impl_from_nsIStandardURL(nsIStandardURL *iface)
3271 return CONTAINING_RECORD(iface, nsWineURI, nsIStandardURL_iface);
3274 static nsresult NSAPI nsStandardURL_QueryInterface(nsIStandardURL *iface, nsIIDRef riid,
3275 void **result)
3277 nsWineURI *This = impl_from_nsIStandardURL(iface);
3278 return nsIFileURL_QueryInterface(&This->nsIFileURL_iface, riid, result);
3281 static nsrefcnt NSAPI nsStandardURL_AddRef(nsIStandardURL *iface)
3283 nsWineURI *This = impl_from_nsIStandardURL(iface);
3284 return nsIFileURL_AddRef(&This->nsIFileURL_iface);
3287 static nsrefcnt NSAPI nsStandardURL_Release(nsIStandardURL *iface)
3289 nsWineURI *This = impl_from_nsIStandardURL(iface);
3290 return nsIFileURL_Release(&This->nsIFileURL_iface);
3293 static nsresult NSAPI nsStandardURL_GetMutable(nsIStandardURL *iface, cpp_bool *aMutable)
3295 nsWineURI *This = impl_from_nsIStandardURL(iface);
3297 TRACE("(%p)->(%p)\n", This, aMutable);
3299 *aMutable = This->is_mutable;
3300 return NS_OK;
3303 static nsresult NSAPI nsStandardURL_SetMutable(nsIStandardURL *iface, cpp_bool aMutable)
3305 nsWineURI *This = impl_from_nsIStandardURL(iface);
3307 TRACE("(%p)->(%x)\n", This, aMutable);
3309 This->is_mutable = aMutable;
3310 return NS_OK;
3313 static nsresult NSAPI nsStandardURL_Init(nsIStandardURL *iface, UINT32 aUrlType, LONG aDefaultPort,
3314 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI)
3316 nsWineURI *This = impl_from_nsIStandardURL(iface);
3317 FIXME("(%p)->(%d %d %s %s %p)\n", This, aUrlType, aDefaultPort, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI);
3318 return NS_ERROR_NOT_IMPLEMENTED;
3321 static nsresult NSAPI nsStandardURL_SetDefaultPort(nsIStandardURL *iface, LONG aNewDefaultPort)
3323 nsWineURI *This = impl_from_nsIStandardURL(iface);
3324 FIXME("(%p)->(%d)\n", This, aNewDefaultPort);
3325 return NS_ERROR_NOT_IMPLEMENTED;
3328 static const nsIStandardURLVtbl nsStandardURLVtbl = {
3329 nsStandardURL_QueryInterface,
3330 nsStandardURL_AddRef,
3331 nsStandardURL_Release,
3332 nsStandardURL_GetMutable,
3333 nsStandardURL_SetMutable,
3334 nsStandardURL_Init,
3335 nsStandardURL_SetDefaultPort
3338 static nsresult create_nsuri(IUri *iuri, nsWineURI **_retval)
3340 nsWineURI *ret;
3341 HRESULT hres;
3343 ret = heap_alloc_zero(sizeof(nsWineURI));
3344 if(!ret)
3345 return NS_ERROR_OUT_OF_MEMORY;
3347 ret->nsIFileURL_iface.lpVtbl = &nsFileURLVtbl;
3348 ret->nsIStandardURL_iface.lpVtbl = &nsStandardURLVtbl;
3349 ret->ref = 1;
3350 ret->is_mutable = TRUE;
3352 IUri_AddRef(iuri);
3353 ret->uri = iuri;
3355 hres = IUri_GetScheme(iuri, &ret->scheme);
3356 if(FAILED(hres))
3357 ret->scheme = URL_SCHEME_UNKNOWN;
3359 TRACE("retval=%p\n", ret);
3360 *_retval = ret;
3361 return NS_OK;
3364 HRESULT create_doc_uri(IUri *iuri, nsWineURI **ret)
3366 nsresult nsres;
3367 nsres = create_nsuri(iuri, ret);
3368 return NS_SUCCEEDED(nsres) ? S_OK : E_OUTOFMEMORY;
3371 static nsresult create_nschannel(nsWineURI *uri, nsChannel **ret)
3373 nsChannel *channel;
3375 if(!ensure_uri(uri))
3376 return NS_ERROR_UNEXPECTED;
3378 channel = heap_alloc_zero(sizeof(nsChannel));
3379 if(!channel)
3380 return NS_ERROR_OUT_OF_MEMORY;
3382 channel->nsIHttpChannel_iface.lpVtbl = &nsChannelVtbl;
3383 channel->nsIUploadChannel_iface.lpVtbl = &nsUploadChannelVtbl;
3384 channel->nsIHttpChannelInternal_iface.lpVtbl = &nsHttpChannelInternalVtbl;
3385 channel->ref = 1;
3386 channel->request_method = METHOD_GET;
3387 list_init(&channel->response_headers);
3388 list_init(&channel->request_headers);
3390 nsIFileURL_AddRef(&uri->nsIFileURL_iface);
3391 channel->uri = uri;
3393 *ret = channel;
3394 return NS_OK;
3397 HRESULT create_redirect_nschannel(const WCHAR *url, nsChannel *orig_channel, nsChannel **ret)
3399 nsChannel *channel;
3400 nsWineURI *uri;
3401 IUri *iuri;
3402 nsresult nsres;
3403 HRESULT hres;
3405 hres = create_uri(url, 0, &iuri);
3406 if(FAILED(hres))
3407 return hres;
3409 nsres = create_nsuri(iuri, &uri);
3410 IUri_Release(iuri);
3411 if(NS_FAILED(nsres))
3412 return E_FAIL;
3414 nsres = create_nschannel(uri, &channel);
3415 nsIFileURL_Release(&uri->nsIFileURL_iface);
3416 if(NS_FAILED(nsres))
3417 return E_FAIL;
3419 if(orig_channel->load_group) {
3420 nsILoadGroup_AddRef(orig_channel->load_group);
3421 channel->load_group = orig_channel->load_group;
3424 if(orig_channel->notif_callback) {
3425 nsIInterfaceRequestor_AddRef(orig_channel->notif_callback);
3426 channel->notif_callback = orig_channel->notif_callback;
3429 channel->load_flags = orig_channel->load_flags | LOAD_REPLACE;
3431 if(orig_channel->request_method == METHOD_POST)
3432 FIXME("unsupported POST method\n");
3434 if(orig_channel->original_uri) {
3435 nsIURI_AddRef(orig_channel->original_uri);
3436 channel->original_uri = orig_channel->original_uri;
3439 if(orig_channel->referrer) {
3440 nsIURI_AddRef(orig_channel->referrer);
3441 channel->referrer = orig_channel->referrer;
3444 *ret = channel;
3445 return S_OK;
3448 typedef struct {
3449 nsIProtocolHandler nsIProtocolHandler_iface;
3451 LONG ref;
3453 nsIProtocolHandler *nshandler;
3454 } nsProtocolHandler;
3456 static inline nsProtocolHandler *impl_from_nsIProtocolHandler(nsIProtocolHandler *iface)
3458 return CONTAINING_RECORD(iface, nsProtocolHandler, nsIProtocolHandler_iface);
3461 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
3462 void **result)
3464 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3466 *result = NULL;
3468 if(IsEqualGUID(&IID_nsISupports, riid)) {
3469 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
3470 *result = &This->nsIProtocolHandler_iface;
3471 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
3472 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
3473 *result = &This->nsIProtocolHandler_iface;
3474 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
3475 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
3476 return NS_NOINTERFACE;
3479 if(*result) {
3480 nsISupports_AddRef((nsISupports*)*result);
3481 return NS_OK;
3484 WARN("(%s %p)\n", debugstr_guid(riid), result);
3485 return NS_NOINTERFACE;
3488 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
3490 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3491 LONG ref = InterlockedIncrement(&This->ref);
3493 TRACE("(%p) ref=%d\n", This, ref);
3495 return ref;
3498 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
3500 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3501 LONG ref = InterlockedDecrement(&This->ref);
3503 TRACE("(%p) ref=%d\n", This, ref);
3505 if(!ref) {
3506 if(This->nshandler)
3507 nsIProtocolHandler_Release(This->nshandler);
3508 heap_free(This);
3511 return ref;
3514 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
3516 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3518 TRACE("(%p)->(%p)\n", This, aScheme);
3520 if(This->nshandler)
3521 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
3522 return NS_ERROR_NOT_IMPLEMENTED;
3525 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
3526 LONG *aDefaultPort)
3528 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3530 TRACE("(%p)->(%p)\n", This, aDefaultPort);
3532 if(This->nshandler)
3533 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
3534 return NS_ERROR_NOT_IMPLEMENTED;
3537 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
3538 UINT32 *aProtocolFlags)
3540 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3542 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
3544 if(This->nshandler)
3545 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
3546 return NS_ERROR_NOT_IMPLEMENTED;
3549 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
3550 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3552 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3554 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3555 aBaseURI, _retval);
3557 if(This->nshandler)
3558 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
3559 return NS_ERROR_NOT_IMPLEMENTED;
3562 static nsresult NSAPI nsProtocolHandler_NewChannel2(nsIProtocolHandler *iface,
3563 nsIURI *aURI, nsILoadInfo *aLoadInfo, nsIChannel **_retval)
3565 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3567 TRACE("(%p)->(%p %p %p)\n", This, aURI, aLoadInfo, _retval);
3569 if(This->nshandler)
3570 return nsIProtocolHandler_NewChannel2(This->nshandler, aURI, aLoadInfo, _retval);
3571 return NS_ERROR_NOT_IMPLEMENTED;
3574 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
3575 nsIURI *aURI, nsIChannel **_retval)
3577 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3579 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
3581 if(This->nshandler)
3582 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
3583 return NS_ERROR_NOT_IMPLEMENTED;
3586 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
3587 LONG port, const char *scheme, cpp_bool *_retval)
3589 nsProtocolHandler *This = impl_from_nsIProtocolHandler(iface);
3591 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
3593 if(This->nshandler)
3594 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
3595 return NS_ERROR_NOT_IMPLEMENTED;
3598 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
3599 nsProtocolHandler_QueryInterface,
3600 nsProtocolHandler_AddRef,
3601 nsProtocolHandler_Release,
3602 nsProtocolHandler_GetScheme,
3603 nsProtocolHandler_GetDefaultPort,
3604 nsProtocolHandler_GetProtocolFlags,
3605 nsProtocolHandler_NewURI,
3606 nsProtocolHandler_NewChannel2,
3607 nsProtocolHandler_NewChannel,
3608 nsProtocolHandler_AllowPort
3611 static nsresult NSAPI nsIOServiceHook_QueryInterface(nsIIOServiceHook *iface, nsIIDRef riid,
3612 void **result)
3614 if(IsEqualGUID(&IID_nsISupports, riid)) {
3615 TRACE("(IID_nsISupports %p)\n", result);
3616 *result = iface;
3617 }else if(IsEqualGUID(&IID_nsIIOServiceHook, riid)) {
3618 TRACE("(IID_nsIIOServiceHook %p)\n", result);
3619 *result = iface;
3620 }else {
3621 ERR("(%s %p)\n", debugstr_guid(riid), result);
3622 *result = NULL;
3623 return NS_NOINTERFACE;
3626 nsISupports_AddRef((nsISupports*)*result);
3627 return NS_OK;
3630 static nsrefcnt NSAPI nsIOServiceHook_AddRef(nsIIOServiceHook *iface)
3632 return 2;
3635 static nsrefcnt NSAPI nsIOServiceHook_Release(nsIIOServiceHook *iface)
3637 return 1;
3640 static nsresult NSAPI nsIOServiceHook_NewChannel(nsIIOServiceHook *iface, nsIURI *aURI,
3641 nsILoadInfo *aLoadInfo, nsIChannel **_retval)
3643 nsWineURI *wine_uri;
3644 nsChannel *ret;
3645 nsresult nsres;
3647 TRACE("(%p %p %p)\n", aURI, aLoadInfo, _retval);
3649 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
3650 if(NS_FAILED(nsres)) {
3651 TRACE("Could not get nsWineURI: %08x\n", nsres);
3652 return NS_SUCCESS_DEFAULT_ACTION;
3655 nsres = create_nschannel(wine_uri, &ret);
3656 nsIFileURL_Release(&wine_uri->nsIFileURL_iface);
3657 if(NS_FAILED(nsres))
3658 return nsres;
3660 nsIURI_AddRef(aURI);
3661 ret->original_uri = aURI;
3663 if(aLoadInfo)
3664 nsIHttpChannel_SetLoadInfo(&ret->nsIHttpChannel_iface, aLoadInfo);
3666 *_retval = (nsIChannel*)&ret->nsIHttpChannel_iface;
3667 return NS_OK;
3670 static nsresult NSAPI nsIOServiceHook_GetProtocolHandler(nsIIOServiceHook *iface, nsIProtocolHandler *aHandler,
3671 nsIProtocolHandler **_retval)
3673 nsIExternalProtocolHandler *nsexthandler;
3674 nsProtocolHandler *ret;
3675 nsresult nsres;
3677 TRACE("(%p %p)\n", aHandler, _retval);
3679 nsres = nsIProtocolHandler_QueryInterface(aHandler, &IID_nsIExternalProtocolHandler, (void**)&nsexthandler);
3680 if(NS_FAILED(nsres)) {
3681 nsIProtocolHandler_AddRef(aHandler);
3682 *_retval = aHandler;
3683 return NS_OK;
3686 nsIExternalProtocolHandler_Release(nsexthandler);
3688 ret = heap_alloc(sizeof(nsProtocolHandler));
3689 if(!ret)
3690 return NS_ERROR_OUT_OF_MEMORY;
3692 ret->nsIProtocolHandler_iface.lpVtbl = &nsProtocolHandlerVtbl;
3693 ret->ref = 1;
3694 nsIProtocolHandler_AddRef(aHandler);
3695 ret->nshandler = aHandler;
3698 *_retval = &ret->nsIProtocolHandler_iface;
3699 TRACE("return %p\n", *_retval);
3700 return NS_OK;
3703 static BOOL is_gecko_special_uri(const char *spec)
3705 static const char *special_schemes[] = {"chrome:", "data:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3706 unsigned int i;
3708 for(i=0; i < ARRAY_SIZE(special_schemes); i++) {
3709 if(!_strnicmp(spec, special_schemes[i], strlen(special_schemes[i])))
3710 return TRUE;
3713 if(!_strnicmp(spec, "file:", 5)) {
3714 const char *ptr = spec+5;
3715 while(*ptr == '/')
3716 ptr++;
3717 return is_gecko_path(ptr);
3720 return FALSE;
3723 static nsresult NSAPI nsIOServiceHook_NewURI(nsIIOServiceHook *iface, const nsACString *aSpec,
3724 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
3726 nsWineURI *wine_uri, *base_wine_uri = NULL;
3727 WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
3728 const char *spec = NULL;
3729 UINT cp = CP_UTF8;
3730 IUri *urlmon_uri;
3731 nsresult nsres;
3732 HRESULT hres;
3734 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
3735 aBaseURI, _retval);
3737 nsACString_GetData(aSpec, &spec);
3738 if(is_gecko_special_uri(spec))
3739 return NS_SUCCESS_DEFAULT_ACTION;
3741 if(!strncmp(spec, "wine:", 5))
3742 spec += 5;
3744 if(aBaseURI) {
3745 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
3746 if(NS_SUCCEEDED(nsres)) {
3747 if(!ensure_uri(base_wine_uri))
3748 return NS_ERROR_UNEXPECTED;
3749 }else {
3750 WARN("Could not get base nsWineURI: %08x\n", nsres);
3754 if(aOriginCharset && *aOriginCharset && _strnicmp(aOriginCharset, "utf", 3)) {
3755 BSTR charset;
3756 int len;
3758 len = MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, NULL, 0);
3759 charset = SysAllocStringLen(NULL, len-1);
3760 if(!charset)
3761 return NS_ERROR_OUT_OF_MEMORY;
3762 MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, charset, len);
3764 cp = cp_from_charset_string(charset);
3766 SysFreeString(charset);
3769 MultiByteToWideChar(cp, 0, spec, -1, new_spec, ARRAY_SIZE(new_spec));
3771 if(base_wine_uri) {
3772 hres = combine_url(base_wine_uri->uri, new_spec, &urlmon_uri);
3773 }else {
3774 hres = create_uri(new_spec, 0, &urlmon_uri);
3775 if(FAILED(hres))
3776 WARN("create_uri failed: %08x\n", hres);
3779 if(FAILED(hres))
3780 return NS_SUCCESS_DEFAULT_ACTION;
3782 nsres = create_nsuri(urlmon_uri, &wine_uri);
3783 IUri_Release(urlmon_uri);
3784 if(base_wine_uri)
3785 nsIFileURL_Release(&base_wine_uri->nsIFileURL_iface);
3786 if(NS_FAILED(nsres))
3787 return nsres;
3789 *_retval = (nsIURI*)&wine_uri->nsIFileURL_iface;
3790 return nsres;
3793 static const char *debugstr_protocol_flags(UINT32 flags)
3795 switch(flags) {
3796 #define X(f) case f: return #f
3797 X(URI_STD);
3798 X(URI_NORELATIVE);
3799 X(URI_NOAUTH);
3800 X(ALLOWS_PROXY);
3801 X(ALLOWS_PROXY_HTTP);
3802 X(URI_INHERITS_SECURITY_CONTEXT);
3803 X(URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT);
3804 X(URI_LOADABLE_BY_ANYONE);
3805 X(URI_DANGEROUS_TO_LOAD);
3806 X(URI_IS_UI_RESOURCE);
3807 X(URI_IS_LOCAL_FILE);
3808 X(URI_LOADABLE_BY_SUBSUMERS);
3809 X(URI_DOES_NOT_RETURN_DATA);
3810 X(URI_IS_LOCAL_RESOURCE);
3811 X(URI_OPENING_EXECUTES_SCRIPT);
3812 X(URI_NON_PERSISTABLE);
3813 X(URI_FORBIDS_COOKIE_ACCESS);
3814 X(URI_CROSS_ORIGIN_NEEDS_WEBAPPS_PERM);
3815 X(URI_SYNC_LOAD_IS_OK);
3816 X(URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT);
3817 X(URI_FETCHABLE_BY_ANYONE);
3818 #undef X
3819 default:
3820 return wine_dbg_sprintf("%08x", flags);
3824 static nsresult NSAPI nsIOServiceHook_ProtocolHasFlags(nsIIOServiceHook *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3826 TRACE("(%p %s %p)\n", aURI, debugstr_protocol_flags(aFlags), _retval);
3827 return NS_SUCCESS_DEFAULT_ACTION;
3830 static nsresult NSAPI nsIOServiceHook_URIChainHasFlags(nsIIOServiceHook *iface, nsIURI *aURI, UINT32 aFlags, cpp_bool *_retval)
3832 TRACE("(%p %s %p)\n", aURI, debugstr_protocol_flags(aFlags), _retval);
3834 if(aFlags == URI_DOES_NOT_RETURN_DATA) {
3835 *_retval = FALSE;
3836 return S_OK;
3839 return NS_SUCCESS_DEFAULT_ACTION;
3842 static const nsIIOServiceHookVtbl nsIOServiceHookVtbl = {
3843 nsIOServiceHook_QueryInterface,
3844 nsIOServiceHook_AddRef,
3845 nsIOServiceHook_Release,
3846 nsIOServiceHook_NewChannel,
3847 nsIOServiceHook_GetProtocolHandler,
3848 nsIOServiceHook_NewURI,
3849 nsIOServiceHook_ProtocolHasFlags,
3850 nsIOServiceHook_URIChainHasFlags
3853 static nsIIOServiceHook nsIOServiceHook = { &nsIOServiceHookVtbl };
3855 void init_nsio(nsIComponentManager *component_manager)
3857 nsIFactory *old_factory = NULL;
3858 nsresult nsres;
3860 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
3861 &IID_nsIFactory, (void**)&old_factory);
3862 if(NS_FAILED(nsres)) {
3863 ERR("Could not get factory: %08x\n", nsres);
3864 return;
3867 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3868 if(NS_FAILED(nsres)) {
3869 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3870 nsIFactory_Release(old_factory);
3871 return;
3874 nsres = nsIIOService_SetHook(nsio, &nsIOServiceHook);
3875 assert(nsres == NS_OK);
3878 void release_nsio(void)
3880 if(nsio) {
3881 nsIIOService_Release(nsio);
3882 nsio = NULL;