include: Update some d3d10shader.h definitions.
[wine.git] / dlls / mshtml / nsio.c
blob7fdd0e68636128b4bd6c16cfe45bc5550e1e4c94
1 /*
2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "wininet.h"
32 #include "shlwapi.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.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;
50 static nsINetUtil *net_util;
52 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
54 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
56 struct nsWineURI {
57 const nsIURLVtbl *lpIURLVtbl;
59 LONG ref;
61 nsIURI *uri;
62 nsIURL *nsurl;
63 NSContainer *container;
64 windowref_t *window_ref;
65 nsChannelBSC *channel_bsc;
66 LPWSTR wine_url;
67 BOOL is_doc_uri;
68 BOOL use_wine_url;
71 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
72 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
74 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
76 static const char *debugstr_nsacstr(const nsACString *nsstr)
78 const char *data;
80 nsACString_GetData(nsstr, &data);
81 return debugstr_a(data);
84 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
86 const WCHAR *ptr = nsuri;
88 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
90 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
91 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
93 if(*ptr || ret_empty) {
94 *ret = SysAllocString(ptr);
95 if(!*ret)
96 return E_OUTOFMEMORY;
97 }else {
98 *ret = NULL;
101 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
102 return S_OK;
105 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
107 IOleCommandTarget *cmdtrg = NULL;
108 HRESULT hres;
110 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
111 if(SUCCEEDED(hres)) {
112 VARIANT varUrl, varRes;
114 V_VT(&varUrl) = VT_BSTR;
115 V_BSTR(&varUrl) = SysAllocString(url);
116 V_VT(&varRes) = VT_BOOL;
118 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
120 IOleCommandTarget_Release(cmdtrg);
121 SysFreeString(V_BSTR(&varUrl));
123 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
124 TRACE("got VARIANT_FALSE, do not load\n");
125 return FALSE;
129 return TRUE;
132 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
134 HTMLDocumentObj *doc = container->doc;
135 DWORD hlnf = 0;
136 BOOL cancel;
137 HRESULT hres;
139 if(!doc) {
140 NSContainer *container_iter = container;
142 hlnf = HLNF_OPENINNEWWINDOW;
143 while(!container_iter->doc)
144 container_iter = container_iter->parent;
145 doc = container_iter->doc;
148 if(!doc->client)
149 return TRUE;
151 if(!hlnf && !exec_shldocvw_67(doc, channel->uri->wine_url))
152 return FALSE;
154 hres = hlink_frame_navigate(&doc->basedoc, channel->uri->wine_url, channel->post_data_stream, hlnf, &cancel);
155 return FAILED(hres) || cancel;
158 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
160 nsIWebNavigation *web_navigation;
161 nsIDocShell *doc_shell;
162 HTMLDocumentNode *doc;
163 nsresult nsres;
165 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
166 if(NS_FAILED(nsres)) {
167 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
168 return E_FAIL;
171 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
172 nsIWebNavigation_Release(web_navigation);
173 if(NS_FAILED(nsres)) {
174 ERR("Could not get nsIDocShell: %08x\n", nsres);
175 return E_FAIL;
178 uri->channel_bsc = channelbsc;
179 doc = window->doc;
180 doc->skip_mutation_notif = TRUE;
181 nsres = nsIDocShell_LoadURI(doc_shell, NSURI(uri), NULL, flags, FALSE);
182 if(doc == window->doc)
183 doc->skip_mutation_notif = FALSE;
184 uri->channel_bsc = NULL;
185 nsIDocShell_Release(doc_shell);
186 if(NS_FAILED(nsres)) {
187 WARN("LoadURI failed: %08x\n", nsres);
188 return E_FAIL;
191 return S_OK;
194 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
196 OLECHAR *new_url = NULL, *url;
197 BOOL ret = FALSE;
198 HRESULT hres;
200 if(!doc->hostui)
201 return FALSE;
203 url = heap_strdupW(uri->wine_url);
204 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
205 if(hres == S_OK && new_url) {
206 if(strcmpW(url, new_url)) {
207 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
208 ret = TRUE;
210 CoTaskMemFree(new_url);
213 heap_free(url);
214 return ret;
217 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
219 nsWineURI *wine_uri;
220 nsresult nsres;
222 *_retval = FALSE;
224 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
225 if(NS_FAILED(nsres)) {
226 WARN("Could not get nsWineURI: %08x\n", nsres);
227 return NS_ERROR_NOT_IMPLEMENTED;
230 if(!wine_uri->is_doc_uri) {
231 wine_uri->is_doc_uri = TRUE;
233 if(!wine_uri->container) {
234 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
235 wine_uri->container = nscontainer;
238 if(nscontainer->doc)
239 *_retval = translate_url(nscontainer->doc, wine_uri);
242 nsIURI_Release(NSURI(wine_uri));
243 return NS_OK;
246 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
248 static const WCHAR wszFtp[] = {'f','t','p',':'};
249 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
250 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
252 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
254 if(url) {
255 WCHAR *new_url;
257 new_url = heap_strdupW(url);
258 if(!new_url)
259 return E_OUTOFMEMORY;
260 heap_free(This->wine_url);
261 This->wine_url = new_url;
263 if(This->uri) {
264 /* FIXME: Always use wine url */
265 This->use_wine_url =
266 strncmpW(url, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
267 && strncmpW(url, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
268 && strncmpW(url, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
269 }else {
270 This->use_wine_url = TRUE;
272 }else {
273 heap_free(This->wine_url);
274 This->wine_url = NULL;
275 This->use_wine_url = FALSE;
278 return S_OK;
281 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
283 if(This->container) {
284 if(This->container == nscontainer)
285 return;
286 TRACE("Changing %p -> %p\n", This->container, nscontainer);
287 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
290 if(nscontainer)
291 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
292 This->container = nscontainer;
295 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
297 if(This->window_ref) {
298 if(This->window_ref->window == window)
299 return;
300 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
301 windowref_release(This->window_ref);
304 if(window) {
305 windowref_addref(window->window_ref);
306 This->window_ref = window->window_ref;
308 if(window->doc_obj)
309 set_uri_nscontainer(This, window->doc_obj->nscontainer);
310 }else {
311 This->window_ref = NULL;
315 static inline BOOL is_http_channel(nsChannel *This)
317 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTPS;
320 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
322 http_header_t *iter;
324 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
325 if(!strcmpiW(iter->header, name))
326 return iter;
329 return NULL;
332 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
333 nsACString *_retval)
335 const char *header_namea;
336 http_header_t *header;
337 WCHAR *header_name;
338 char *data;
340 nsACString_GetData(header_name_str, &header_namea);
341 header_name = heap_strdupAtoW(header_namea);
342 if(!header_name)
343 return NS_ERROR_UNEXPECTED;
345 header = find_http_header(headers, header_name, strlenW(header_name));
346 heap_free(header_name);
347 if(!header)
348 return NS_ERROR_NOT_AVAILABLE;
350 data = heap_strdupWtoA(header->data);
351 if(!data)
352 return NS_ERROR_UNEXPECTED;
354 nsACString_SetData(_retval, data);
355 heap_free(data);
356 return NS_OK;
359 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
360 const WCHAR *value, int value_len)
362 http_header_t *header;
364 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
366 header = find_http_header(headers, name, name_len);
367 if(header) {
368 WCHAR *new_data;
370 new_data = heap_strndupW(value, value_len);
371 if(!new_data)
372 return E_OUTOFMEMORY;
374 heap_free(header->data);
375 header->data = new_data;
376 }else {
377 header = heap_alloc(sizeof(http_header_t));
378 if(!header)
379 return E_OUTOFMEMORY;
381 header->header = heap_strndupW(name, name_len);
382 header->data = heap_strndupW(value, value_len);
383 if(!header->header || !header->data) {
384 heap_free(header->header);
385 heap_free(header->data);
386 heap_free(header);
387 return E_OUTOFMEMORY;
390 list_add_tail(headers, &header->entry);
393 return S_OK;
396 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
397 const nsACString *value_str)
399 const char *namea, *valuea;
400 WCHAR *name, *value;
401 HRESULT hres;
403 nsACString_GetData(name_str, &namea);
404 name = heap_strdupAtoW(namea);
405 if(!name)
406 return NS_ERROR_UNEXPECTED;
408 nsACString_GetData(value_str, &valuea);
409 value = heap_strdupAtoW(valuea);
410 if(!value) {
411 heap_free(name);
412 return NS_ERROR_UNEXPECTED;
415 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
417 heap_free(name);
418 heap_free(value);
419 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
422 static void free_http_headers(struct list *list)
424 http_header_t *iter, *iter_next;
426 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
427 list_remove(&iter->entry);
428 heap_free(iter->header);
429 heap_free(iter->data);
430 heap_free(iter);
434 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
436 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
438 nsChannel *This = NSCHANNEL_THIS(iface);
440 if(IsEqualGUID(&IID_nsISupports, riid)) {
441 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
442 *result = NSCHANNEL(This);
443 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
444 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
445 *result = NSCHANNEL(This);
446 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
447 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
448 *result = NSCHANNEL(This);
449 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
450 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
451 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
452 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
453 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
454 *result = NSUPCHANNEL(This);
455 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
456 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
457 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
458 }else {
459 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
460 *result = NULL;
463 if(*result) {
464 nsIChannel_AddRef(NSCHANNEL(This));
465 return NS_OK;
468 return NS_NOINTERFACE;
471 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
473 nsChannel *This = NSCHANNEL_THIS(iface);
474 nsrefcnt ref = InterlockedIncrement(&This->ref);
476 TRACE("(%p) ref=%d\n", This, ref);
478 return ref;
481 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
483 nsChannel *This = NSCHANNEL_THIS(iface);
484 LONG ref = InterlockedDecrement(&This->ref);
486 if(!ref) {
487 nsIURI_Release(NSURI(This->uri));
488 if(This->owner)
489 nsISupports_Release(This->owner);
490 if(This->post_data_stream)
491 nsIInputStream_Release(This->post_data_stream);
492 if(This->load_group)
493 nsILoadGroup_Release(This->load_group);
494 if(This->notif_callback)
495 nsIInterfaceRequestor_Release(This->notif_callback);
496 if(This->original_uri)
497 nsIURI_Release(This->original_uri);
498 if(This->referrer)
499 nsIURI_Release(This->referrer);
501 free_http_headers(&This->response_headers);
502 free_http_headers(&This->request_headers);
504 heap_free(This->content_type);
505 heap_free(This->charset);
506 heap_free(This);
509 return ref;
512 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
514 nsChannel *This = NSCHANNEL_THIS(iface);
516 TRACE("(%p)->(%p)\n", This, aName);
518 return nsIURI_GetSpec(NSURI(This->uri), aName);
521 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
523 nsChannel *This = NSCHANNEL_THIS(iface);
525 FIXME("(%p)->(%p)\n", This, _retval);
527 return NS_ERROR_NOT_IMPLEMENTED;
530 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
532 nsChannel *This = NSCHANNEL_THIS(iface);
534 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
536 return *aStatus = NS_OK;
539 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
541 nsChannel *This = NSCHANNEL_THIS(iface);
543 FIXME("(%p)->(%08x)\n", This, aStatus);
545 return NS_ERROR_NOT_IMPLEMENTED;
548 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
550 nsChannel *This = NSCHANNEL_THIS(iface);
552 FIXME("(%p)\n", This);
554 return NS_ERROR_NOT_IMPLEMENTED;
557 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
559 nsChannel *This = NSCHANNEL_THIS(iface);
561 FIXME("(%p)\n", This);
563 return NS_ERROR_NOT_IMPLEMENTED;
566 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
568 nsChannel *This = NSCHANNEL_THIS(iface);
570 TRACE("(%p)->(%p)\n", This, aLoadGroup);
572 if(This->load_group)
573 nsILoadGroup_AddRef(This->load_group);
575 *aLoadGroup = This->load_group;
576 return NS_OK;
579 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
581 nsChannel *This = NSCHANNEL_THIS(iface);
583 TRACE("(%p)->(%p)\n", This, aLoadGroup);
585 if(This->load_group)
586 nsILoadGroup_Release(This->load_group);
587 if(aLoadGroup)
588 nsILoadGroup_AddRef(aLoadGroup);
589 This->load_group = aLoadGroup;
591 return NS_OK;
594 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
596 nsChannel *This = NSCHANNEL_THIS(iface);
598 TRACE("(%p)->(%p)\n", This, aLoadFlags);
600 *aLoadFlags = This->load_flags;
601 return NS_OK;
604 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
606 nsChannel *This = NSCHANNEL_THIS(iface);
608 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
610 This->load_flags = aLoadFlags;
611 return NS_OK;
614 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
616 nsChannel *This = NSCHANNEL_THIS(iface);
618 TRACE("(%p)->(%p)\n", This, aOriginalURI);
620 if(This->original_uri)
621 nsIURI_AddRef(This->original_uri);
623 *aOriginalURI = This->original_uri;
624 return NS_OK;
627 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
629 nsChannel *This = NSCHANNEL_THIS(iface);
631 TRACE("(%p)->(%p)\n", This, aOriginalURI);
633 if(This->original_uri)
634 nsIURI_Release(This->original_uri);
636 nsIURI_AddRef(aOriginalURI);
637 This->original_uri = aOriginalURI;
638 return NS_OK;
641 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
643 nsChannel *This = NSCHANNEL_THIS(iface);
645 TRACE("(%p)->(%p)\n", This, aURI);
647 nsIURI_AddRef(NSURI(This->uri));
648 *aURI = (nsIURI*)This->uri;
650 return NS_OK;
653 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
655 nsChannel *This = NSCHANNEL_THIS(iface);
657 TRACE("(%p)->(%p)\n", This, aOwner);
659 if(This->owner)
660 nsISupports_AddRef(This->owner);
661 *aOwner = This->owner;
663 return NS_OK;
666 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
668 nsChannel *This = NSCHANNEL_THIS(iface);
670 TRACE("(%p)->(%p)\n", This, aOwner);
672 if(aOwner)
673 nsISupports_AddRef(aOwner);
674 if(This->owner)
675 nsISupports_Release(This->owner);
676 This->owner = aOwner;
678 return NS_OK;
681 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
682 nsIInterfaceRequestor **aNotificationCallbacks)
684 nsChannel *This = NSCHANNEL_THIS(iface);
686 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
688 if(This->notif_callback)
689 nsIInterfaceRequestor_AddRef(This->notif_callback);
690 *aNotificationCallbacks = This->notif_callback;
692 return NS_OK;
695 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
696 nsIInterfaceRequestor *aNotificationCallbacks)
698 nsChannel *This = NSCHANNEL_THIS(iface);
700 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
702 if(This->notif_callback)
703 nsIInterfaceRequestor_Release(This->notif_callback);
704 if(aNotificationCallbacks)
705 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
707 This->notif_callback = aNotificationCallbacks;
709 return NS_OK;
712 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
714 nsChannel *This = NSCHANNEL_THIS(iface);
716 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
718 return NS_ERROR_NOT_IMPLEMENTED;
721 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
723 nsChannel *This = NSCHANNEL_THIS(iface);
725 TRACE("(%p)->(%p)\n", This, aContentType);
727 if(This->content_type) {
728 nsACString_SetData(aContentType, This->content_type);
729 return S_OK;
732 WARN("unknown type\n");
733 return NS_ERROR_FAILURE;
736 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
737 const nsACString *aContentType)
739 nsChannel *This = NSCHANNEL_THIS(iface);
740 const char *content_type;
742 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
744 nsACString_GetData(aContentType, &content_type);
745 heap_free(This->content_type);
746 This->content_type = heap_strdupA(content_type);
748 return NS_OK;
751 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
752 nsACString *aContentCharset)
754 nsChannel *This = NSCHANNEL_THIS(iface);
756 TRACE("(%p)->(%p)\n", This, aContentCharset);
758 if(This->charset) {
759 nsACString_SetData(aContentCharset, This->charset);
760 return NS_OK;
763 nsACString_SetData(aContentCharset, "");
764 return NS_OK;
767 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
768 const nsACString *aContentCharset)
770 nsChannel *This = NSCHANNEL_THIS(iface);
772 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
774 return NS_ERROR_NOT_IMPLEMENTED;
777 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
779 nsChannel *This = NSCHANNEL_THIS(iface);
781 FIXME("(%p)->(%p)\n", This, aContentLength);
783 return NS_ERROR_NOT_IMPLEMENTED;
786 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
788 nsChannel *This = NSCHANNEL_THIS(iface);
790 FIXME("(%p)->(%d)\n", This, aContentLength);
792 return NS_ERROR_NOT_IMPLEMENTED;
795 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
797 nsChannel *This = NSCHANNEL_THIS(iface);
799 FIXME("(%p)->(%p)\n", This, _retval);
801 return NS_ERROR_NOT_IMPLEMENTED;
804 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
806 nsWineURI *wine_uri;
807 nsresult nsres;
808 HRESULT hres;
810 if(!channel->original_uri) {
811 ERR("original_uri == NULL\n");
812 return E_FAIL;
815 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsWineURI, (void**)&wine_uri);
816 if(NS_FAILED(nsres)) {
817 ERR("Could not get nsWineURI: %08x\n", nsres);
818 return E_FAIL;
821 if(wine_uri->wine_url) {
822 hres = CreateURLMoniker(NULL, wine_uri->wine_url, mon);
823 if(FAILED(hres))
824 WARN("CreateURLMoniker failed: %08x\n", hres);
825 }else {
826 TRACE("wine_url == NULL\n");
827 hres = E_FAIL;
830 nsIURI_Release(NSURI(wine_uri));
832 return hres;
835 static HTMLWindow *get_window_from_load_group(nsChannel *This)
837 HTMLWindow *window;
838 nsIChannel *channel;
839 nsIRequest *req;
840 nsWineURI *wine_uri;
841 nsIURI *uri;
842 nsresult nsres;
844 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
845 if(NS_FAILED(nsres)) {
846 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
847 return NULL;
850 if(!req)
851 return NULL;
853 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
854 nsIRequest_Release(req);
855 if(NS_FAILED(nsres)) {
856 WARN("Could not get nsIChannel interface: %08x\n", nsres);
857 return NULL;
860 nsres = nsIChannel_GetURI(channel, &uri);
861 nsIChannel_Release(channel);
862 if(NS_FAILED(nsres)) {
863 ERR("GetURI failed: %08x\n", nsres);
864 return NULL;
867 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
868 nsIURI_Release(uri);
869 if(NS_FAILED(nsres)) {
870 TRACE("Could not get nsWineURI: %08x\n", nsres);
871 return NULL;
874 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
875 if(window)
876 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
877 nsIURI_Release(NSURI(wine_uri));
879 return window;
882 static HTMLWindow *get_channel_window(nsChannel *This)
884 nsIRequestObserver *req_observer;
885 nsIWebProgress *web_progress;
886 nsIDOMWindow *nswindow;
887 HTMLWindow *window;
888 nsresult nsres;
890 if(!This->load_group) {
891 ERR("NULL load_group\n");
892 return NULL;
895 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
896 if(NS_FAILED(nsres) || !req_observer) {
897 ERR("GetGroupObserver failed: %08x\n", nsres);
898 return NULL;
901 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
902 nsIRequestObserver_Release(req_observer);
903 if(NS_FAILED(nsres)) {
904 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
905 return NULL;
908 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
909 nsIWebProgress_Release(web_progress);
910 if(NS_FAILED(nsres) || !nswindow) {
911 ERR("GetDOMWindow failed: %08x\n", nsres);
912 return NULL;
915 window = nswindow_to_window(nswindow);
916 nsIDOMWindow_Release(nswindow);
918 if(window)
919 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
920 else
921 FIXME("NULL window for %p\n", nswindow);
922 return window;
925 typedef struct {
926 task_t header;
927 HTMLDocumentNode *doc;
928 nsChannelBSC *bscallback;
929 } start_binding_task_t;
931 static void start_binding_proc(task_t *_task)
933 start_binding_task_t *task = (start_binding_task_t*)_task;
935 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
937 IUnknown_Release((IUnknown*)task->bscallback);
940 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
941 nsISupports *context)
943 nsChannelBSC *bscallback;
944 IMoniker *mon = NULL;
945 HRESULT hres;
947 hres = create_mon_for_nschannel(This, &mon);
948 if(FAILED(hres))
949 return NS_ERROR_UNEXPECTED;
951 if(is_doc_channel)
952 set_current_mon(window, mon);
954 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
955 IMoniker_Release(mon);
956 if(FAILED(hres))
957 return NS_ERROR_UNEXPECTED;
959 channelbsc_set_channel(bscallback, This, listener, context);
961 if(is_doc_channel) {
962 set_window_bscallback(window, bscallback);
963 async_start_doc_binding(window, bscallback);
964 IUnknown_Release((IUnknown*)bscallback);
965 }else {
966 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
968 task->doc = window->doc;
969 task->bscallback = bscallback;
970 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
973 return NS_OK;
976 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
977 nsISupports *aContext)
979 nsChannel *This = NSCHANNEL_THIS(iface);
980 HTMLWindow *window = NULL;
981 BOOL open = TRUE;
982 nsresult nsres = NS_OK;
984 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
986 if(This->uri->is_doc_uri) {
987 window = get_channel_window(This);
988 if(window) {
989 set_uri_window(This->uri, window);
990 }else if(This->uri->container) {
991 BOOL b;
993 /* nscontainer->doc should be NULL which means navigation to a new window */
994 if(This->uri->container->doc)
995 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
997 b = before_async_open(This, This->uri->container);
998 if(b)
999 FIXME("Navigation not cancelled\n");
1000 return NS_ERROR_UNEXPECTED;
1004 if(!window) {
1005 if(This->uri->window_ref && This->uri->window_ref->window) {
1006 window = This->uri->window_ref->window;
1007 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
1008 }else if(This->load_group) {
1009 window = get_window_from_load_group(This);
1010 if(window)
1011 set_uri_window(This->uri, window);
1015 if(!window) {
1016 ERR("window = NULL\n");
1017 return NS_ERROR_UNEXPECTED;
1020 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1021 if(This->uri->channel_bsc) {
1022 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1024 if(window->doc_obj->mime) {
1025 heap_free(This->content_type);
1026 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1029 open = FALSE;
1030 }else {
1031 open = !before_async_open(This, window->doc_obj->nscontainer);
1032 if(!open) {
1033 TRACE("canceled\n");
1034 nsres = NS_ERROR_UNEXPECTED;
1039 if(open)
1040 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1042 if(NS_SUCCEEDED(nsres) && This->load_group) {
1043 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)NSCHANNEL(This), aContext);
1044 if(NS_FAILED(nsres))
1045 ERR("AddRequest failed: %08x\n", nsres);
1048 IHTMLWindow2_Release(HTMLWINDOW2(window));
1049 return nsres;
1052 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1054 nsChannel *This = NSCHANNEL_THIS(iface);
1056 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1058 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1059 return NS_OK;
1062 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1063 const nsACString *aRequestMethod)
1065 nsChannel *This = NSCHANNEL_THIS(iface);
1066 const char *method;
1067 unsigned i;
1069 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1071 nsACString_GetData(aRequestMethod, &method);
1072 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1073 if(!strcasecmp(method, request_method_strings[i])) {
1074 This->request_method = i;
1075 return NS_OK;
1079 ERR("Invalid method %s\n", debugstr_a(method));
1080 return NS_ERROR_UNEXPECTED;
1083 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1085 nsChannel *This = NSCHANNEL_THIS(iface);
1087 TRACE("(%p)->(%p)\n", This, aReferrer);
1089 if(This->referrer)
1090 nsIURI_AddRef(This->referrer);
1091 *aReferrer = This->referrer;
1092 return NS_OK;
1095 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1097 nsChannel *This = NSCHANNEL_THIS(iface);
1099 TRACE("(%p)->(%p)\n", This, aReferrer);
1101 if(aReferrer)
1102 nsIURI_AddRef(aReferrer);
1103 if(This->referrer)
1104 nsIURI_Release(This->referrer);
1105 This->referrer = aReferrer;
1106 return NS_OK;
1109 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1110 const nsACString *aHeader, nsACString *_retval)
1112 nsChannel *This = NSCHANNEL_THIS(iface);
1114 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1116 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1119 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1120 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
1122 nsChannel *This = NSCHANNEL_THIS(iface);
1124 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1126 if(aMerge)
1127 FIXME("aMerge not supported\n");
1129 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1132 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1133 nsIHttpHeaderVisitor *aVisitor)
1135 nsChannel *This = NSCHANNEL_THIS(iface);
1137 FIXME("(%p)->(%p)\n", This, aVisitor);
1139 return NS_ERROR_NOT_IMPLEMENTED;
1142 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1144 nsChannel *This = NSCHANNEL_THIS(iface);
1146 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1148 return NS_ERROR_NOT_IMPLEMENTED;
1151 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1153 nsChannel *This = NSCHANNEL_THIS(iface);
1155 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1157 return NS_ERROR_NOT_IMPLEMENTED;
1160 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1162 nsChannel *This = NSCHANNEL_THIS(iface);
1164 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1166 return NS_ERROR_NOT_IMPLEMENTED;
1169 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1171 nsChannel *This = NSCHANNEL_THIS(iface);
1173 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1175 return NS_ERROR_NOT_IMPLEMENTED;
1178 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1180 nsChannel *This = NSCHANNEL_THIS(iface);
1182 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1184 if(This->response_status) {
1185 *aResponseStatus = This->response_status;
1186 return NS_OK;
1189 WARN("No response status\n");
1190 return NS_ERROR_UNEXPECTED;
1193 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1194 nsACString *aResponseStatusText)
1196 nsChannel *This = NSCHANNEL_THIS(iface);
1198 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1200 return NS_ERROR_NOT_IMPLEMENTED;
1203 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1204 PRBool *aRequestSucceeded)
1206 nsChannel *This = NSCHANNEL_THIS(iface);
1208 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1210 if(!This->response_status)
1211 return NS_ERROR_NOT_AVAILABLE;
1213 *aRequestSucceeded = This->response_status/100 == 2;
1215 return NS_OK;
1218 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1219 const nsACString *header, nsACString *_retval)
1221 nsChannel *This = NSCHANNEL_THIS(iface);
1223 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1225 return get_channel_http_header(&This->response_headers, header, _retval);
1228 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1229 const nsACString *header, const nsACString *value, PRBool merge)
1231 nsChannel *This = NSCHANNEL_THIS(iface);
1233 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1235 return NS_ERROR_NOT_IMPLEMENTED;
1238 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1239 nsIHttpHeaderVisitor *aVisitor)
1241 nsChannel *This = NSCHANNEL_THIS(iface);
1243 FIXME("(%p)->(%p)\n", This, aVisitor);
1245 return NS_ERROR_NOT_IMPLEMENTED;
1248 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1250 nsChannel *This = NSCHANNEL_THIS(iface);
1252 FIXME("(%p)->(%p)\n", This, _retval);
1254 return NS_ERROR_NOT_IMPLEMENTED;
1257 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1259 nsChannel *This = NSCHANNEL_THIS(iface);
1261 FIXME("(%p)->(%p)\n", This, _retval);
1263 return NS_ERROR_NOT_IMPLEMENTED;
1266 #undef NSCHANNEL_THIS
1268 static const nsIHttpChannelVtbl nsChannelVtbl = {
1269 nsChannel_QueryInterface,
1270 nsChannel_AddRef,
1271 nsChannel_Release,
1272 nsChannel_GetName,
1273 nsChannel_IsPending,
1274 nsChannel_GetStatus,
1275 nsChannel_Cancel,
1276 nsChannel_Suspend,
1277 nsChannel_Resume,
1278 nsChannel_GetLoadGroup,
1279 nsChannel_SetLoadGroup,
1280 nsChannel_GetLoadFlags,
1281 nsChannel_SetLoadFlags,
1282 nsChannel_GetOriginalURI,
1283 nsChannel_SetOriginalURI,
1284 nsChannel_GetURI,
1285 nsChannel_GetOwner,
1286 nsChannel_SetOwner,
1287 nsChannel_GetNotificationCallbacks,
1288 nsChannel_SetNotificationCallbacks,
1289 nsChannel_GetSecurityInfo,
1290 nsChannel_GetContentType,
1291 nsChannel_SetContentType,
1292 nsChannel_GetContentCharset,
1293 nsChannel_SetContentCharset,
1294 nsChannel_GetContentLength,
1295 nsChannel_SetContentLength,
1296 nsChannel_Open,
1297 nsChannel_AsyncOpen,
1298 nsChannel_GetRequestMethod,
1299 nsChannel_SetRequestMethod,
1300 nsChannel_GetReferrer,
1301 nsChannel_SetReferrer,
1302 nsChannel_GetRequestHeader,
1303 nsChannel_SetRequestHeader,
1304 nsChannel_VisitRequestHeaders,
1305 nsChannel_GetAllowPipelining,
1306 nsChannel_SetAllowPipelining,
1307 nsChannel_GetRedirectionLimit,
1308 nsChannel_SetRedirectionLimit,
1309 nsChannel_GetResponseStatus,
1310 nsChannel_GetResponseStatusText,
1311 nsChannel_GetRequestSucceeded,
1312 nsChannel_GetResponseHeader,
1313 nsChannel_SetResponseHeader,
1314 nsChannel_VisitResponseHeaders,
1315 nsChannel_IsNoStoreResponse,
1316 nsChannel_IsNoCacheResponse
1319 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1321 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1322 void **result)
1324 nsChannel *This = NSUPCHANNEL_THIS(iface);
1325 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1328 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1330 nsChannel *This = NSUPCHANNEL_THIS(iface);
1331 return nsIChannel_AddRef(NSCHANNEL(This));
1334 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1336 nsChannel *This = NSUPCHANNEL_THIS(iface);
1337 return nsIChannel_Release(NSCHANNEL(This));
1340 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1341 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1343 nsChannel *This = NSUPCHANNEL_THIS(iface);
1344 const char *content_type;
1346 static const WCHAR content_typeW[] =
1347 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1349 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1351 This->parse_stream = TRUE;
1352 if(aContentType) {
1353 nsACString_GetData(aContentType, &content_type);
1354 if(*content_type) {
1355 WCHAR *ct;
1357 ct = heap_strdupAtoW(content_type);
1358 if(!ct)
1359 return NS_ERROR_UNEXPECTED;
1361 set_http_header(&This->request_headers, content_typeW,
1362 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1363 heap_free(ct);
1364 This->parse_stream = FALSE;
1368 if(This->post_data_stream)
1369 nsIInputStream_Release(This->post_data_stream);
1371 if(aContentLength != -1)
1372 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1374 if(This->post_data_stream)
1375 nsIInputStream_Release(This->post_data_stream);
1376 This->post_data_stream = aStream;
1377 if(aStream)
1378 nsIInputStream_AddRef(aStream);
1380 This->request_method = METHOD_POST;
1381 return NS_OK;
1384 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1385 nsIInputStream **aUploadStream)
1387 nsChannel *This = NSUPCHANNEL_THIS(iface);
1389 TRACE("(%p)->(%p)\n", This, aUploadStream);
1391 if(This->post_data_stream)
1392 nsIInputStream_AddRef(This->post_data_stream);
1394 *aUploadStream = This->post_data_stream;
1395 return NS_OK;
1398 #undef NSUPCHANNEL_THIS
1400 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1401 nsUploadChannel_QueryInterface,
1402 nsUploadChannel_AddRef,
1403 nsUploadChannel_Release,
1404 nsUploadChannel_SetUploadStream,
1405 nsUploadChannel_GetUploadStream
1408 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1410 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1411 void **result)
1413 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1414 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1417 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1419 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1420 return nsIChannel_AddRef(NSCHANNEL(This));
1423 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1425 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1426 return nsIChannel_Release(NSCHANNEL(This));
1429 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1431 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1433 FIXME("(%p)->()\n", This);
1435 return NS_ERROR_NOT_IMPLEMENTED;
1438 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1440 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1442 FIXME("(%p)->()\n", This);
1444 return NS_ERROR_NOT_IMPLEMENTED;
1447 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1449 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1451 FIXME("(%p)->()\n", This);
1453 return NS_ERROR_NOT_IMPLEMENTED;
1456 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1458 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1460 FIXME("(%p)->()\n", This);
1462 return NS_ERROR_NOT_IMPLEMENTED;
1465 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1467 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1469 FIXME("(%p)->()\n", This);
1471 return NS_ERROR_NOT_IMPLEMENTED;
1474 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1476 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1478 FIXME("(%p)->()\n", This);
1480 return NS_ERROR_NOT_IMPLEMENTED;
1483 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1485 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1487 FIXME("(%p)->()\n", This);
1489 return NS_ERROR_NOT_IMPLEMENTED;
1492 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1494 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1496 FIXME("(%p)->()\n", This);
1498 return NS_ERROR_NOT_IMPLEMENTED;
1501 static nsresult NSAPI nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal *iface, PRBool *aCanceled)
1503 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1505 FIXME("(%p)->(%p)\n", This, aCanceled);
1507 return NS_ERROR_NOT_IMPLEMENTED;
1510 #undef NSHTTPINTERNAL_THIS
1512 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1513 nsHttpChannelInternal_QueryInterface,
1514 nsHttpChannelInternal_AddRef,
1515 nsHttpChannelInternal_Release,
1516 nsHttpChannelInternal_GetDocumentURI,
1517 nsHttpChannelInternal_SetDocumentURI,
1518 nsHttpChannelInternal_GetRequestVersion,
1519 nsHttpChannelInternal_GetResponseVersion,
1520 nsHttpChannelInternal_SetCookie,
1521 nsHttpChannelInternal_SetupFallbackChannel,
1522 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1523 nsHttpChannelInternal_SetForceAllowThirdPartyCookie,
1524 nsHttpChannelInternal_GetCanceled
1527 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1529 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, void **result)
1531 nsWineURI *This = NSURI_THIS(iface);
1533 *result = NULL;
1535 if(IsEqualGUID(&IID_nsISupports, riid)) {
1536 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1537 *result = NSURI(This);
1538 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1539 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1540 *result = NSURI(This);
1541 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1542 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1543 *result = NSURL(This);
1544 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1545 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1546 *result = This;
1549 if(*result) {
1550 nsIURI_AddRef(NSURI(This));
1551 return NS_OK;
1554 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1555 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1558 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1560 nsWineURI *This = NSURI_THIS(iface);
1561 LONG ref = InterlockedIncrement(&This->ref);
1563 TRACE("(%p) ref=%d\n", This, ref);
1565 return ref;
1568 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1570 nsWineURI *This = NSURI_THIS(iface);
1571 LONG ref = InterlockedDecrement(&This->ref);
1573 TRACE("(%p) ref=%d\n", This, ref);
1575 if(!ref) {
1576 if(This->window_ref)
1577 windowref_release(This->window_ref);
1578 if(This->container)
1579 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1580 if(This->nsurl)
1581 nsIURL_Release(This->nsurl);
1582 if(This->uri)
1583 nsIURI_Release(This->uri);
1584 heap_free(This->wine_url);
1585 heap_free(This);
1588 return ref;
1591 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1593 nsWineURI *This = NSURI_THIS(iface);
1595 TRACE("(%p)->(%p)\n", This, aSpec);
1597 if(This->use_wine_url) {
1598 char speca[INTERNET_MAX_URL_LENGTH];
1599 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca, sizeof(speca), NULL, NULL);
1600 nsACString_SetData(aSpec, speca);
1602 return NS_OK;
1605 if(This->uri)
1606 return nsIURI_GetSpec(This->uri, aSpec);
1608 TRACE("returning error\n");
1609 return NS_ERROR_NOT_IMPLEMENTED;
1613 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1615 nsWineURI *This = NSURI_THIS(iface);
1617 TRACE("(%p)->(%p)\n", This, debugstr_nsacstr(aSpec));
1619 if(This->uri)
1620 return nsIURI_SetSpec(This->uri, aSpec);
1622 FIXME("default action not implemented\n");
1623 return NS_ERROR_NOT_IMPLEMENTED;
1626 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1628 nsWineURI *This = NSURI_THIS(iface);
1630 TRACE("(%p)->(%p)\n", This, aPrePath);
1632 if(This->uri)
1633 return nsIURI_GetPrePath(This->uri, aPrePath);
1635 FIXME("default action not implemented\n");
1636 return NS_ERROR_NOT_IMPLEMENTED;
1639 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1641 nsWineURI *This = NSURI_THIS(iface);
1643 TRACE("(%p)->(%p)\n", This, aScheme);
1645 if(This->use_wine_url) {
1646 char scheme[INTERNET_MAX_SCHEME_LENGTH+1];
1647 WCHAR *ptr;
1648 int len;
1650 ptr = strchrW(This->wine_url, ':');
1651 if(!ptr) {
1652 nsACString_SetData(aScheme, "wine");
1653 return NS_OK;
1656 len = WideCharToMultiByte(CP_ACP, 0, This->wine_url, ptr-This->wine_url, scheme,
1657 sizeof(scheme), NULL, NULL);
1658 scheme[min(len,sizeof(scheme)-1)] = 0;
1659 nsACString_SetData(aScheme, strcmp(scheme, "about") ? scheme : "wine");
1660 return NS_OK;
1663 if(This->uri)
1664 return nsIURI_GetScheme(This->uri, aScheme);
1666 TRACE("returning error\n");
1667 return NS_ERROR_NOT_IMPLEMENTED;
1670 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1672 nsWineURI *This = NSURI_THIS(iface);
1674 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1676 if(This->uri)
1677 return nsIURI_SetScheme(This->uri, aScheme);
1679 FIXME("default action not implemented\n");
1680 return NS_ERROR_NOT_IMPLEMENTED;
1683 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1685 nsWineURI *This = NSURI_THIS(iface);
1687 TRACE("(%p)->(%p)\n", This, aUserPass);
1689 if(This->uri)
1690 return nsIURI_GetUserPass(This->uri, aUserPass);
1692 FIXME("default action not implemented\n");
1693 return NS_ERROR_NOT_IMPLEMENTED;
1696 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1698 nsWineURI *This = NSURI_THIS(iface);
1700 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
1702 if(This->uri)
1703 return nsIURI_SetUserPass(This->uri, aUserPass);
1705 FIXME("default action not implemented\n");
1706 return NS_ERROR_NOT_IMPLEMENTED;
1709 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1711 nsWineURI *This = NSURI_THIS(iface);
1713 TRACE("(%p)->(%p)\n", This, aUsername);
1715 if(This->uri)
1716 return nsIURI_GetUsername(This->uri, aUsername);
1718 FIXME("default action not implemented\n");
1719 return NS_ERROR_NOT_IMPLEMENTED;
1722 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1724 nsWineURI *This = NSURI_THIS(iface);
1726 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
1728 if(This->uri)
1729 return nsIURI_SetUsername(This->uri, aUsername);
1731 FIXME("default action not implemented\n");
1732 return NS_ERROR_NOT_IMPLEMENTED;
1735 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1737 nsWineURI *This = NSURI_THIS(iface);
1739 TRACE("(%p)->(%p)\n", This, aPassword);
1741 if(This->uri)
1742 return nsIURI_GetPassword(This->uri, aPassword);
1744 FIXME("default action not implemented\n");
1745 return NS_ERROR_NOT_IMPLEMENTED;
1748 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1750 nsWineURI *This = NSURI_THIS(iface);
1752 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
1754 if(This->uri)
1755 return nsIURI_SetPassword(This->uri, aPassword);
1757 FIXME("default action not implemented\n");
1758 return NS_ERROR_NOT_IMPLEMENTED;
1761 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1763 nsWineURI *This = NSURI_THIS(iface);
1765 TRACE("(%p)->(%p)\n", This, aHostPort);
1767 if(This->uri)
1768 return nsIURI_GetHostPort(This->uri, aHostPort);
1770 FIXME("default action not implemented\n");
1771 return NS_ERROR_NOT_IMPLEMENTED;
1774 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1776 nsWineURI *This = NSURI_THIS(iface);
1778 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
1780 if(This->uri)
1781 return nsIURI_SetHostPort(This->uri, aHostPort);
1783 FIXME("default action not implemented\n");
1784 return NS_ERROR_NOT_IMPLEMENTED;
1787 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1789 nsWineURI *This = NSURI_THIS(iface);
1791 TRACE("(%p)->(%p)\n", This, aHost);
1793 if(This->uri)
1794 return nsIURI_GetHost(This->uri, aHost);
1796 FIXME("default action not implemented\n");
1797 return NS_ERROR_NOT_IMPLEMENTED;
1800 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1802 nsWineURI *This = NSURI_THIS(iface);
1804 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
1806 if(This->uri)
1807 return nsIURI_SetHost(This->uri, aHost);
1809 FIXME("default action not implemented\n");
1810 return NS_ERROR_NOT_IMPLEMENTED;
1813 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1815 nsWineURI *This = NSURI_THIS(iface);
1817 TRACE("(%p)->(%p)\n", This, aPort);
1819 if(This->uri)
1820 return nsIURI_GetPort(This->uri, aPort);
1822 FIXME("default action not implemented\n");
1823 return NS_ERROR_NOT_IMPLEMENTED;
1826 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1828 nsWineURI *This = NSURI_THIS(iface);
1830 TRACE("(%p)->(%d)\n", This, aPort);
1832 if(This->uri)
1833 return nsIURI_SetPort(This->uri, aPort);
1835 FIXME("default action not implemented\n");
1836 return NS_ERROR_NOT_IMPLEMENTED;
1839 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
1841 nsWineURI *This = NSURI_THIS(iface);
1843 TRACE("(%p)->(%p)\n", This, aPath);
1845 if(This->uri)
1846 return nsIURI_GetPath(This->uri, aPath);
1848 FIXME("default action not implemented\n");
1849 return NS_ERROR_NOT_IMPLEMENTED;
1852 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
1854 nsWineURI *This = NSURI_THIS(iface);
1855 const char *path;
1857 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
1859 nsACString_GetData(aPath, &path);
1860 if(This->wine_url) {
1861 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1862 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1863 LPWSTR pathw;
1864 HRESULT hres;
1866 pathw = heap_strdupAtoW(path);
1867 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1868 heap_free(pathw);
1869 if(SUCCEEDED(hres))
1870 set_wine_url(This, new_url);
1871 else
1872 WARN("UrlCombine failed: %08x\n", hres);
1875 if(!This->uri)
1876 return NS_OK;
1878 return nsIURI_SetPath(This->uri, aPath);
1881 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
1883 nsWineURI *This = NSURI_THIS(iface);
1884 nsWineURI *wine_uri;
1885 nsresult nsres;
1887 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1889 if(This->uri)
1890 return nsIURI_Equals(This->uri, other, _retval);
1892 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&wine_uri);
1893 if(NS_FAILED(nsres)) {
1894 TRACE("Could not get nsWineURI interface\n");
1895 *_retval = FALSE;
1896 return NS_OK;
1899 *_retval = wine_uri->wine_url && !UrlCompareW(This->wine_url, wine_uri->wine_url, TRUE);
1900 nsIURI_Release(NSURI(wine_uri));
1902 return NS_OK;
1905 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
1907 nsWineURI *This = NSURI_THIS(iface);
1909 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1911 if(This->use_wine_url) {
1912 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1913 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1915 *_retval = lstrlenW(This->wine_url) > len
1916 && This->wine_url[len] == ':'
1917 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1918 return NS_OK;
1921 if(This->uri)
1922 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1924 TRACE("returning error\n");
1925 return NS_ERROR_NOT_IMPLEMENTED;
1928 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
1930 nsWineURI *This = NSURI_THIS(iface);
1931 nsIURI *nsuri = NULL;
1932 nsWineURI *wine_uri;
1933 nsresult nsres;
1935 TRACE("(%p)->(%p)\n", This, _retval);
1937 if(This->uri) {
1938 nsres = nsIURI_Clone(This->uri, &nsuri);
1939 if(NS_FAILED(nsres)) {
1940 WARN("Clone failed: %08x\n", nsres);
1941 return nsres;
1945 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1946 if(NS_FAILED(nsres)) {
1947 WARN("create_uri failed: %08x\n", nsres);
1948 return nsres;
1951 set_wine_url(wine_uri, This->wine_url);
1953 *_retval = NSURI(wine_uri);
1954 return NS_OK;
1957 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *aRelativePath,
1958 nsACString *_retval)
1960 nsWineURI *This = NSURI_THIS(iface);
1961 WCHAR url[INTERNET_MAX_URL_LENGTH];
1962 const char *patha;
1963 WCHAR *path;
1964 char *urla;
1965 DWORD len;
1966 HRESULT hres;
1968 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
1970 if(This->uri)
1971 return nsIURI_Resolve(This->uri, aRelativePath, _retval);
1973 nsACString_GetData(aRelativePath, &patha);
1974 path = heap_strdupAtoW(patha);
1975 if(!path)
1976 return NS_ERROR_OUT_OF_MEMORY;
1978 hres = CoInternetCombineUrl(This->wine_url, path,
1979 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
1980 url, sizeof(url)/sizeof(WCHAR), &len, 0);
1981 heap_free(path);
1982 if(FAILED(hres)) {
1983 ERR("CoIntenetCombineUrl failed: %08x\n", hres);
1984 return NS_ERROR_FAILURE;
1987 urla = heap_strdupWtoA(url);
1988 if(!urla)
1989 return NS_ERROR_OUT_OF_MEMORY;
1991 TRACE("returning %s\n", debugstr_a(urla));
1992 nsACString_SetData(_retval, urla);
1993 heap_free(urla);
1994 return NS_OK;
1997 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
1999 nsWineURI *This = NSURI_THIS(iface);
2001 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
2003 if(This->use_wine_url)
2004 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
2006 if(This->uri)
2007 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
2009 TRACE("returning error\n");
2010 return NS_ERROR_NOT_IMPLEMENTED;
2013 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
2015 nsWineURI *This = NSURI_THIS(iface);
2017 TRACE("(%p)->(%p)\n", This, aAsciiHost);
2019 if(This->uri)
2020 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
2022 FIXME("default action not implemented\n");
2023 return NS_ERROR_NOT_IMPLEMENTED;
2026 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
2028 nsWineURI *This = NSURI_THIS(iface);
2030 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2032 if(This->uri)
2033 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
2035 FIXME("default action not implemented\n");
2036 return NS_ERROR_NOT_IMPLEMENTED;
2039 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
2041 nsWineURI *This = NSURI_THIS(iface);
2043 TRACE("(%p)->(%p)\n", This, aFilePath);
2045 if(This->nsurl)
2046 return nsIURL_GetFilePath(This->nsurl, aFilePath);
2048 FIXME("default action not implemented\n");
2049 return NS_ERROR_NOT_IMPLEMENTED;
2052 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
2054 nsWineURI *This = NSURI_THIS(iface);
2056 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2058 if(This->nsurl)
2059 return nsIURL_SetFilePath(This->nsurl, aFilePath);
2061 FIXME("default action not implemented\n");
2062 return NS_ERROR_NOT_IMPLEMENTED;
2065 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
2067 nsWineURI *This = NSURI_THIS(iface);
2069 TRACE("(%p)->(%p)\n", This, aParam);
2071 if(This->nsurl)
2072 return nsIURL_GetParam(This->nsurl, aParam);
2074 FIXME("default action not implemented\n");
2075 return NS_ERROR_NOT_IMPLEMENTED;
2078 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
2080 nsWineURI *This = NSURI_THIS(iface);
2082 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
2084 if(This->nsurl)
2085 return nsIURL_SetParam(This->nsurl, aParam);
2087 FIXME("default action not implemented\n");
2088 return NS_ERROR_NOT_IMPLEMENTED;
2091 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
2093 nsWineURI *This = NSURI_THIS(iface);
2095 TRACE("(%p)->(%p)\n", This, aQuery);
2097 if(This->nsurl)
2098 return nsIURL_GetQuery(This->nsurl, aQuery);
2100 FIXME("default action not implemented\n");
2101 return NS_ERROR_NOT_IMPLEMENTED;
2104 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
2106 nsWineURI *This = NSURI_THIS(iface);
2107 const WCHAR *ptr1, *ptr2;
2108 const char *query;
2109 WCHAR *new_url, *ptr;
2110 DWORD len, size;
2112 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2114 if(This->nsurl)
2115 nsIURL_SetQuery(This->nsurl, aQuery);
2117 if(!This->wine_url)
2118 return NS_OK;
2120 nsACString_GetData(aQuery, &query);
2121 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
2122 ptr1 = strchrW(This->wine_url, '?');
2123 if(ptr1) {
2124 size += ptr1-This->wine_url;
2125 ptr2 = strchrW(ptr1, '#');
2126 if(ptr2)
2127 size += strlenW(ptr2);
2128 }else {
2129 ptr1 = This->wine_url + strlenW(This->wine_url);
2130 ptr2 = NULL;
2131 size += strlenW(This->wine_url);
2134 if(*query)
2135 size++;
2137 new_url = heap_alloc(size*sizeof(WCHAR));
2138 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
2139 ptr = new_url + (ptr1-This->wine_url);
2140 if(*query) {
2141 *ptr++ = '?';
2142 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
2143 ptr += len-1;
2145 if(ptr2)
2146 strcpyW(ptr, ptr2);
2147 else
2148 *ptr = 0;
2150 TRACE("setting %s\n", debugstr_w(new_url));
2152 heap_free(This->wine_url);
2153 This->wine_url = new_url;
2154 return NS_OK;
2157 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
2159 nsWineURI *This = NSURI_THIS(iface);
2161 TRACE("(%p)->(%p)\n", This, aRef);
2163 if(This->nsurl)
2164 return nsIURL_GetRef(This->nsurl, aRef);
2166 FIXME("default action not implemented\n");
2167 return NS_ERROR_NOT_IMPLEMENTED;
2170 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
2172 nsWineURI *This = NSURI_THIS(iface);
2173 const char *refa;
2175 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2177 if(This->nsurl)
2178 return nsIURL_SetRef(This->nsurl, aRef);
2180 nsACString_GetData(aRef, &refa);
2181 if(!*refa)
2182 return NS_OK;
2184 FIXME("default action not implemented\n");
2185 return NS_ERROR_NOT_IMPLEMENTED;
2188 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
2190 nsWineURI *This = NSURI_THIS(iface);
2192 TRACE("(%p)->(%p)\n", This, aDirectory);
2194 if(This->nsurl)
2195 return nsIURL_GetDirectory(This->nsurl, aDirectory);
2197 FIXME("default action not implemented\n");
2198 return NS_ERROR_NOT_IMPLEMENTED;
2201 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2203 nsWineURI *This = NSURI_THIS(iface);
2205 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2207 if(This->nsurl)
2208 return nsIURL_SetDirectory(This->nsurl, aDirectory);
2210 FIXME("default action not implemented\n");
2211 return NS_ERROR_NOT_IMPLEMENTED;
2214 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2216 nsWineURI *This = NSURI_THIS(iface);
2218 TRACE("(%p)->(%p)\n", This, aFileName);
2220 if(This->nsurl)
2221 return nsIURL_GetFileName(This->nsurl, aFileName);
2223 FIXME("default action not implemented\n");
2224 return NS_ERROR_NOT_IMPLEMENTED;
2227 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2229 nsWineURI *This = NSURI_THIS(iface);
2231 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2233 if(This->nsurl)
2234 return nsIURL_SetFileName(This->nsurl, aFileName);
2236 FIXME("default action not implemented\n");
2237 return NS_ERROR_NOT_IMPLEMENTED;
2240 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2242 nsWineURI *This = NSURI_THIS(iface);
2244 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2246 if(This->nsurl)
2247 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2249 FIXME("default action not implemented\n");
2250 return NS_ERROR_NOT_IMPLEMENTED;
2253 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2255 nsWineURI *This = NSURI_THIS(iface);
2257 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2259 if(This->nsurl)
2260 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2262 FIXME("default action not implemented\n");
2263 return NS_ERROR_NOT_IMPLEMENTED;
2266 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2268 nsWineURI *This = NSURI_THIS(iface);
2270 TRACE("(%p)->(%p)\n", This, aFileExtension);
2272 if(This->nsurl)
2273 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2275 FIXME("default action not implemented\n");
2276 return NS_ERROR_NOT_IMPLEMENTED;
2279 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2281 nsWineURI *This = NSURI_THIS(iface);
2283 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2285 if(This->nsurl)
2286 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2288 FIXME("default action not implemented\n");
2289 return NS_ERROR_NOT_IMPLEMENTED;
2292 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2294 nsWineURI *This = NSURI_THIS(iface);
2296 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2298 if(This->nsurl)
2299 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2301 FIXME("default action not implemented\n");
2302 return NS_ERROR_NOT_IMPLEMENTED;
2305 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2307 nsWineURI *This = NSURI_THIS(iface);
2309 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2311 if(This->nsurl)
2312 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2314 FIXME("default action not implemented\n");
2315 return NS_ERROR_NOT_IMPLEMENTED;
2318 #undef NSURI_THIS
2320 static const nsIURLVtbl nsURLVtbl = {
2321 nsURI_QueryInterface,
2322 nsURI_AddRef,
2323 nsURI_Release,
2324 nsURI_GetSpec,
2325 nsURI_SetSpec,
2326 nsURI_GetPrePath,
2327 nsURI_GetScheme,
2328 nsURI_SetScheme,
2329 nsURI_GetUserPass,
2330 nsURI_SetUserPass,
2331 nsURI_GetUsername,
2332 nsURI_SetUsername,
2333 nsURI_GetPassword,
2334 nsURI_SetPassword,
2335 nsURI_GetHostPort,
2336 nsURI_SetHostPort,
2337 nsURI_GetHost,
2338 nsURI_SetHost,
2339 nsURI_GetPort,
2340 nsURI_SetPort,
2341 nsURI_GetPath,
2342 nsURI_SetPath,
2343 nsURI_Equals,
2344 nsURI_SchemeIs,
2345 nsURI_Clone,
2346 nsURI_Resolve,
2347 nsURI_GetAsciiSpec,
2348 nsURI_GetAsciiHost,
2349 nsURI_GetOriginCharset,
2350 nsURL_GetFilePath,
2351 nsURL_SetFilePath,
2352 nsURL_GetParam,
2353 nsURL_SetParam,
2354 nsURL_GetQuery,
2355 nsURL_SetQuery,
2356 nsURL_GetRef,
2357 nsURL_SetRef,
2358 nsURL_GetDirectory,
2359 nsURL_SetDirectory,
2360 nsURL_GetFileName,
2361 nsURL_SetFileName,
2362 nsURL_GetFileBaseName,
2363 nsURL_SetFileBaseName,
2364 nsURL_GetFileExtension,
2365 nsURL_SetFileExtension,
2366 nsURL_GetCommonBaseSpec,
2367 nsURL_GetRelativeSpec
2370 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2372 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2374 ret->lpIURLVtbl = &nsURLVtbl;
2375 ret->ref = 1;
2376 ret->uri = uri;
2378 set_uri_nscontainer(ret, container);
2379 set_uri_window(ret, window);
2381 if(uri)
2382 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2384 TRACE("retval=%p\n", ret);
2385 *_retval = ret;
2386 return NS_OK;
2389 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2391 nsWineURI *uri;
2392 nsresult nsres;
2394 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2395 if(NS_FAILED(nsres))
2396 return E_FAIL;
2398 set_wine_url(uri, url);
2399 uri->is_doc_uri = TRUE;
2401 *ret = uri;
2402 return S_OK;
2405 typedef struct {
2406 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2408 LONG ref;
2410 nsIProtocolHandler *nshandler;
2411 } nsProtocolHandler;
2413 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2415 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2417 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2418 void **result)
2420 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2422 *result = NULL;
2424 if(IsEqualGUID(&IID_nsISupports, riid)) {
2425 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2426 *result = NSPROTHANDLER(This);
2427 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2428 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2429 *result = NSPROTHANDLER(This);
2430 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2431 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2432 return NS_NOINTERFACE;
2435 if(*result) {
2436 nsISupports_AddRef((nsISupports*)*result);
2437 return NS_OK;
2440 WARN("(%s %p)\n", debugstr_guid(riid), result);
2441 return NS_NOINTERFACE;
2444 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2446 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2447 LONG ref = InterlockedIncrement(&This->ref);
2449 TRACE("(%p) ref=%d\n", This, ref);
2451 return ref;
2454 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2456 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2457 LONG ref = InterlockedDecrement(&This->ref);
2459 TRACE("(%p) ref=%d\n", This, ref);
2461 if(!ref) {
2462 if(This->nshandler)
2463 nsIProtocolHandler_Release(This->nshandler);
2464 heap_free(This);
2467 return ref;
2470 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2472 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2474 TRACE("(%p)->(%p)\n", This, aScheme);
2476 if(This->nshandler)
2477 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2478 return NS_ERROR_NOT_IMPLEMENTED;
2481 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2482 PRInt32 *aDefaultPort)
2484 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2486 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2488 if(This->nshandler)
2489 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2490 return NS_ERROR_NOT_IMPLEMENTED;
2493 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2494 PRUint32 *aProtocolFlags)
2496 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2498 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2500 if(This->nshandler)
2501 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2502 return NS_ERROR_NOT_IMPLEMENTED;
2505 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2506 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2508 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2510 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2511 aBaseURI, _retval);
2513 if(This->nshandler)
2514 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2515 return NS_ERROR_NOT_IMPLEMENTED;
2518 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2519 nsIURI *aURI, nsIChannel **_retval)
2521 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2523 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2525 if(This->nshandler)
2526 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2527 return NS_ERROR_NOT_IMPLEMENTED;
2530 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2531 PRInt32 port, const char *scheme, PRBool *_retval)
2533 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2535 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2537 if(This->nshandler)
2538 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2539 return NS_ERROR_NOT_IMPLEMENTED;
2542 #undef NSPROTHANDLER_THIS
2544 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2545 nsProtocolHandler_QueryInterface,
2546 nsProtocolHandler_AddRef,
2547 nsProtocolHandler_Release,
2548 nsProtocolHandler_GetScheme,
2549 nsProtocolHandler_GetDefaultPort,
2550 nsProtocolHandler_GetProtocolFlags,
2551 nsProtocolHandler_NewURI,
2552 nsProtocolHandler_NewChannel,
2553 nsProtocolHandler_AllowPort
2556 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2558 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2560 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2561 ret->ref = 1;
2562 ret->nshandler = nshandler;
2564 return NSPROTHANDLER(ret);
2567 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
2569 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2571 return 2;
2574 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2576 return 1;
2579 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2580 nsIProtocolHandler **_retval)
2582 nsIExternalProtocolHandler *nsexthandler;
2583 nsIProtocolHandler *nshandler;
2584 nsresult nsres;
2586 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2588 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2589 if(NS_FAILED(nsres)) {
2590 WARN("GetProtocolHandler failed: %08x\n", nsres);
2591 return nsres;
2594 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2595 (void**)&nsexthandler);
2596 if(NS_FAILED(nsres)) {
2597 *_retval = nshandler;
2598 return NS_OK;
2601 nsIExternalProtocolHandler_Release(nsexthandler);
2602 *_retval = create_protocol_handler(nshandler);
2603 TRACE("return %p\n", *_retval);
2604 return NS_OK;
2607 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2608 PRUint32 *_retval)
2610 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2611 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2614 static BOOL is_gecko_special_uri(const char *spec)
2616 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2617 int i;
2619 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2620 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2621 return TRUE;
2624 if(!strncasecmp(spec, "file:", 5)) {
2625 const char *ptr = spec+5;
2626 while(*ptr == '/')
2627 ptr++;
2628 return is_gecko_path(ptr);
2631 return FALSE;
2634 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2635 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2637 nsWineURI *wine_uri, *base_wine_uri = NULL;
2638 const char *spec = NULL;
2639 HTMLWindow *window = NULL;
2640 nsIURI *uri = NULL;
2641 LPCWSTR base_wine_url = NULL;
2642 nsACString spec_str;
2643 nsresult nsres;
2646 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2647 aBaseURI, _retval);
2649 nsACString_GetData(aSpec, &spec);
2650 if(is_gecko_special_uri(spec))
2651 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2653 if(!strncmp(spec, "wine:", 5))
2654 spec += 5;
2656 if(aBaseURI) {
2657 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2659 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
2660 if(NS_SUCCEEDED(nsres)) {
2661 base_wine_url = base_wine_uri->wine_url;
2662 if(base_wine_uri->window_ref && base_wine_uri->window_ref->window) {
2663 window = base_wine_uri->window_ref->window;
2664 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2666 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2667 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2668 TRACE("not wraping\n");
2669 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2670 }else {
2671 WARN("Could not get base nsWineURI: %08x\n", nsres);
2675 nsACString_InitDepend(&spec_str, spec);
2676 nsres = nsIIOService_NewURI(nsio, &spec_str, aOriginCharset, aBaseURI, &uri);
2677 nsACString_Finish(&spec_str);
2678 if(NS_FAILED(nsres))
2679 TRACE("NewURI failed: %08x\n", nsres);
2681 nsres = create_uri(uri, window, NULL, &wine_uri);
2682 *_retval = (nsIURI*)wine_uri;
2684 if(window)
2685 IHTMLWindow2_Release(HTMLWINDOW2(window));
2687 if(base_wine_url) {
2688 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2689 DWORD len;
2690 HRESULT hres;
2692 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2694 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2695 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2696 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2697 if(SUCCEEDED(hres))
2698 set_wine_url(wine_uri, url);
2699 else
2700 WARN("CoCombineUrl failed: %08x\n", hres);
2701 }else {
2702 WCHAR url[INTERNET_MAX_URL_LENGTH];
2704 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2705 set_wine_url(wine_uri, url);
2708 if(base_wine_uri)
2709 nsIURI_Release(NSURI(base_wine_uri));
2711 return nsres;
2714 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2715 nsIURI **_retval)
2717 TRACE("(%p %p)\n", aFile, _retval);
2718 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2721 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2722 nsIChannel **_retval)
2724 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2725 nsChannel *ret;
2726 nsWineURI *wine_uri;
2727 nsresult nsres;
2729 TRACE("(%p %p)\n", aURI, _retval);
2731 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2732 if(NS_FAILED(nsres)) {
2733 TRACE("Could not get nsWineURI: %08x\n", nsres);
2734 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2737 ret = heap_alloc_zero(sizeof(nsChannel));
2739 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2740 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2741 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2742 ret->ref = 1;
2743 ret->uri = wine_uri;
2744 ret->request_method = METHOD_GET;
2745 list_init(&ret->response_headers);
2746 list_init(&ret->request_headers);
2748 nsIURI_AddRef(aURI);
2749 ret->original_uri = aURI;
2750 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2751 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2753 *_retval = NSCHANNEL(ret);
2754 return NS_OK;
2757 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2758 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2760 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
2761 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2764 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2766 TRACE("(%p)\n", aOffline);
2767 return nsIIOService_GetOffline(nsio, aOffline);
2770 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2772 TRACE("(%x)\n", aOffline);
2773 return nsIIOService_SetOffline(nsio, aOffline);
2776 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2777 const char *aScheme, PRBool *_retval)
2779 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2780 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2783 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2784 nsACString * _retval)
2786 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
2787 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2790 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2791 nsIOService_QueryInterface,
2792 nsIOService_AddRef,
2793 nsIOService_Release,
2794 nsIOService_GetProtocolHandler,
2795 nsIOService_GetProtocolFlags,
2796 nsIOService_NewURI,
2797 nsIOService_NewFileURI,
2798 nsIOService_NewChannelFromURI,
2799 nsIOService_NewChannel,
2800 nsIOService_GetOffline,
2801 nsIOService_SetOffline,
2802 nsIOService_AllowPort,
2803 nsIOService_ExtractScheme
2806 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2808 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2809 void **result)
2811 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2814 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2816 return 2;
2819 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2821 return 1;
2824 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2825 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2827 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
2829 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2832 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2834 TRACE("()\n");
2836 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2839 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2841 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2843 if(aFlags == (1<<11)) {
2844 *_retval = FALSE;
2845 return NS_OK;
2848 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2851 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2853 TRACE("(%p %p)\n", aURI, _retval);
2855 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2858 static nsresult NSAPI nsNetUtil_NewSimpleNestedURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2860 TRACE("(%p %p)\n", aURI, _retval);
2862 return nsINetUtil_NewSimpleNestedURI(net_util, aURI, _retval);
2865 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2866 PRUint32 aEscapeType, nsACString *_retval)
2868 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
2870 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2873 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2874 nsACString *_retval)
2876 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
2878 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2881 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2882 PRUint32 aFlags, nsACString *_retval)
2884 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
2886 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2889 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2890 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2892 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
2893 aCharsetEnd, _retval);
2895 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2898 static const nsINetUtilVtbl nsNetUtilVtbl = {
2899 nsNetUtil_QueryInterface,
2900 nsNetUtil_AddRef,
2901 nsNetUtil_Release,
2902 nsNetUtil_ParseContentType,
2903 nsNetUtil_ProtocolHasFlags,
2904 nsNetUtil_URIChainHasFlags,
2905 nsNetUtil_ToImmutableURI,
2906 nsNetUtil_NewSimpleNestedURI,
2907 nsNetUtil_EscapeString,
2908 nsNetUtil_EscapeURL,
2909 nsNetUtil_UnescapeString,
2910 nsNetUtil_ExtractCharsetFromContentType
2913 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2915 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2916 void **result)
2918 *result = NULL;
2920 if(IsEqualGUID(&IID_nsISupports, riid))
2921 *result = &nsIOService;
2922 else if(IsEqualGUID(&IID_nsIIOService, riid))
2923 *result = &nsIOService;
2924 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2925 *result = &nsNetUtil;
2927 if(*result) {
2928 nsISupports_AddRef((nsISupports*)*result);
2929 return NS_OK;
2932 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2933 return NS_NOINTERFACE;
2936 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2937 void **result)
2939 *result = NULL;
2941 if(IsEqualGUID(&IID_nsISupports, riid)) {
2942 TRACE("(IID_nsISupports %p)\n", result);
2943 *result = iface;
2944 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2945 TRACE("(IID_nsIFactory %p)\n", result);
2946 *result = iface;
2949 if(*result) {
2950 nsIFactory_AddRef(iface);
2951 return NS_OK;
2954 WARN("(%s %p)\n", debugstr_guid(riid), result);
2955 return NS_NOINTERFACE;
2958 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2960 return 2;
2963 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2965 return 1;
2968 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2969 nsISupports *aOuter, const nsIID *iid, void **result)
2971 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2974 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2976 WARN("(%x)\n", lock);
2977 return NS_OK;
2980 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2981 nsIOServiceFactory_QueryInterface,
2982 nsIOServiceFactory_AddRef,
2983 nsIOServiceFactory_Release,
2984 nsIOServiceFactory_CreateInstance,
2985 nsIOServiceFactory_LockFactory
2988 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2990 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2992 nsIFactory *old_factory = NULL;
2993 nsresult nsres;
2995 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2996 &IID_nsIFactory, (void**)&old_factory);
2997 if(NS_FAILED(nsres)) {
2998 ERR("Could not get factory: %08x\n", nsres);
2999 return;
3002 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
3003 if(NS_FAILED(nsres)) {
3004 ERR("Couldn not create nsIOService instance %08x\n", nsres);
3005 nsIFactory_Release(old_factory);
3006 return;
3009 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
3010 if(NS_FAILED(nsres)) {
3011 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
3012 nsIIOService_Release(nsio);
3013 return;
3016 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
3017 nsIFactory_Release(old_factory);
3018 if(NS_FAILED(nsres))
3019 ERR("UnregisterFactory failed: %08x\n", nsres);
3021 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3022 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3023 if(NS_FAILED(nsres))
3024 ERR("RegisterFactory failed: %08x\n", nsres);
3027 void release_nsio(void)
3029 if(net_util) {
3030 nsINetUtil_Release(net_util);
3031 net_util = NULL;
3034 if(nsio) {
3035 nsIIOService_Release(nsio);
3036 nsio = NULL;