push 1d8ffbc7e5e31cb02d564185c2f7d29830c376df
[wine/hacks.git] / dlls / mshtml / nsio.c
blob63c9a6a3d6a771d96ba4836e335888ce3834ea13
1 /*
2 * Copyright 2006-2007 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 struct nsWineURI {
55 const nsIURLVtbl *lpIURLVtbl;
57 LONG ref;
59 nsIURI *uri;
60 nsIURL *nsurl;
61 NSContainer *container;
62 windowref_t *window_ref;
63 nsChannelBSC *channel_bsc;
64 LPWSTR wine_url;
65 BOOL is_doc_uri;
66 BOOL use_wine_url;
69 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
70 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
72 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
74 static const char *debugstr_nsacstr(const nsACString *nsstr)
76 const char *data;
78 nsACString_GetData(nsstr, &data);
79 return debugstr_a(data);
82 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
84 const WCHAR *ptr = nsuri;
86 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
88 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
89 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
91 if(*ptr || ret_empty) {
92 *ret = SysAllocString(ptr);
93 if(!*ret)
94 return E_OUTOFMEMORY;
95 }else {
96 *ret = NULL;
99 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
100 return S_OK;
103 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
105 IOleCommandTarget *cmdtrg = NULL;
106 HRESULT hres;
108 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
109 if(SUCCEEDED(hres)) {
110 VARIANT varUrl, varRes;
112 V_VT(&varUrl) = VT_BSTR;
113 V_BSTR(&varUrl) = SysAllocString(url);
114 V_VT(&varRes) = VT_BOOL;
116 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
118 IOleCommandTarget_Release(cmdtrg);
119 SysFreeString(V_BSTR(&varUrl));
121 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
122 TRACE("got VARIANT_FALSE, do not load\n");
123 return FALSE;
127 return TRUE;
130 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
132 HTMLDocumentObj *doc = container->doc;
133 DWORD hlnf = 0;
134 BOOL cancel;
135 HRESULT hres;
137 if(!doc) {
138 NSContainer *container_iter = container;
140 hlnf = HLNF_OPENINNEWWINDOW;
141 while(!container_iter->doc)
142 container_iter = container_iter->parent;
143 doc = container_iter->doc;
146 if(!doc->client)
147 return TRUE;
149 if(!hlnf && !exec_shldocvw_67(doc, channel->uri->wine_url))
150 return FALSE;
152 hres = hlink_frame_navigate(&doc->basedoc, channel->uri->wine_url, channel->post_data_stream, hlnf, &cancel);
153 return FAILED(hres) || cancel;
156 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
158 nsIWebNavigation *web_navigation;
159 nsIDocShell *doc_shell;
160 nsresult nsres;
162 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
163 if(NS_FAILED(nsres)) {
164 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
165 return E_FAIL;
168 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
169 nsIWebNavigation_Release(web_navigation);
170 if(NS_FAILED(nsres)) {
171 ERR("Could not get nsIDocShell: %08x\n", nsres);
172 return E_FAIL;
176 uri->channel_bsc = channelbsc;
177 nsres = nsIDocShell_LoadURI(doc_shell, NSURI(uri), NULL, flags, FALSE);
178 uri->channel_bsc = NULL;
179 nsIDocShell_Release(doc_shell);
180 if(NS_FAILED(nsres)) {
181 WARN("LoadURI failed: %08x\n", nsres);
182 return E_FAIL;
185 return S_OK;
188 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
190 OLECHAR *new_url = NULL, *url;
191 BOOL ret = FALSE;
192 HRESULT hres;
194 if(!doc->hostui)
195 return FALSE;
197 url = heap_strdupW(uri->wine_url);
198 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
199 if(hres == S_OK && new_url) {
200 if(strcmpW(url, new_url)) {
201 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
202 ret = TRUE;
204 CoTaskMemFree(new_url);
207 heap_free(url);
208 return ret;
211 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
213 nsWineURI *wine_uri;
214 nsresult nsres;
216 *_retval = FALSE;
218 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
219 if(NS_FAILED(nsres)) {
220 WARN("Could not get nsWineURI: %08x\n", nsres);
221 return NS_ERROR_NOT_IMPLEMENTED;
224 if(!wine_uri->is_doc_uri) {
225 if(!wine_uri->container) {
226 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
227 wine_uri->container = nscontainer;
230 wine_uri->is_doc_uri = TRUE;
231 *_retval = translate_url(nscontainer->doc, wine_uri);
234 nsIURI_Release(NSURI(wine_uri));
235 return NS_OK;
238 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
240 static const WCHAR wszFtp[] = {'f','t','p',':'};
241 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
242 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
244 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
246 if(url) {
247 WCHAR *new_url;
249 new_url = heap_strdupW(url);
250 if(!new_url)
251 return E_OUTOFMEMORY;
252 heap_free(This->wine_url);
253 This->wine_url = new_url;
255 if(This->uri) {
256 /* FIXME: Always use wine url */
257 This->use_wine_url =
258 strncmpW(url, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
259 && strncmpW(url, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
260 && strncmpW(url, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
261 }else {
262 This->use_wine_url = TRUE;
264 }else {
265 heap_free(This->wine_url);
266 This->wine_url = NULL;
267 This->use_wine_url = FALSE;
270 return S_OK;
273 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
275 if(This->container) {
276 if(This->container == nscontainer)
277 return;
278 TRACE("Changing %p -> %p\n", This->container, nscontainer);
279 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
282 if(nscontainer)
283 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
284 This->container = nscontainer;
287 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
289 if(This->window_ref) {
290 if(This->window_ref->window == window)
291 return;
292 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
293 windowref_release(This->window_ref);
296 if(window) {
297 windowref_addref(window->window_ref);
298 This->window_ref = window->window_ref;
300 if(window->doc_obj)
301 set_uri_nscontainer(This, window->doc_obj->nscontainer);
302 }else {
303 This->window_ref = NULL;
307 static inline BOOL is_http_channel(nsChannel *This)
309 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTPS;
312 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
314 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
316 nsChannel *This = NSCHANNEL_THIS(iface);
318 if(IsEqualGUID(&IID_nsISupports, riid)) {
319 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
320 *result = NSCHANNEL(This);
321 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
322 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
323 *result = NSCHANNEL(This);
324 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
325 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
326 *result = NSCHANNEL(This);
327 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
328 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
329 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
330 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
331 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
332 *result = NSUPCHANNEL(This);
333 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
334 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
335 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
336 }else {
337 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
338 *result = NULL;
341 if(*result) {
342 nsIChannel_AddRef(NSCHANNEL(This));
343 return NS_OK;
346 return NS_NOINTERFACE;
349 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
351 nsChannel *This = NSCHANNEL_THIS(iface);
352 nsrefcnt ref = InterlockedIncrement(&This->ref);
354 TRACE("(%p) ref=%d\n", This, ref);
356 return ref;
359 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
361 nsChannel *This = NSCHANNEL_THIS(iface);
362 LONG ref = InterlockedDecrement(&This->ref);
364 if(!ref) {
365 struct ResponseHeader *header, *next_hdr;
367 nsIURI_Release(NSURI(This->uri));
368 if(This->owner)
369 nsISupports_Release(This->owner);
370 if(This->post_data_stream)
371 nsIInputStream_Release(This->post_data_stream);
372 if(This->load_group)
373 nsILoadGroup_Release(This->load_group);
374 if(This->notif_callback)
375 nsIInterfaceRequestor_Release(This->notif_callback);
376 if(This->original_uri)
377 nsIURI_Release(This->original_uri);
378 heap_free(This->content_type);
379 heap_free(This->charset);
381 LIST_FOR_EACH_ENTRY_SAFE(header, next_hdr, &This->response_headers, struct ResponseHeader, entry) {
382 list_remove(&header->entry);
383 heap_free(header->header);
384 heap_free(header->data);
385 heap_free(header);
388 heap_free(This);
391 return ref;
394 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
396 nsChannel *This = NSCHANNEL_THIS(iface);
398 FIXME("(%p)->(%p)\n", This, aName);
400 return NS_ERROR_NOT_IMPLEMENTED;
403 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
405 nsChannel *This = NSCHANNEL_THIS(iface);
407 FIXME("(%p)->(%p)\n", This, _retval);
409 return NS_ERROR_NOT_IMPLEMENTED;
412 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
414 nsChannel *This = NSCHANNEL_THIS(iface);
416 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
418 return *aStatus = NS_OK;
421 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
423 nsChannel *This = NSCHANNEL_THIS(iface);
425 FIXME("(%p)->(%08x)\n", This, aStatus);
427 return NS_ERROR_NOT_IMPLEMENTED;
430 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
432 nsChannel *This = NSCHANNEL_THIS(iface);
434 FIXME("(%p)\n", This);
436 return NS_ERROR_NOT_IMPLEMENTED;
439 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
441 nsChannel *This = NSCHANNEL_THIS(iface);
443 FIXME("(%p)\n", This);
445 return NS_ERROR_NOT_IMPLEMENTED;
448 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
450 nsChannel *This = NSCHANNEL_THIS(iface);
452 TRACE("(%p)->(%p)\n", This, aLoadGroup);
454 if(This->load_group)
455 nsILoadGroup_AddRef(This->load_group);
457 *aLoadGroup = This->load_group;
458 return NS_OK;
461 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
463 nsChannel *This = NSCHANNEL_THIS(iface);
465 TRACE("(%p)->(%p)\n", This, aLoadGroup);
467 if(This->load_group)
468 nsILoadGroup_Release(This->load_group);
469 if(aLoadGroup)
470 nsILoadGroup_AddRef(aLoadGroup);
471 This->load_group = aLoadGroup;
473 return NS_OK;
476 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
478 nsChannel *This = NSCHANNEL_THIS(iface);
480 TRACE("(%p)->(%p)\n", This, aLoadFlags);
482 *aLoadFlags = This->load_flags;
483 return NS_OK;
486 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
488 nsChannel *This = NSCHANNEL_THIS(iface);
490 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
492 This->load_flags = aLoadFlags;
493 return NS_OK;
496 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
498 nsChannel *This = NSCHANNEL_THIS(iface);
500 TRACE("(%p)->(%p)\n", This, aOriginalURI);
502 if(This->original_uri)
503 nsIURI_AddRef(This->original_uri);
505 *aOriginalURI = This->original_uri;
506 return NS_OK;
509 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
511 nsChannel *This = NSCHANNEL_THIS(iface);
513 TRACE("(%p)->(%p)\n", This, aOriginalURI);
515 if(This->original_uri)
516 nsIURI_Release(This->original_uri);
518 nsIURI_AddRef(aOriginalURI);
519 This->original_uri = aOriginalURI;
520 return NS_OK;
523 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
525 nsChannel *This = NSCHANNEL_THIS(iface);
527 TRACE("(%p)->(%p)\n", This, aURI);
529 nsIURI_AddRef(NSURI(This->uri));
530 *aURI = (nsIURI*)This->uri;
532 return NS_OK;
535 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
537 nsChannel *This = NSCHANNEL_THIS(iface);
539 TRACE("(%p)->(%p)\n", This, aOwner);
541 if(This->owner)
542 nsISupports_AddRef(This->owner);
543 *aOwner = This->owner;
545 return NS_OK;
548 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
550 nsChannel *This = NSCHANNEL_THIS(iface);
552 TRACE("(%p)->(%p)\n", This, aOwner);
554 if(aOwner)
555 nsISupports_AddRef(aOwner);
556 if(This->owner)
557 nsISupports_Release(This->owner);
558 This->owner = aOwner;
560 return NS_OK;
563 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
564 nsIInterfaceRequestor **aNotificationCallbacks)
566 nsChannel *This = NSCHANNEL_THIS(iface);
568 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
570 if(This->notif_callback)
571 nsIInterfaceRequestor_AddRef(This->notif_callback);
572 *aNotificationCallbacks = This->notif_callback;
574 return NS_OK;
577 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
578 nsIInterfaceRequestor *aNotificationCallbacks)
580 nsChannel *This = NSCHANNEL_THIS(iface);
582 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
584 if(This->notif_callback)
585 nsIInterfaceRequestor_Release(This->notif_callback);
586 if(aNotificationCallbacks)
587 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
589 This->notif_callback = aNotificationCallbacks;
591 return NS_OK;
594 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
596 nsChannel *This = NSCHANNEL_THIS(iface);
598 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
600 return NS_ERROR_NOT_IMPLEMENTED;
603 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
605 nsChannel *This = NSCHANNEL_THIS(iface);
607 TRACE("(%p)->(%p)\n", This, aContentType);
609 if(This->content_type) {
610 nsACString_SetData(aContentType, This->content_type);
611 return S_OK;
614 WARN("unknown type\n");
615 return NS_ERROR_FAILURE;
618 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
619 const nsACString *aContentType)
621 nsChannel *This = NSCHANNEL_THIS(iface);
622 const char *content_type;
624 TRACE("(%p)->(%p)\n", This, aContentType);
626 nsACString_GetData(aContentType, &content_type);
628 TRACE("content_type %s\n", content_type);
630 heap_free(This->content_type);
631 This->content_type = heap_strdupA(content_type);
633 return NS_OK;
636 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
637 nsACString *aContentCharset)
639 nsChannel *This = NSCHANNEL_THIS(iface);
641 TRACE("(%p)->(%p)\n", This, aContentCharset);
643 if(This->charset) {
644 nsACString_SetData(aContentCharset, This->charset);
645 return NS_OK;
648 nsACString_SetData(aContentCharset, "");
649 return NS_OK;
652 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
653 const nsACString *aContentCharset)
655 nsChannel *This = NSCHANNEL_THIS(iface);
657 FIXME("(%p)->(%p)\n", This, aContentCharset);
659 return NS_ERROR_NOT_IMPLEMENTED;
662 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
664 nsChannel *This = NSCHANNEL_THIS(iface);
666 FIXME("(%p)->(%p)\n", This, aContentLength);
668 return NS_ERROR_NOT_IMPLEMENTED;
671 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
673 nsChannel *This = NSCHANNEL_THIS(iface);
675 FIXME("(%p)->(%d)\n", This, aContentLength);
677 return NS_ERROR_NOT_IMPLEMENTED;
680 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
682 nsChannel *This = NSCHANNEL_THIS(iface);
684 FIXME("(%p)->(%p)\n", This, _retval);
686 return NS_ERROR_NOT_IMPLEMENTED;
689 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
691 nsWineURI *wine_uri;
692 nsresult nsres;
693 HRESULT hres;
695 if(!channel->original_uri) {
696 ERR("original_uri == NULL\n");
697 return E_FAIL;
700 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsWineURI, (void**)&wine_uri);
701 if(NS_FAILED(nsres)) {
702 ERR("Could not get nsWineURI: %08x\n", nsres);
703 return E_FAIL;
706 if(wine_uri->wine_url) {
707 hres = CreateURLMoniker(NULL, wine_uri->wine_url, mon);
708 if(FAILED(hres))
709 WARN("CreateURLMoniker failed: %08x\n", hres);
710 }else {
711 TRACE("wine_url == NULL\n");
712 hres = E_FAIL;
715 nsIURI_Release(NSURI(wine_uri));
717 return hres;
720 static HTMLWindow *get_window_from_load_group(nsChannel *This)
722 HTMLWindow *window;
723 nsIChannel *channel;
724 nsIRequest *req;
725 nsWineURI *wine_uri;
726 nsIURI *uri;
727 nsresult nsres;
729 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
730 if(NS_FAILED(nsres)) {
731 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
732 return NULL;
735 if(!req)
736 return NULL;
738 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
739 nsIRequest_Release(req);
740 if(NS_FAILED(nsres)) {
741 WARN("Could not get nsIChannel interface: %08x\n", nsres);
742 return NULL;
745 nsres = nsIChannel_GetURI(channel, &uri);
746 nsIChannel_Release(channel);
747 if(NS_FAILED(nsres)) {
748 ERR("GetURI failed: %08x\n", nsres);
749 return NULL;
752 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
753 nsIURI_Release(uri);
754 if(NS_FAILED(nsres)) {
755 TRACE("Could not get nsWineURI: %08x\n", nsres);
756 return NULL;
759 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
760 if(window)
761 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
762 nsIURI_Release(NSURI(wine_uri));
764 return window;
767 static HTMLWindow *get_channel_window(nsChannel *This)
769 nsIRequestObserver *req_observer;
770 nsIWebProgress *web_progress;
771 nsIDOMWindow *nswindow;
772 HTMLWindow *window;
773 nsresult nsres;
775 if(!This->load_group) {
776 ERR("NULL load_group\n");
777 return NULL;
780 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
781 if(NS_FAILED(nsres) || !req_observer) {
782 ERR("GetGroupObserver failed: %08x\n", nsres);
783 return NULL;
786 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
787 nsIRequestObserver_Release(req_observer);
788 if(NS_FAILED(nsres)) {
789 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
790 return NULL;
793 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
794 nsIWebProgress_Release(web_progress);
795 if(NS_FAILED(nsres) || !nswindow) {
796 ERR("GetDOMWindow failed: %08x\n", nsres);
797 return NULL;
800 window = nswindow_to_window(nswindow);
801 nsIDOMWindow_Release(nswindow);
803 if(window)
804 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
805 else
806 FIXME("NULL window for %p\n", nswindow);
807 return window;
810 typedef struct {
811 task_t header;
812 HTMLDocumentNode *doc;
813 nsChannelBSC *bscallback;
814 } start_binding_task_t;
816 static void start_binding_proc(task_t *_task)
818 start_binding_task_t *task = (start_binding_task_t*)_task;
820 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
822 IUnknown_Release((IUnknown*)task->bscallback);
825 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
826 nsISupports *context)
828 nsChannelBSC *bscallback;
829 IMoniker *mon = NULL;
830 HRESULT hres;
832 hres = create_mon_for_nschannel(This, &mon);
833 if(FAILED(hres))
834 return NS_ERROR_UNEXPECTED;
836 if(is_doc_channel)
837 set_current_mon(window, mon);
839 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
840 IMoniker_Release(mon);
841 if(FAILED(hres))
842 return NS_ERROR_UNEXPECTED;
844 channelbsc_set_channel(bscallback, This, listener, context);
846 if(is_doc_channel) {
847 set_window_bscallback(window, bscallback);
848 async_start_doc_binding(window, bscallback);
849 IUnknown_Release((IUnknown*)bscallback);
850 }else {
851 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
853 task->doc = window->doc;
854 task->bscallback = bscallback;
855 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
858 return NS_OK;
861 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
862 nsISupports *aContext)
864 nsChannel *This = NSCHANNEL_THIS(iface);
865 HTMLWindow *window = NULL;
866 BOOL open = TRUE;
867 nsresult nsres = NS_OK;
869 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
871 if(This->uri->is_doc_uri) {
872 window = get_channel_window(This);
873 if(window) {
874 set_uri_window(This->uri, window);
875 }else if(This->uri->container) {
876 BOOL b;
878 /* nscontainer->doc should be NULL which means navigation to a new window */
879 if(This->uri->container->doc)
880 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
882 b = before_async_open(This, This->uri->container);
883 if(b)
884 FIXME("Navigation not cancelled\n");
885 return NS_ERROR_UNEXPECTED;
889 if(!window) {
890 if(This->uri->window_ref && This->uri->window_ref->window) {
891 window = This->uri->window_ref->window;
892 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
893 }else if(This->load_group) {
894 window = get_window_from_load_group(This);
895 if(window)
896 set_uri_window(This->uri, window);
900 if(!window) {
901 ERR("window = NULL\n");
902 return NS_ERROR_UNEXPECTED;
905 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
906 if(This->uri->channel_bsc) {
907 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
909 if(window->doc_obj->mime) {
910 heap_free(This->content_type);
911 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
914 open = FALSE;
915 }else {
916 open = !before_async_open(This, window->doc_obj->nscontainer);
917 if(!open) {
918 TRACE("canceled\n");
919 nsres = NS_ERROR_UNEXPECTED;
924 if(open)
925 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
927 IHTMLWindow2_Release(HTMLWINDOW2(window));
928 return nsres;
931 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
933 nsChannel *This = NSCHANNEL_THIS(iface);
935 FIXME("(%p)->(%p)\n", This, aRequestMethod);
937 return NS_ERROR_NOT_IMPLEMENTED;
940 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
941 const nsACString *aRequestMethod)
943 nsChannel *This = NSCHANNEL_THIS(iface);
945 TRACE("(%p)->(%p): Returning NS_OK\n", This, aRequestMethod);
947 return NS_OK;
950 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
952 nsChannel *This = NSCHANNEL_THIS(iface);
954 FIXME("(%p)->(%p)\n", This, aReferrer);
956 return NS_ERROR_NOT_IMPLEMENTED;
959 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
961 nsChannel *This = NSCHANNEL_THIS(iface);
963 FIXME("(%p)->(%p)\n", This, aReferrer);
965 return NS_OK;
968 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
969 const nsACString *aHeader, nsACString *_retval)
971 nsChannel *This = NSCHANNEL_THIS(iface);
973 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
975 return NS_ERROR_NOT_IMPLEMENTED;
978 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
979 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
981 nsChannel *This = NSCHANNEL_THIS(iface);
983 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
985 return NS_OK;
988 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
989 nsIHttpHeaderVisitor *aVisitor)
991 nsChannel *This = NSCHANNEL_THIS(iface);
993 FIXME("(%p)->(%p)\n", This, aVisitor);
995 return NS_ERROR_NOT_IMPLEMENTED;
998 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1000 nsChannel *This = NSCHANNEL_THIS(iface);
1002 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1004 return NS_ERROR_NOT_IMPLEMENTED;
1007 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1009 nsChannel *This = NSCHANNEL_THIS(iface);
1011 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1013 return NS_ERROR_NOT_IMPLEMENTED;
1016 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1018 nsChannel *This = NSCHANNEL_THIS(iface);
1020 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1022 return NS_ERROR_NOT_IMPLEMENTED;
1025 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1027 nsChannel *This = NSCHANNEL_THIS(iface);
1029 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1031 return NS_ERROR_NOT_IMPLEMENTED;
1034 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1036 nsChannel *This = NSCHANNEL_THIS(iface);
1038 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1040 if(This->response_status) {
1041 *aResponseStatus = This->response_status;
1042 return NS_OK;
1045 WARN("No response status\n");
1046 return NS_ERROR_UNEXPECTED;
1049 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1050 nsACString *aResponseStatusText)
1052 nsChannel *This = NSCHANNEL_THIS(iface);
1054 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1056 return NS_ERROR_NOT_IMPLEMENTED;
1059 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1060 PRBool *aRequestSucceeded)
1062 nsChannel *This = NSCHANNEL_THIS(iface);
1064 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1066 if(!This->response_status)
1067 return NS_ERROR_NOT_AVAILABLE;
1069 *aRequestSucceeded = This->response_status/100 == 2;
1071 return NS_OK;
1074 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1075 const nsACString *header, nsACString *_retval)
1077 nsChannel *This = NSCHANNEL_THIS(iface);
1078 const char *header_str;
1079 WCHAR *header_wstr;
1080 struct ResponseHeader *this_header;
1082 nsACString_GetData(header, &header_str);
1083 TRACE("(%p)->(%p(%s) %p)\n", This, header, header_str, _retval);
1085 header_wstr = heap_strdupAtoW(header_str);
1086 if(!header_wstr)
1087 return NS_ERROR_UNEXPECTED;
1089 LIST_FOR_EACH_ENTRY(this_header, &This->response_headers, struct ResponseHeader, entry) {
1090 if(!strcmpW(this_header->header, header_wstr)) {
1091 char *data = heap_strdupWtoA(this_header->data);
1092 if(!data) {
1093 heap_free(header_wstr);
1094 return NS_ERROR_UNEXPECTED;
1096 nsACString_SetData(_retval, data);
1097 heap_free(data);
1098 heap_free(header_wstr);
1099 return NS_OK;
1103 heap_free(header_wstr);
1105 return NS_ERROR_NOT_AVAILABLE;
1108 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1109 const nsACString *header, const nsACString *value, PRBool merge)
1111 nsChannel *This = NSCHANNEL_THIS(iface);
1113 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
1115 return NS_ERROR_NOT_IMPLEMENTED;
1118 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1119 nsIHttpHeaderVisitor *aVisitor)
1121 nsChannel *This = NSCHANNEL_THIS(iface);
1123 FIXME("(%p)->(%p)\n", This, aVisitor);
1125 return NS_ERROR_NOT_IMPLEMENTED;
1128 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1130 nsChannel *This = NSCHANNEL_THIS(iface);
1132 FIXME("(%p)->(%p)\n", This, _retval);
1134 return NS_ERROR_NOT_IMPLEMENTED;
1137 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1139 nsChannel *This = NSCHANNEL_THIS(iface);
1141 FIXME("(%p)->(%p)\n", This, _retval);
1143 return NS_ERROR_NOT_IMPLEMENTED;
1146 #undef NSCHANNEL_THIS
1148 static const nsIHttpChannelVtbl nsChannelVtbl = {
1149 nsChannel_QueryInterface,
1150 nsChannel_AddRef,
1151 nsChannel_Release,
1152 nsChannel_GetName,
1153 nsChannel_IsPending,
1154 nsChannel_GetStatus,
1155 nsChannel_Cancel,
1156 nsChannel_Suspend,
1157 nsChannel_Resume,
1158 nsChannel_GetLoadGroup,
1159 nsChannel_SetLoadGroup,
1160 nsChannel_GetLoadFlags,
1161 nsChannel_SetLoadFlags,
1162 nsChannel_GetOriginalURI,
1163 nsChannel_SetOriginalURI,
1164 nsChannel_GetURI,
1165 nsChannel_GetOwner,
1166 nsChannel_SetOwner,
1167 nsChannel_GetNotificationCallbacks,
1168 nsChannel_SetNotificationCallbacks,
1169 nsChannel_GetSecurityInfo,
1170 nsChannel_GetContentType,
1171 nsChannel_SetContentType,
1172 nsChannel_GetContentCharset,
1173 nsChannel_SetContentCharset,
1174 nsChannel_GetContentLength,
1175 nsChannel_SetContentLength,
1176 nsChannel_Open,
1177 nsChannel_AsyncOpen,
1178 nsChannel_GetRequestMethod,
1179 nsChannel_SetRequestMethod,
1180 nsChannel_GetReferrer,
1181 nsChannel_SetReferrer,
1182 nsChannel_GetRequestHeader,
1183 nsChannel_SetRequestHeader,
1184 nsChannel_VisitRequestHeaders,
1185 nsChannel_GetAllowPipelining,
1186 nsChannel_SetAllowPipelining,
1187 nsChannel_GetRedirectionLimit,
1188 nsChannel_SetRedirectionLimit,
1189 nsChannel_GetResponseStatus,
1190 nsChannel_GetResponseStatusText,
1191 nsChannel_GetRequestSucceeded,
1192 nsChannel_GetResponseHeader,
1193 nsChannel_SetResponseHeader,
1194 nsChannel_VisitResponseHeaders,
1195 nsChannel_IsNoStoreResponse,
1196 nsChannel_IsNoCacheResponse
1199 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1201 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1202 nsQIResult result)
1204 nsChannel *This = NSUPCHANNEL_THIS(iface);
1205 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1208 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1210 nsChannel *This = NSUPCHANNEL_THIS(iface);
1211 return nsIChannel_AddRef(NSCHANNEL(This));
1214 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1216 nsChannel *This = NSUPCHANNEL_THIS(iface);
1217 return nsIChannel_Release(NSCHANNEL(This));
1220 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1221 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1223 nsChannel *This = NSUPCHANNEL_THIS(iface);
1224 const char *content_type;
1226 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1228 if(This->post_data_stream)
1229 nsIInputStream_Release(This->post_data_stream);
1231 if(aContentType) {
1232 nsACString_GetData(aContentType, &content_type);
1233 if(*content_type)
1234 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1237 if(aContentLength != -1)
1238 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1240 if(This->post_data_stream)
1241 nsIInputStream_Release(This->post_data_stream);
1242 This->post_data_stream = aStream;
1243 if(aStream)
1244 nsIInputStream_AddRef(aStream);
1246 return NS_OK;
1249 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1250 nsIInputStream **aUploadStream)
1252 nsChannel *This = NSUPCHANNEL_THIS(iface);
1254 TRACE("(%p)->(%p)\n", This, aUploadStream);
1256 if(This->post_data_stream)
1257 nsIInputStream_AddRef(This->post_data_stream);
1259 *aUploadStream = This->post_data_stream;
1260 return NS_OK;
1263 #undef NSUPCHANNEL_THIS
1265 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1266 nsUploadChannel_QueryInterface,
1267 nsUploadChannel_AddRef,
1268 nsUploadChannel_Release,
1269 nsUploadChannel_SetUploadStream,
1270 nsUploadChannel_GetUploadStream
1273 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1275 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1276 nsQIResult result)
1278 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1279 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1282 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1284 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1285 return nsIChannel_AddRef(NSCHANNEL(This));
1288 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1290 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1291 return nsIChannel_Release(NSCHANNEL(This));
1294 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1296 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1298 FIXME("(%p)->()\n", This);
1300 return NS_ERROR_NOT_IMPLEMENTED;
1303 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1305 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1307 FIXME("(%p)->()\n", This);
1309 return NS_ERROR_NOT_IMPLEMENTED;
1312 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1314 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1316 FIXME("(%p)->()\n", This);
1318 return NS_ERROR_NOT_IMPLEMENTED;
1321 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1323 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1325 FIXME("(%p)->()\n", This);
1327 return NS_ERROR_NOT_IMPLEMENTED;
1330 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1332 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1334 FIXME("(%p)->()\n", This);
1336 return NS_ERROR_NOT_IMPLEMENTED;
1339 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1341 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1343 FIXME("(%p)->()\n", This);
1345 return NS_ERROR_NOT_IMPLEMENTED;
1348 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1350 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1352 FIXME("(%p)->()\n", This);
1354 return NS_ERROR_NOT_IMPLEMENTED;
1357 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1359 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1361 FIXME("(%p)->()\n", This);
1363 return NS_ERROR_NOT_IMPLEMENTED;
1366 #undef NSHTTPINTERNAL_THIS
1368 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1369 nsHttpChannelInternal_QueryInterface,
1370 nsHttpChannelInternal_AddRef,
1371 nsHttpChannelInternal_Release,
1372 nsHttpChannelInternal_GetDocumentURI,
1373 nsHttpChannelInternal_SetDocumentURI,
1374 nsHttpChannelInternal_GetRequestVersion,
1375 nsHttpChannelInternal_GetResponseVersion,
1376 nsHttpChannelInternal_SetCookie,
1377 nsHttpChannelInternal_SetupFallbackChannel,
1378 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1379 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1382 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1384 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, nsQIResult result)
1386 nsWineURI *This = NSURI_THIS(iface);
1388 *result = NULL;
1390 if(IsEqualGUID(&IID_nsISupports, riid)) {
1391 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1392 *result = NSURI(This);
1393 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1394 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1395 *result = NSURI(This);
1396 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1397 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1398 *result = NSURL(This);
1399 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1400 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1401 *result = This;
1404 if(*result) {
1405 nsIURI_AddRef(NSURI(This));
1406 return NS_OK;
1409 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1410 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1413 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1415 nsWineURI *This = NSURI_THIS(iface);
1416 LONG ref = InterlockedIncrement(&This->ref);
1418 TRACE("(%p) ref=%d\n", This, ref);
1420 return ref;
1423 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1425 nsWineURI *This = NSURI_THIS(iface);
1426 LONG ref = InterlockedDecrement(&This->ref);
1428 TRACE("(%p) ref=%d\n", This, ref);
1430 if(!ref) {
1431 if(This->window_ref)
1432 windowref_release(This->window_ref);
1433 if(This->container)
1434 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1435 if(This->nsurl)
1436 nsIURL_Release(This->nsurl);
1437 if(This->uri)
1438 nsIURI_Release(This->uri);
1439 heap_free(This->wine_url);
1440 heap_free(This);
1443 return ref;
1446 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1448 nsWineURI *This = NSURI_THIS(iface);
1450 TRACE("(%p)->(%p)\n", This, aSpec);
1452 if(This->use_wine_url) {
1453 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1454 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1455 nsACString_SetData(aSpec, speca);
1457 return NS_OK;
1460 if(This->uri)
1461 return nsIURI_GetSpec(This->uri, aSpec);
1463 TRACE("returning error\n");
1464 return NS_ERROR_NOT_IMPLEMENTED;
1468 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1470 nsWineURI *This = NSURI_THIS(iface);
1472 TRACE("(%p)->(%p)\n", This, aSpec);
1474 if(This->uri)
1475 return nsIURI_SetSpec(This->uri, aSpec);
1477 FIXME("default action not implemented\n");
1478 return NS_ERROR_NOT_IMPLEMENTED;
1481 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1483 nsWineURI *This = NSURI_THIS(iface);
1485 TRACE("(%p)->(%p)\n", This, aPrePath);
1487 if(This->uri)
1488 return nsIURI_GetPrePath(This->uri, aPrePath);
1490 FIXME("default action not implemented\n");
1491 return NS_ERROR_NOT_IMPLEMENTED;
1494 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1496 nsWineURI *This = NSURI_THIS(iface);
1498 TRACE("(%p)->(%p)\n", This, aScheme);
1500 if(This->use_wine_url) {
1502 * For Gecko we set scheme to unknown so it won't be handled
1503 * as any special case.
1505 nsACString_SetData(aScheme, "wine");
1506 return NS_OK;
1509 if(This->uri)
1510 return nsIURI_GetScheme(This->uri, aScheme);
1512 TRACE("returning error\n");
1513 return NS_ERROR_NOT_IMPLEMENTED;
1516 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1518 nsWineURI *This = NSURI_THIS(iface);
1520 TRACE("(%p)->(%p)\n", This, aScheme);
1522 if(This->uri)
1523 return nsIURI_SetScheme(This->uri, aScheme);
1525 FIXME("default action not implemented\n");
1526 return NS_ERROR_NOT_IMPLEMENTED;
1529 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1531 nsWineURI *This = NSURI_THIS(iface);
1533 TRACE("(%p)->(%p)\n", This, aUserPass);
1535 if(This->uri)
1536 return nsIURI_GetUserPass(This->uri, aUserPass);
1538 FIXME("default action not implemented\n");
1539 return NS_ERROR_NOT_IMPLEMENTED;
1542 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1544 nsWineURI *This = NSURI_THIS(iface);
1546 TRACE("(%p)->(%p)\n", This, aUserPass);
1548 if(This->uri)
1549 return nsIURI_SetUserPass(This->uri, aUserPass);
1551 FIXME("default action not implemented\n");
1552 return NS_ERROR_NOT_IMPLEMENTED;
1555 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1557 nsWineURI *This = NSURI_THIS(iface);
1559 TRACE("(%p)->(%p)\n", This, aUsername);
1561 if(This->uri)
1562 return nsIURI_GetUsername(This->uri, aUsername);
1564 FIXME("default action not implemented\n");
1565 return NS_ERROR_NOT_IMPLEMENTED;
1568 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1570 nsWineURI *This = NSURI_THIS(iface);
1572 TRACE("(%p)->(%p)\n", This, aUsername);
1574 if(This->uri)
1575 return nsIURI_SetUsername(This->uri, aUsername);
1577 FIXME("default action not implemented\n");
1578 return NS_ERROR_NOT_IMPLEMENTED;
1581 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1583 nsWineURI *This = NSURI_THIS(iface);
1585 TRACE("(%p)->(%p)\n", This, aPassword);
1587 if(This->uri)
1588 return nsIURI_GetPassword(This->uri, aPassword);
1590 FIXME("default action not implemented\n");
1591 return NS_ERROR_NOT_IMPLEMENTED;
1594 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1596 nsWineURI *This = NSURI_THIS(iface);
1598 TRACE("(%p)->(%p)\n", This, aPassword);
1600 if(This->uri)
1601 return nsIURI_SetPassword(This->uri, aPassword);
1603 FIXME("default action not implemented\n");
1604 return NS_ERROR_NOT_IMPLEMENTED;
1607 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1609 nsWineURI *This = NSURI_THIS(iface);
1611 TRACE("(%p)->(%p)\n", This, aHostPort);
1613 if(This->uri)
1614 return nsIURI_GetHostPort(This->uri, aHostPort);
1616 FIXME("default action not implemented\n");
1617 return NS_ERROR_NOT_IMPLEMENTED;
1620 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1622 nsWineURI *This = NSURI_THIS(iface);
1624 TRACE("(%p)->(%p)\n", This, aHostPort);
1626 if(This->uri)
1627 return nsIURI_SetHostPort(This->uri, aHostPort);
1629 FIXME("default action not implemented\n");
1630 return NS_ERROR_NOT_IMPLEMENTED;
1633 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1635 nsWineURI *This = NSURI_THIS(iface);
1637 TRACE("(%p)->(%p)\n", This, aHost);
1639 if(This->uri)
1640 return nsIURI_GetHost(This->uri, aHost);
1642 FIXME("default action not implemented\n");
1643 return NS_ERROR_NOT_IMPLEMENTED;
1646 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1648 nsWineURI *This = NSURI_THIS(iface);
1650 TRACE("(%p)->(%p)\n", This, aHost);
1652 if(This->uri)
1653 return nsIURI_SetHost(This->uri, aHost);
1655 FIXME("default action not implemented\n");
1656 return NS_ERROR_NOT_IMPLEMENTED;
1659 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1661 nsWineURI *This = NSURI_THIS(iface);
1663 TRACE("(%p)->(%p)\n", This, aPort);
1665 if(This->uri)
1666 return nsIURI_GetPort(This->uri, aPort);
1668 FIXME("default action not implemented\n");
1669 return NS_ERROR_NOT_IMPLEMENTED;
1672 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1674 nsWineURI *This = NSURI_THIS(iface);
1676 TRACE("(%p)->(%d)\n", This, aPort);
1678 if(This->uri)
1679 return nsIURI_SetPort(This->uri, aPort);
1681 FIXME("default action not implemented\n");
1682 return NS_ERROR_NOT_IMPLEMENTED;
1685 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
1687 nsWineURI *This = NSURI_THIS(iface);
1689 TRACE("(%p)->(%p)\n", This, aPath);
1691 if(This->uri)
1692 return nsIURI_GetPath(This->uri, aPath);
1694 FIXME("default action not implemented\n");
1695 return NS_ERROR_NOT_IMPLEMENTED;
1698 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
1700 nsWineURI *This = NSURI_THIS(iface);
1701 const char *path;
1703 nsACString_GetData(aPath, &path);
1704 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1707 if(This->wine_url) {
1708 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1709 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1710 LPWSTR pathw;
1711 HRESULT hres;
1713 pathw = heap_strdupAtoW(path);
1714 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1715 heap_free(pathw);
1716 if(SUCCEEDED(hres))
1717 set_wine_url(This, new_url);
1718 else
1719 WARN("UrlCombine failed: %08x\n", hres);
1722 if(!This->uri)
1723 return NS_OK;
1725 return nsIURI_SetPath(This->uri, aPath);
1728 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
1730 nsWineURI *This = NSURI_THIS(iface);
1731 nsWineURI *wine_uri;
1732 nsresult nsres;
1734 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1736 if(This->uri)
1737 return nsIURI_Equals(This->uri, other, _retval);
1739 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&wine_uri);
1740 if(NS_FAILED(nsres)) {
1741 TRACE("Could not get nsWineURI interface\n");
1742 *_retval = FALSE;
1743 return NS_OK;
1746 *_retval = wine_uri->wine_url && !UrlCompareW(This->wine_url, wine_uri->wine_url, TRUE);
1747 nsIURI_Release(NSURI(wine_uri));
1749 return NS_OK;
1752 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
1754 nsWineURI *This = NSURI_THIS(iface);
1756 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1758 if(This->use_wine_url) {
1759 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1760 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1762 *_retval = lstrlenW(This->wine_url) > len
1763 && This->wine_url[len] == ':'
1764 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1765 return NS_OK;
1768 if(This->uri)
1769 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1771 TRACE("returning error\n");
1772 return NS_ERROR_NOT_IMPLEMENTED;
1775 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
1777 nsWineURI *This = NSURI_THIS(iface);
1778 nsIURI *nsuri = NULL;
1779 nsWineURI *wine_uri;
1780 nsresult nsres;
1782 TRACE("(%p)->(%p)\n", This, _retval);
1784 if(This->uri) {
1785 nsres = nsIURI_Clone(This->uri, &nsuri);
1786 if(NS_FAILED(nsres)) {
1787 WARN("Clone failed: %08x\n", nsres);
1788 return nsres;
1792 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1793 if(NS_FAILED(nsres)) {
1794 WARN("create_uri failed: %08x\n", nsres);
1795 return nsres;
1798 set_wine_url(wine_uri, This->wine_url);
1800 *_retval = NSURI(wine_uri);
1801 return NS_OK;
1804 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *arelativePath,
1805 nsACString *_retval)
1807 nsWineURI *This = NSURI_THIS(iface);
1809 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1811 if(This->uri)
1812 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1814 FIXME("default action not implemented\n");
1815 return NS_ERROR_NOT_IMPLEMENTED;
1818 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
1820 nsWineURI *This = NSURI_THIS(iface);
1822 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1824 if(This->use_wine_url)
1825 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1827 if(This->uri)
1828 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1830 TRACE("returning error\n");
1831 return NS_ERROR_NOT_IMPLEMENTED;
1834 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
1836 nsWineURI *This = NSURI_THIS(iface);
1838 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1840 if(This->uri)
1841 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1843 FIXME("default action not implemented\n");
1844 return NS_ERROR_NOT_IMPLEMENTED;
1847 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
1849 nsWineURI *This = NSURI_THIS(iface);
1851 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1853 if(This->uri)
1854 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1856 FIXME("default action not implemented\n");
1857 return NS_ERROR_NOT_IMPLEMENTED;
1860 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
1862 nsWineURI *This = NSURI_THIS(iface);
1864 TRACE("(%p)->(%p)\n", This, aFilePath);
1866 if(This->nsurl)
1867 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1869 FIXME("default action not implemented\n");
1870 return NS_ERROR_NOT_IMPLEMENTED;
1873 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
1875 nsWineURI *This = NSURI_THIS(iface);
1877 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1879 if(This->nsurl)
1880 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1882 FIXME("default action not implemented\n");
1883 return NS_ERROR_NOT_IMPLEMENTED;
1886 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
1888 nsWineURI *This = NSURI_THIS(iface);
1890 TRACE("(%p)->(%p)\n", This, aParam);
1892 if(This->nsurl)
1893 return nsIURL_GetParam(This->nsurl, aParam);
1895 FIXME("default action not implemented\n");
1896 return NS_ERROR_NOT_IMPLEMENTED;
1899 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
1901 nsWineURI *This = NSURI_THIS(iface);
1903 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1905 if(This->nsurl)
1906 return nsIURL_SetParam(This->nsurl, aParam);
1908 FIXME("default action not implemented\n");
1909 return NS_ERROR_NOT_IMPLEMENTED;
1912 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
1914 nsWineURI *This = NSURI_THIS(iface);
1916 TRACE("(%p)->(%p)\n", This, aQuery);
1918 if(This->nsurl)
1919 return nsIURL_GetQuery(This->nsurl, aQuery);
1921 FIXME("default action not implemented\n");
1922 return NS_ERROR_NOT_IMPLEMENTED;
1925 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
1927 nsWineURI *This = NSURI_THIS(iface);
1928 const WCHAR *ptr1, *ptr2;
1929 const char *query;
1930 WCHAR *new_url, *ptr;
1931 DWORD len, size;
1933 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1935 if(This->nsurl)
1936 nsIURL_SetQuery(This->nsurl, aQuery);
1938 if(!This->wine_url)
1939 return NS_OK;
1941 nsACString_GetData(aQuery, &query);
1942 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1943 ptr1 = strchrW(This->wine_url, '?');
1944 if(ptr1) {
1945 size += ptr1-This->wine_url;
1946 ptr2 = strchrW(ptr1, '#');
1947 if(ptr2)
1948 size += strlenW(ptr2);
1949 }else {
1950 ptr1 = This->wine_url + strlenW(This->wine_url);
1951 ptr2 = NULL;
1952 size += strlenW(This->wine_url);
1955 if(*query)
1956 size++;
1958 new_url = heap_alloc(size*sizeof(WCHAR));
1959 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1960 ptr = new_url + (ptr1-This->wine_url);
1961 if(*query) {
1962 *ptr++ = '?';
1963 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1964 ptr += len-1;
1966 if(ptr2)
1967 strcpyW(ptr, ptr2);
1968 else
1969 *ptr = 0;
1971 TRACE("setting %s\n", debugstr_w(new_url));
1973 heap_free(This->wine_url);
1974 This->wine_url = new_url;
1975 return NS_OK;
1978 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
1980 nsWineURI *This = NSURI_THIS(iface);
1982 TRACE("(%p)->(%p)\n", This, aRef);
1984 if(This->nsurl)
1985 return nsIURL_GetRef(This->nsurl, aRef);
1987 FIXME("default action not implemented\n");
1988 return NS_ERROR_NOT_IMPLEMENTED;
1991 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
1993 nsWineURI *This = NSURI_THIS(iface);
1994 const char *refa;
1996 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1998 if(This->nsurl)
1999 return nsIURL_SetRef(This->nsurl, aRef);
2001 nsACString_GetData(aRef, &refa);
2002 if(!*refa)
2003 return NS_OK;
2005 FIXME("default action not implemented\n");
2006 return NS_ERROR_NOT_IMPLEMENTED;
2009 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
2011 nsWineURI *This = NSURI_THIS(iface);
2013 TRACE("(%p)->(%p)\n", This, aDirectory);
2015 if(This->nsurl)
2016 return nsIURL_GetDirectory(This->nsurl, aDirectory);
2018 FIXME("default action not implemented\n");
2019 return NS_ERROR_NOT_IMPLEMENTED;
2022 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2024 nsWineURI *This = NSURI_THIS(iface);
2026 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2028 if(This->nsurl)
2029 return nsIURL_SetDirectory(This->nsurl, aDirectory);
2031 FIXME("default action not implemented\n");
2032 return NS_ERROR_NOT_IMPLEMENTED;
2035 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2037 nsWineURI *This = NSURI_THIS(iface);
2039 TRACE("(%p)->(%p)\n", This, aFileName);
2041 if(This->nsurl)
2042 return nsIURL_GetFileName(This->nsurl, aFileName);
2044 FIXME("default action not implemented\n");
2045 return NS_ERROR_NOT_IMPLEMENTED;
2048 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2050 nsWineURI *This = NSURI_THIS(iface);
2052 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2054 if(This->nsurl)
2055 return nsIURL_SetFileName(This->nsurl, aFileName);
2057 FIXME("default action not implemented\n");
2058 return NS_ERROR_NOT_IMPLEMENTED;
2061 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2063 nsWineURI *This = NSURI_THIS(iface);
2065 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2067 if(This->nsurl)
2068 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2070 FIXME("default action not implemented\n");
2071 return NS_ERROR_NOT_IMPLEMENTED;
2074 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2076 nsWineURI *This = NSURI_THIS(iface);
2078 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2080 if(This->nsurl)
2081 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2083 FIXME("default action not implemented\n");
2084 return NS_ERROR_NOT_IMPLEMENTED;
2087 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2089 nsWineURI *This = NSURI_THIS(iface);
2091 TRACE("(%p)->(%p)\n", This, aFileExtension);
2093 if(This->nsurl)
2094 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2096 FIXME("default action not implemented\n");
2097 return NS_ERROR_NOT_IMPLEMENTED;
2100 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2102 nsWineURI *This = NSURI_THIS(iface);
2104 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2106 if(This->nsurl)
2107 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2109 FIXME("default action not implemented\n");
2110 return NS_ERROR_NOT_IMPLEMENTED;
2113 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2115 nsWineURI *This = NSURI_THIS(iface);
2117 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2119 if(This->nsurl)
2120 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2122 FIXME("default action not implemented\n");
2123 return NS_ERROR_NOT_IMPLEMENTED;
2126 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2128 nsWineURI *This = NSURI_THIS(iface);
2130 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2132 if(This->nsurl)
2133 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2135 FIXME("default action not implemented\n");
2136 return NS_ERROR_NOT_IMPLEMENTED;
2139 #undef NSURI_THIS
2141 static const nsIURLVtbl nsURLVtbl = {
2142 nsURI_QueryInterface,
2143 nsURI_AddRef,
2144 nsURI_Release,
2145 nsURI_GetSpec,
2146 nsURI_SetSpec,
2147 nsURI_GetPrePath,
2148 nsURI_GetScheme,
2149 nsURI_SetScheme,
2150 nsURI_GetUserPass,
2151 nsURI_SetUserPass,
2152 nsURI_GetUsername,
2153 nsURI_SetUsername,
2154 nsURI_GetPassword,
2155 nsURI_SetPassword,
2156 nsURI_GetHostPort,
2157 nsURI_SetHostPort,
2158 nsURI_GetHost,
2159 nsURI_SetHost,
2160 nsURI_GetPort,
2161 nsURI_SetPort,
2162 nsURI_GetPath,
2163 nsURI_SetPath,
2164 nsURI_Equals,
2165 nsURI_SchemeIs,
2166 nsURI_Clone,
2167 nsURI_Resolve,
2168 nsURI_GetAsciiSpec,
2169 nsURI_GetAsciiHost,
2170 nsURI_GetOriginCharset,
2171 nsURL_GetFilePath,
2172 nsURL_SetFilePath,
2173 nsURL_GetParam,
2174 nsURL_SetParam,
2175 nsURL_GetQuery,
2176 nsURL_SetQuery,
2177 nsURL_GetRef,
2178 nsURL_SetRef,
2179 nsURL_GetDirectory,
2180 nsURL_SetDirectory,
2181 nsURL_GetFileName,
2182 nsURL_SetFileName,
2183 nsURL_GetFileBaseName,
2184 nsURL_SetFileBaseName,
2185 nsURL_GetFileExtension,
2186 nsURL_SetFileExtension,
2187 nsURL_GetCommonBaseSpec,
2188 nsURL_GetRelativeSpec
2191 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2193 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2195 ret->lpIURLVtbl = &nsURLVtbl;
2196 ret->ref = 1;
2197 ret->uri = uri;
2199 set_uri_nscontainer(ret, container);
2200 set_uri_window(ret, window);
2202 if(uri)
2203 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2205 TRACE("retval=%p\n", ret);
2206 *_retval = ret;
2207 return NS_OK;
2210 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2212 nsWineURI *uri;
2213 nsresult nsres;
2215 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2216 if(NS_FAILED(nsres))
2217 return E_FAIL;
2219 set_wine_url(uri, url);
2220 uri->is_doc_uri = TRUE;
2222 *ret = uri;
2223 return S_OK;
2226 typedef struct {
2227 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2229 LONG ref;
2231 nsIProtocolHandler *nshandler;
2232 } nsProtocolHandler;
2234 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2236 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2238 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2239 nsQIResult result)
2241 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2243 *result = NULL;
2245 if(IsEqualGUID(&IID_nsISupports, riid)) {
2246 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2247 *result = NSPROTHANDLER(This);
2248 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2249 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2250 *result = NSPROTHANDLER(This);
2251 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2252 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2253 return NS_NOINTERFACE;
2256 if(*result) {
2257 nsISupports_AddRef((nsISupports*)*result);
2258 return NS_OK;
2261 WARN("(%s %p)\n", debugstr_guid(riid), result);
2262 return NS_NOINTERFACE;
2265 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2267 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2268 LONG ref = InterlockedIncrement(&This->ref);
2270 TRACE("(%p) ref=%d\n", This, ref);
2272 return ref;
2275 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2277 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2278 LONG ref = InterlockedDecrement(&This->ref);
2280 TRACE("(%p) ref=%d\n", This, ref);
2282 if(!ref) {
2283 if(This->nshandler)
2284 nsIProtocolHandler_Release(This->nshandler);
2285 heap_free(This);
2288 return ref;
2291 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2293 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2295 TRACE("(%p)->(%p)\n", This, aScheme);
2297 if(This->nshandler)
2298 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2299 return NS_ERROR_NOT_IMPLEMENTED;
2302 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2303 PRInt32 *aDefaultPort)
2305 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2307 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2309 if(This->nshandler)
2310 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2311 return NS_ERROR_NOT_IMPLEMENTED;
2314 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2315 PRUint32 *aProtocolFlags)
2317 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2319 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2321 if(This->nshandler)
2322 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2323 return NS_ERROR_NOT_IMPLEMENTED;
2326 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2327 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2329 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2331 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2333 if(This->nshandler)
2334 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2335 return NS_ERROR_NOT_IMPLEMENTED;
2338 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2339 nsIURI *aURI, nsIChannel **_retval)
2341 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2343 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2345 if(This->nshandler)
2346 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2347 return NS_ERROR_NOT_IMPLEMENTED;
2350 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2351 PRInt32 port, const char *scheme, PRBool *_retval)
2353 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2355 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2357 if(This->nshandler)
2358 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2359 return NS_ERROR_NOT_IMPLEMENTED;
2362 #undef NSPROTHANDLER_THIS
2364 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2365 nsProtocolHandler_QueryInterface,
2366 nsProtocolHandler_AddRef,
2367 nsProtocolHandler_Release,
2368 nsProtocolHandler_GetScheme,
2369 nsProtocolHandler_GetDefaultPort,
2370 nsProtocolHandler_GetProtocolFlags,
2371 nsProtocolHandler_NewURI,
2372 nsProtocolHandler_NewChannel,
2373 nsProtocolHandler_AllowPort
2376 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2378 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2380 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2381 ret->ref = 1;
2382 ret->nshandler = nshandler;
2384 return NSPROTHANDLER(ret);
2387 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2389 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2391 return 2;
2394 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2396 return 1;
2399 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2400 nsIProtocolHandler **_retval)
2402 nsIExternalProtocolHandler *nsexthandler;
2403 nsIProtocolHandler *nshandler;
2404 nsresult nsres;
2406 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2408 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2409 if(NS_FAILED(nsres)) {
2410 WARN("GetProtocolHandler failed: %08x\n", nsres);
2411 return nsres;
2414 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2415 (void**)&nsexthandler);
2416 if(NS_FAILED(nsres)) {
2417 *_retval = nshandler;
2418 return NS_OK;
2421 nsIExternalProtocolHandler_Release(nsexthandler);
2422 *_retval = create_protocol_handler(nshandler);
2423 TRACE("return %p\n", *_retval);
2424 return NS_OK;
2427 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2428 PRUint32 *_retval)
2430 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2431 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2434 static BOOL is_gecko_special_uri(const char *spec)
2436 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2437 int i;
2439 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2440 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2441 return TRUE;
2444 return FALSE;
2447 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2448 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2450 nsWineURI *wine_uri, *base_wine_uri = NULL;
2451 const char *spec = NULL;
2452 HTMLWindow *window = NULL;
2453 nsIURI *uri = NULL;
2454 LPCWSTR base_wine_url = NULL;
2455 nsACString spec_str;
2456 nsresult nsres;
2458 nsACString_GetData(aSpec, &spec);
2460 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2461 aBaseURI, _retval);
2463 if(is_gecko_special_uri(spec))
2464 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2466 if(!strncmp(spec, "wine:", 5))
2467 spec += 5;
2469 if(aBaseURI) {
2470 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2472 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
2473 if(NS_SUCCEEDED(nsres)) {
2474 base_wine_url = base_wine_uri->wine_url;
2475 if(base_wine_uri->window_ref && base_wine_uri->window_ref->window) {
2476 window = base_wine_uri->window_ref->window;
2477 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2479 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2480 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2481 TRACE("not wraping\n");
2482 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2483 }else {
2484 WARN("Could not get base nsWineURI: %08x\n", nsres);
2488 nsACString_InitDepend(&spec_str, spec);
2489 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2490 nsACString_Finish(&spec_str);
2491 if(NS_FAILED(nsres))
2492 TRACE("NewURI failed: %08x\n", nsres);
2494 nsres = create_uri(uri, window, NULL, &wine_uri);
2495 *_retval = (nsIURI*)wine_uri;
2497 if(window)
2498 IHTMLWindow2_Release(HTMLWINDOW2(window));
2500 if(base_wine_url) {
2501 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2502 DWORD len;
2503 HRESULT hres;
2505 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2507 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2508 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2509 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2510 if(SUCCEEDED(hres))
2511 set_wine_url(wine_uri, url);
2512 else
2513 WARN("CoCombineUrl failed: %08x\n", hres);
2514 }else {
2515 WCHAR url[INTERNET_MAX_URL_LENGTH];
2517 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2518 set_wine_url(wine_uri, url);
2521 if(base_wine_uri)
2522 nsIURI_Release(NSURI(base_wine_uri));
2524 return nsres;
2527 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2528 nsIURI **_retval)
2530 TRACE("(%p %p)\n", aFile, _retval);
2531 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2534 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2535 nsIChannel **_retval)
2537 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2538 nsChannel *ret;
2539 nsWineURI *wine_uri;
2540 nsresult nsres;
2542 TRACE("(%p %p)\n", aURI, _retval);
2544 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2545 if(NS_FAILED(nsres)) {
2546 TRACE("Could not get nsWineURI: %08x\n", nsres);
2547 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2550 ret = heap_alloc_zero(sizeof(nsChannel));
2552 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2553 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2554 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2555 ret->ref = 1;
2556 ret->uri = wine_uri;
2557 list_init(&ret->response_headers);
2559 nsIURI_AddRef(aURI);
2560 ret->original_uri = aURI;
2561 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2562 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2564 *_retval = NSCHANNEL(ret);
2565 return NS_OK;
2568 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2569 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2571 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2572 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2575 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2577 TRACE("(%p)\n", aOffline);
2578 return nsIIOService_GetOffline(nsio, aOffline);
2581 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2583 TRACE("(%x)\n", aOffline);
2584 return nsIIOService_SetOffline(nsio, aOffline);
2587 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2588 const char *aScheme, PRBool *_retval)
2590 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2591 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2594 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2595 nsACString * _retval)
2597 TRACE("(%p %p)\n", urlString, _retval);
2598 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2601 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2602 nsIOService_QueryInterface,
2603 nsIOService_AddRef,
2604 nsIOService_Release,
2605 nsIOService_GetProtocolHandler,
2606 nsIOService_GetProtocolFlags,
2607 nsIOService_NewURI,
2608 nsIOService_NewFileURI,
2609 nsIOService_NewChannelFromURI,
2610 nsIOService_NewChannel,
2611 nsIOService_GetOffline,
2612 nsIOService_SetOffline,
2613 nsIOService_AllowPort,
2614 nsIOService_ExtractScheme
2617 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2619 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2620 nsQIResult result)
2622 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2625 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2627 return 2;
2630 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2632 return 1;
2635 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2636 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2638 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2640 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2643 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2645 TRACE("()\n");
2647 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2650 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2652 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2654 if(aFlags == (1<<11)) {
2655 *_retval = FALSE;
2656 return NS_OK;
2659 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2662 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2664 TRACE("(%p %p)\n", aURI, _retval);
2666 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2669 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2670 PRUint32 aEscapeType, nsACString *_retval)
2672 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2674 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2677 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2678 nsACString *_retval)
2680 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2682 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2685 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2686 PRUint32 aFlags, nsACString *_retval)
2688 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2690 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2693 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2694 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2696 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2698 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2701 static const nsINetUtilVtbl nsNetUtilVtbl = {
2702 nsNetUtil_QueryInterface,
2703 nsNetUtil_AddRef,
2704 nsNetUtil_Release,
2705 nsNetUtil_ParseContentType,
2706 nsNetUtil_ProtocolHasFlags,
2707 nsNetUtil_URIChainHasFlags,
2708 nsNetUtil_ToImmutableURI,
2709 nsNetUtil_EscapeString,
2710 nsNetUtil_EscapeURL,
2711 nsNetUtil_UnescapeString,
2712 nsNetUtil_ExtractCharsetFromContentType
2715 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2717 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2718 nsQIResult result)
2720 *result = NULL;
2722 if(IsEqualGUID(&IID_nsISupports, riid))
2723 *result = &nsIOService;
2724 else if(IsEqualGUID(&IID_nsIIOService, riid))
2725 *result = &nsIOService;
2726 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2727 *result = &nsNetUtil;
2729 if(*result) {
2730 nsISupports_AddRef((nsISupports*)*result);
2731 return NS_OK;
2734 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2735 return NS_NOINTERFACE;
2738 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2739 nsQIResult result)
2741 *result = NULL;
2743 if(IsEqualGUID(&IID_nsISupports, riid)) {
2744 TRACE("(IID_nsISupports %p)\n", result);
2745 *result = iface;
2746 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2747 TRACE("(IID_nsIFactory %p)\n", result);
2748 *result = iface;
2751 if(*result) {
2752 nsIFactory_AddRef(iface);
2753 return NS_OK;
2756 WARN("(%s %p)\n", debugstr_guid(riid), result);
2757 return NS_NOINTERFACE;
2760 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2762 return 2;
2765 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2767 return 1;
2770 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2771 nsISupports *aOuter, const nsIID *iid, void **result)
2773 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2776 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2778 WARN("(%x)\n", lock);
2779 return NS_OK;
2782 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2783 nsIOServiceFactory_QueryInterface,
2784 nsIOServiceFactory_AddRef,
2785 nsIOServiceFactory_Release,
2786 nsIOServiceFactory_CreateInstance,
2787 nsIOServiceFactory_LockFactory
2790 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2792 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2794 nsIFactory *old_factory = NULL;
2795 nsresult nsres;
2797 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2798 &IID_nsIFactory, (void**)&old_factory);
2799 if(NS_FAILED(nsres)) {
2800 ERR("Could not get factory: %08x\n", nsres);
2801 return;
2804 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2805 if(NS_FAILED(nsres)) {
2806 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2807 nsIFactory_Release(old_factory);
2808 return;
2811 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2812 if(NS_FAILED(nsres)) {
2813 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2814 nsIIOService_Release(nsio);
2815 return;
2818 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2819 nsIFactory_Release(old_factory);
2820 if(NS_FAILED(nsres))
2821 ERR("UnregisterFactory failed: %08x\n", nsres);
2823 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2824 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2825 if(NS_FAILED(nsres))
2826 ERR("RegisterFactory failed: %08x\n", nsres);
2829 void release_nsio(void)
2831 if(net_util) {
2832 nsINetUtil_Release(net_util);
2833 net_util = NULL;
2836 if(nsio) {
2837 nsIIOService_Release(nsio);
2838 nsio = NULL;