shell32: Add printers CLSID to test, clean up a bit.
[wine/testsucceed.git] / dlls / mshtml / nsio.c
blob0c8e45704d78cb62492ecbfb7ee7889ceead2ecd
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 heap_free(url);
200 if(hres != S_OK || !new_url)
201 return FALSE;
203 if(strcmpW(url, new_url)) {
204 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
205 ret = TRUE;
208 CoTaskMemFree(new_url);
209 return ret;
212 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
214 nsWineURI *wine_uri;
215 nsresult nsres;
217 *_retval = FALSE;
219 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
220 if(NS_FAILED(nsres)) {
221 WARN("Could not get nsWineURI: %08x\n", nsres);
222 return NS_ERROR_NOT_IMPLEMENTED;
225 if(!wine_uri->is_doc_uri) {
226 if(!wine_uri->container) {
227 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
228 wine_uri->container = nscontainer;
231 wine_uri->is_doc_uri = TRUE;
232 *_retval = translate_url(nscontainer->doc->basedoc.doc_obj, wine_uri);
235 nsIURI_Release(NSURI(wine_uri));
236 return NS_OK;
239 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
241 static const WCHAR wszFtp[] = {'f','t','p',':'};
242 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
243 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
245 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
247 if(url) {
248 WCHAR *new_url;
250 new_url = heap_strdupW(url);
251 if(!new_url)
252 return E_OUTOFMEMORY;
253 heap_free(This->wine_url);
254 This->wine_url = new_url;
256 if(This->uri) {
257 /* FIXME: Always use wine url */
258 This->use_wine_url =
259 strncmpW(url, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
260 && strncmpW(url, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
261 && strncmpW(url, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
262 }else {
263 This->use_wine_url = TRUE;
265 }else {
266 heap_free(This->wine_url);
267 This->wine_url = NULL;
268 This->use_wine_url = FALSE;
271 return S_OK;
274 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
276 if(This->container) {
277 if(This->container == nscontainer)
278 return;
279 TRACE("Changing %p -> %p\n", This->container, nscontainer);
280 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
283 if(nscontainer)
284 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
285 This->container = nscontainer;
288 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
290 if(This->window_ref) {
291 if(This->window_ref->window == window)
292 return;
293 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
294 windowref_release(This->window_ref);
297 if(window) {
298 windowref_addref(window->window_ref);
299 This->window_ref = window->window_ref;
301 if(window->doc_obj)
302 set_uri_nscontainer(This, window->doc_obj->nscontainer);
303 }else {
304 This->window_ref = NULL;
308 static inline BOOL is_http_channel(nsChannel *This)
310 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTPS;
313 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
315 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
317 nsChannel *This = NSCHANNEL_THIS(iface);
319 if(IsEqualGUID(&IID_nsISupports, riid)) {
320 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
321 *result = NSCHANNEL(This);
322 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
323 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
324 *result = NSCHANNEL(This);
325 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
326 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
327 *result = NSCHANNEL(This);
328 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
329 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
330 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
331 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
332 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
333 *result = NSUPCHANNEL(This);
334 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
335 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
336 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
337 }else {
338 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
339 *result = NULL;
342 if(*result) {
343 nsIChannel_AddRef(NSCHANNEL(This));
344 return NS_OK;
347 return NS_NOINTERFACE;
350 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
352 nsChannel *This = NSCHANNEL_THIS(iface);
353 nsrefcnt ref = InterlockedIncrement(&This->ref);
355 TRACE("(%p) ref=%d\n", This, ref);
357 return ref;
360 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
362 nsChannel *This = NSCHANNEL_THIS(iface);
363 LONG ref = InterlockedDecrement(&This->ref);
365 if(!ref) {
366 struct ResponseHeader *header, *next_hdr;
368 nsIURI_Release(NSURI(This->uri));
369 if(This->owner)
370 nsISupports_Release(This->owner);
371 if(This->post_data_stream)
372 nsIInputStream_Release(This->post_data_stream);
373 if(This->load_group)
374 nsILoadGroup_Release(This->load_group);
375 if(This->notif_callback)
376 nsIInterfaceRequestor_Release(This->notif_callback);
377 if(This->original_uri)
378 nsIURI_Release(This->original_uri);
379 heap_free(This->content_type);
380 heap_free(This->charset);
382 LIST_FOR_EACH_ENTRY_SAFE(header, next_hdr, &This->response_headers, struct ResponseHeader, entry) {
383 list_remove(&header->entry);
384 heap_free(header->header);
385 heap_free(header->data);
386 heap_free(header);
389 heap_free(This);
392 return ref;
395 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
397 nsChannel *This = NSCHANNEL_THIS(iface);
399 FIXME("(%p)->(%p)\n", This, aName);
401 return NS_ERROR_NOT_IMPLEMENTED;
404 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
406 nsChannel *This = NSCHANNEL_THIS(iface);
408 FIXME("(%p)->(%p)\n", This, _retval);
410 return NS_ERROR_NOT_IMPLEMENTED;
413 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
415 nsChannel *This = NSCHANNEL_THIS(iface);
417 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
419 return *aStatus = NS_OK;
422 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
424 nsChannel *This = NSCHANNEL_THIS(iface);
426 FIXME("(%p)->(%08x)\n", This, aStatus);
428 return NS_ERROR_NOT_IMPLEMENTED;
431 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
433 nsChannel *This = NSCHANNEL_THIS(iface);
435 FIXME("(%p)\n", This);
437 return NS_ERROR_NOT_IMPLEMENTED;
440 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
442 nsChannel *This = NSCHANNEL_THIS(iface);
444 FIXME("(%p)\n", This);
446 return NS_ERROR_NOT_IMPLEMENTED;
449 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
451 nsChannel *This = NSCHANNEL_THIS(iface);
453 TRACE("(%p)->(%p)\n", This, aLoadGroup);
455 if(This->load_group)
456 nsILoadGroup_AddRef(This->load_group);
458 *aLoadGroup = This->load_group;
459 return NS_OK;
462 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
464 nsChannel *This = NSCHANNEL_THIS(iface);
466 TRACE("(%p)->(%p)\n", This, aLoadGroup);
468 if(This->load_group)
469 nsILoadGroup_Release(This->load_group);
470 if(aLoadGroup)
471 nsILoadGroup_AddRef(aLoadGroup);
472 This->load_group = aLoadGroup;
474 return NS_OK;
477 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
479 nsChannel *This = NSCHANNEL_THIS(iface);
481 TRACE("(%p)->(%p)\n", This, aLoadFlags);
483 *aLoadFlags = This->load_flags;
484 return NS_OK;
487 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
489 nsChannel *This = NSCHANNEL_THIS(iface);
491 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
493 This->load_flags = aLoadFlags;
494 return NS_OK;
497 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
499 nsChannel *This = NSCHANNEL_THIS(iface);
501 TRACE("(%p)->(%p)\n", This, aOriginalURI);
503 if(This->original_uri)
504 nsIURI_AddRef(This->original_uri);
506 *aOriginalURI = This->original_uri;
507 return NS_OK;
510 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
512 nsChannel *This = NSCHANNEL_THIS(iface);
514 TRACE("(%p)->(%p)\n", This, aOriginalURI);
516 if(This->original_uri)
517 nsIURI_Release(This->original_uri);
519 nsIURI_AddRef(aOriginalURI);
520 This->original_uri = aOriginalURI;
521 return NS_OK;
524 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
526 nsChannel *This = NSCHANNEL_THIS(iface);
528 TRACE("(%p)->(%p)\n", This, aURI);
530 nsIURI_AddRef(NSURI(This->uri));
531 *aURI = (nsIURI*)This->uri;
533 return NS_OK;
536 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
538 nsChannel *This = NSCHANNEL_THIS(iface);
540 TRACE("(%p)->(%p)\n", This, aOwner);
542 if(This->owner)
543 nsISupports_AddRef(This->owner);
544 *aOwner = This->owner;
546 return NS_OK;
549 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
551 nsChannel *This = NSCHANNEL_THIS(iface);
553 TRACE("(%p)->(%p)\n", This, aOwner);
555 if(aOwner)
556 nsISupports_AddRef(aOwner);
557 if(This->owner)
558 nsISupports_Release(This->owner);
559 This->owner = aOwner;
561 return NS_OK;
564 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
565 nsIInterfaceRequestor **aNotificationCallbacks)
567 nsChannel *This = NSCHANNEL_THIS(iface);
569 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
571 if(This->notif_callback)
572 nsIInterfaceRequestor_AddRef(This->notif_callback);
573 *aNotificationCallbacks = This->notif_callback;
575 return NS_OK;
578 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
579 nsIInterfaceRequestor *aNotificationCallbacks)
581 nsChannel *This = NSCHANNEL_THIS(iface);
583 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
585 if(This->notif_callback)
586 nsIInterfaceRequestor_Release(This->notif_callback);
587 if(aNotificationCallbacks)
588 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
590 This->notif_callback = aNotificationCallbacks;
592 return NS_OK;
595 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
597 nsChannel *This = NSCHANNEL_THIS(iface);
599 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
601 return NS_ERROR_NOT_IMPLEMENTED;
604 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
606 nsChannel *This = NSCHANNEL_THIS(iface);
608 TRACE("(%p)->(%p)\n", This, aContentType);
610 if(This->content_type) {
611 nsACString_SetData(aContentType, This->content_type);
612 return S_OK;
615 WARN("unknown type\n");
616 return NS_ERROR_FAILURE;
619 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
620 const nsACString *aContentType)
622 nsChannel *This = NSCHANNEL_THIS(iface);
623 const char *content_type;
625 TRACE("(%p)->(%p)\n", This, aContentType);
627 nsACString_GetData(aContentType, &content_type);
629 TRACE("content_type %s\n", content_type);
631 heap_free(This->content_type);
632 This->content_type = heap_strdupA(content_type);
634 return NS_OK;
637 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
638 nsACString *aContentCharset)
640 nsChannel *This = NSCHANNEL_THIS(iface);
642 TRACE("(%p)->(%p)\n", This, aContentCharset);
644 if(This->charset) {
645 nsACString_SetData(aContentCharset, This->charset);
646 return NS_OK;
649 nsACString_SetData(aContentCharset, "");
650 return NS_OK;
653 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
654 const nsACString *aContentCharset)
656 nsChannel *This = NSCHANNEL_THIS(iface);
658 FIXME("(%p)->(%p)\n", This, aContentCharset);
660 return NS_ERROR_NOT_IMPLEMENTED;
663 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
665 nsChannel *This = NSCHANNEL_THIS(iface);
667 FIXME("(%p)->(%p)\n", This, aContentLength);
669 return NS_ERROR_NOT_IMPLEMENTED;
672 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
674 nsChannel *This = NSCHANNEL_THIS(iface);
676 FIXME("(%p)->(%d)\n", This, aContentLength);
678 return NS_ERROR_NOT_IMPLEMENTED;
681 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
683 nsChannel *This = NSCHANNEL_THIS(iface);
685 FIXME("(%p)->(%p)\n", This, _retval);
687 return NS_ERROR_NOT_IMPLEMENTED;
690 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
692 nsWineURI *wine_uri;
693 nsresult nsres;
694 HRESULT hres;
696 if(!channel->original_uri) {
697 ERR("original_uri == NULL\n");
698 return E_FAIL;
701 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsWineURI, (void**)&wine_uri);
702 if(NS_FAILED(nsres)) {
703 ERR("Could not get nsWineURI: %08x\n", nsres);
704 return E_FAIL;
707 if(wine_uri->wine_url) {
708 hres = CreateURLMoniker(NULL, wine_uri->wine_url, mon);
709 if(FAILED(hres))
710 WARN("CreateURLMoniker failed: %08x\n", hres);
711 }else {
712 TRACE("wine_url == NULL\n");
713 hres = E_FAIL;
716 nsIURI_Release(NSURI(wine_uri));
718 return hres;
721 static HTMLWindow *get_window_from_load_group(nsChannel *This)
723 HTMLWindow *window;
724 nsIChannel *channel;
725 nsIRequest *req;
726 nsWineURI *wine_uri;
727 nsIURI *uri;
728 nsresult nsres;
730 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
731 if(NS_FAILED(nsres)) {
732 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
733 return NULL;
736 if(!req)
737 return NULL;
739 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
740 nsIRequest_Release(req);
741 if(NS_FAILED(nsres)) {
742 WARN("Could not get nsIChannel interface: %08x\n", nsres);
743 return NULL;
746 nsres = nsIChannel_GetURI(channel, &uri);
747 nsIChannel_Release(channel);
748 if(NS_FAILED(nsres)) {
749 ERR("GetURI failed: %08x\n", nsres);
750 return NULL;
753 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
754 nsIURI_Release(uri);
755 if(NS_FAILED(nsres)) {
756 TRACE("Could not get nsWineURI: %08x\n", nsres);
757 return NULL;
760 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
761 if(window)
762 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
763 nsIURI_Release(NSURI(wine_uri));
765 return window;
768 static HTMLWindow *get_channel_window(nsChannel *This)
770 nsIRequestObserver *req_observer;
771 nsIWebProgress *web_progress;
772 nsIDOMWindow *nswindow;
773 HTMLWindow *window;
774 nsresult nsres;
776 if(!This->load_group) {
777 ERR("NULL load_group\n");
778 return NULL;
781 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
782 if(NS_FAILED(nsres) || !req_observer) {
783 ERR("GetGroupObserver failed: %08x\n", nsres);
784 return NULL;
787 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
788 nsIRequestObserver_Release(req_observer);
789 if(NS_FAILED(nsres)) {
790 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
791 return NULL;
794 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
795 nsIWebProgress_Release(web_progress);
796 if(NS_FAILED(nsres) || !nswindow) {
797 ERR("GetDOMWindow failed: %08x\n", nsres);
798 return NULL;
801 window = nswindow_to_window(nswindow);
802 nsIDOMWindow_Release(nswindow);
804 if(window)
805 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
806 else
807 FIXME("NULL window for %p\n", nswindow);
808 return window;
811 typedef struct {
812 task_t header;
813 HTMLDocumentNode *doc;
814 nsChannelBSC *bscallback;
815 } start_binding_task_t;
817 static void start_binding_proc(task_t *_task)
819 start_binding_task_t *task = (start_binding_task_t*)_task;
821 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
823 IUnknown_Release((IUnknown*)task->bscallback);
826 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
827 nsISupports *context)
829 nsChannelBSC *bscallback;
830 IMoniker *mon = NULL;
831 HRESULT hres;
833 hres = create_mon_for_nschannel(This, &mon);
834 if(FAILED(hres))
835 return NS_ERROR_UNEXPECTED;
837 if(is_doc_channel)
838 set_current_mon(window, mon);
840 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
841 IMoniker_Release(mon);
842 if(FAILED(hres))
843 return NS_ERROR_UNEXPECTED;
845 channelbsc_set_channel(bscallback, This, listener, context);
847 if(is_doc_channel) {
848 set_window_bscallback(window, bscallback);
849 async_start_doc_binding(window, bscallback);
850 IUnknown_Release((IUnknown*)bscallback);
851 }else {
852 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
854 task->doc = window->doc;
855 task->bscallback = bscallback;
856 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
859 return NS_OK;
862 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
863 nsISupports *aContext)
865 nsChannel *This = NSCHANNEL_THIS(iface);
866 HTMLWindow *window = NULL;
867 BOOL open = TRUE;
868 nsresult nsres = NS_OK;
870 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
872 if(This->uri->is_doc_uri) {
873 window = get_channel_window(This);
874 if(window) {
875 set_uri_window(This->uri, window);
876 }else if(This->uri->container) {
877 BOOL b;
879 /* nscontainer->doc should be NULL which means navigation to a new window */
880 if(This->uri->container->doc)
881 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
883 b = before_async_open(This, This->uri->container);
884 if(b)
885 FIXME("Navigation not cancelled\n");
886 return NS_ERROR_UNEXPECTED;
890 if(!window) {
891 if(This->uri->window_ref && This->uri->window_ref->window) {
892 window = This->uri->window_ref->window;
893 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
894 }else if(This->load_group) {
895 window = get_window_from_load_group(This);
896 if(window)
897 set_uri_window(This->uri, window);
901 if(!window) {
902 ERR("window = NULL\n");
903 return NS_ERROR_UNEXPECTED;
906 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
907 if(This->uri->channel_bsc) {
908 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
910 if(window->doc_obj->mime) {
911 heap_free(This->content_type);
912 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
915 open = FALSE;
916 }else {
917 open = !before_async_open(This, window->doc_obj->nscontainer);
918 if(!open) {
919 TRACE("canceled\n");
920 nsres = NS_ERROR_UNEXPECTED;
925 if(open)
926 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
928 IHTMLWindow2_Release(HTMLWINDOW2(window));
929 return nsres;
932 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
934 nsChannel *This = NSCHANNEL_THIS(iface);
936 FIXME("(%p)->(%p)\n", This, aRequestMethod);
938 return NS_ERROR_NOT_IMPLEMENTED;
941 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
942 const nsACString *aRequestMethod)
944 nsChannel *This = NSCHANNEL_THIS(iface);
946 TRACE("(%p)->(%p): Returning NS_OK\n", This, aRequestMethod);
948 return NS_OK;
951 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
953 nsChannel *This = NSCHANNEL_THIS(iface);
955 FIXME("(%p)->(%p)\n", This, aReferrer);
957 return NS_ERROR_NOT_IMPLEMENTED;
960 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
962 nsChannel *This = NSCHANNEL_THIS(iface);
964 FIXME("(%p)->(%p)\n", This, aReferrer);
966 return NS_OK;
969 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
970 const nsACString *aHeader, nsACString *_retval)
972 nsChannel *This = NSCHANNEL_THIS(iface);
974 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
976 return NS_ERROR_NOT_IMPLEMENTED;
979 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
980 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
982 nsChannel *This = NSCHANNEL_THIS(iface);
984 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
986 return NS_OK;
989 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
990 nsIHttpHeaderVisitor *aVisitor)
992 nsChannel *This = NSCHANNEL_THIS(iface);
994 FIXME("(%p)->(%p)\n", This, aVisitor);
996 return NS_ERROR_NOT_IMPLEMENTED;
999 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1001 nsChannel *This = NSCHANNEL_THIS(iface);
1003 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1005 return NS_ERROR_NOT_IMPLEMENTED;
1008 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1010 nsChannel *This = NSCHANNEL_THIS(iface);
1012 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1014 return NS_ERROR_NOT_IMPLEMENTED;
1017 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1019 nsChannel *This = NSCHANNEL_THIS(iface);
1021 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1023 return NS_ERROR_NOT_IMPLEMENTED;
1026 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1028 nsChannel *This = NSCHANNEL_THIS(iface);
1030 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1032 return NS_ERROR_NOT_IMPLEMENTED;
1035 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1037 nsChannel *This = NSCHANNEL_THIS(iface);
1039 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1041 if(This->response_status) {
1042 *aResponseStatus = This->response_status;
1043 return NS_OK;
1046 WARN("No response status\n");
1047 return NS_ERROR_UNEXPECTED;
1050 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1051 nsACString *aResponseStatusText)
1053 nsChannel *This = NSCHANNEL_THIS(iface);
1055 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1057 return NS_ERROR_NOT_IMPLEMENTED;
1060 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1061 PRBool *aRequestSucceeded)
1063 nsChannel *This = NSCHANNEL_THIS(iface);
1065 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1067 if(!This->response_status)
1068 return NS_ERROR_NOT_AVAILABLE;
1070 *aRequestSucceeded = This->response_status/100 == 2;
1072 return NS_OK;
1075 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1076 const nsACString *header, nsACString *_retval)
1078 nsChannel *This = NSCHANNEL_THIS(iface);
1079 const char *header_str;
1080 WCHAR *header_wstr;
1081 struct ResponseHeader *this_header;
1083 nsACString_GetData(header, &header_str);
1084 TRACE("(%p)->(%p(%s) %p)\n", This, header, header_str, _retval);
1086 header_wstr = heap_strdupAtoW(header_str);
1087 if(!header_wstr)
1088 return NS_ERROR_UNEXPECTED;
1090 LIST_FOR_EACH_ENTRY(this_header, &This->response_headers, struct ResponseHeader, entry) {
1091 if(!strcmpW(this_header->header, header_wstr)) {
1092 char *data = heap_strdupWtoA(this_header->data);
1093 if(!data) {
1094 heap_free(header_wstr);
1095 return NS_ERROR_UNEXPECTED;
1097 nsACString_SetData(_retval, data);
1098 heap_free(data);
1099 heap_free(header_wstr);
1100 return NS_OK;
1104 heap_free(header_wstr);
1106 return NS_ERROR_NOT_AVAILABLE;
1109 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1110 const nsACString *header, const nsACString *value, PRBool merge)
1112 nsChannel *This = NSCHANNEL_THIS(iface);
1114 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
1116 return NS_ERROR_NOT_IMPLEMENTED;
1119 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1120 nsIHttpHeaderVisitor *aVisitor)
1122 nsChannel *This = NSCHANNEL_THIS(iface);
1124 FIXME("(%p)->(%p)\n", This, aVisitor);
1126 return NS_ERROR_NOT_IMPLEMENTED;
1129 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1131 nsChannel *This = NSCHANNEL_THIS(iface);
1133 FIXME("(%p)->(%p)\n", This, _retval);
1135 return NS_ERROR_NOT_IMPLEMENTED;
1138 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1140 nsChannel *This = NSCHANNEL_THIS(iface);
1142 FIXME("(%p)->(%p)\n", This, _retval);
1144 return NS_ERROR_NOT_IMPLEMENTED;
1147 #undef NSCHANNEL_THIS
1149 static const nsIHttpChannelVtbl nsChannelVtbl = {
1150 nsChannel_QueryInterface,
1151 nsChannel_AddRef,
1152 nsChannel_Release,
1153 nsChannel_GetName,
1154 nsChannel_IsPending,
1155 nsChannel_GetStatus,
1156 nsChannel_Cancel,
1157 nsChannel_Suspend,
1158 nsChannel_Resume,
1159 nsChannel_GetLoadGroup,
1160 nsChannel_SetLoadGroup,
1161 nsChannel_GetLoadFlags,
1162 nsChannel_SetLoadFlags,
1163 nsChannel_GetOriginalURI,
1164 nsChannel_SetOriginalURI,
1165 nsChannel_GetURI,
1166 nsChannel_GetOwner,
1167 nsChannel_SetOwner,
1168 nsChannel_GetNotificationCallbacks,
1169 nsChannel_SetNotificationCallbacks,
1170 nsChannel_GetSecurityInfo,
1171 nsChannel_GetContentType,
1172 nsChannel_SetContentType,
1173 nsChannel_GetContentCharset,
1174 nsChannel_SetContentCharset,
1175 nsChannel_GetContentLength,
1176 nsChannel_SetContentLength,
1177 nsChannel_Open,
1178 nsChannel_AsyncOpen,
1179 nsChannel_GetRequestMethod,
1180 nsChannel_SetRequestMethod,
1181 nsChannel_GetReferrer,
1182 nsChannel_SetReferrer,
1183 nsChannel_GetRequestHeader,
1184 nsChannel_SetRequestHeader,
1185 nsChannel_VisitRequestHeaders,
1186 nsChannel_GetAllowPipelining,
1187 nsChannel_SetAllowPipelining,
1188 nsChannel_GetRedirectionLimit,
1189 nsChannel_SetRedirectionLimit,
1190 nsChannel_GetResponseStatus,
1191 nsChannel_GetResponseStatusText,
1192 nsChannel_GetRequestSucceeded,
1193 nsChannel_GetResponseHeader,
1194 nsChannel_SetResponseHeader,
1195 nsChannel_VisitResponseHeaders,
1196 nsChannel_IsNoStoreResponse,
1197 nsChannel_IsNoCacheResponse
1200 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1202 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1203 nsQIResult result)
1205 nsChannel *This = NSUPCHANNEL_THIS(iface);
1206 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1209 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1211 nsChannel *This = NSUPCHANNEL_THIS(iface);
1212 return nsIChannel_AddRef(NSCHANNEL(This));
1215 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1217 nsChannel *This = NSUPCHANNEL_THIS(iface);
1218 return nsIChannel_Release(NSCHANNEL(This));
1221 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1222 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1224 nsChannel *This = NSUPCHANNEL_THIS(iface);
1225 const char *content_type;
1227 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1229 if(This->post_data_stream)
1230 nsIInputStream_Release(This->post_data_stream);
1232 if(aContentType) {
1233 nsACString_GetData(aContentType, &content_type);
1234 if(*content_type)
1235 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1238 if(aContentLength != -1)
1239 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1241 if(This->post_data_stream)
1242 nsIInputStream_Release(This->post_data_stream);
1243 This->post_data_stream = aStream;
1244 if(aStream)
1245 nsIInputStream_AddRef(aStream);
1247 return NS_OK;
1250 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1251 nsIInputStream **aUploadStream)
1253 nsChannel *This = NSUPCHANNEL_THIS(iface);
1255 TRACE("(%p)->(%p)\n", This, aUploadStream);
1257 if(This->post_data_stream)
1258 nsIInputStream_AddRef(This->post_data_stream);
1260 *aUploadStream = This->post_data_stream;
1261 return NS_OK;
1264 #undef NSUPCHANNEL_THIS
1266 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1267 nsUploadChannel_QueryInterface,
1268 nsUploadChannel_AddRef,
1269 nsUploadChannel_Release,
1270 nsUploadChannel_SetUploadStream,
1271 nsUploadChannel_GetUploadStream
1274 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1276 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1277 nsQIResult result)
1279 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1280 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1283 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1285 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1286 return nsIChannel_AddRef(NSCHANNEL(This));
1289 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1291 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1292 return nsIChannel_Release(NSCHANNEL(This));
1295 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1297 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1299 FIXME("(%p)->()\n", This);
1301 return NS_ERROR_NOT_IMPLEMENTED;
1304 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1306 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1308 FIXME("(%p)->()\n", This);
1310 return NS_ERROR_NOT_IMPLEMENTED;
1313 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1315 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1317 FIXME("(%p)->()\n", This);
1319 return NS_ERROR_NOT_IMPLEMENTED;
1322 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1324 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1326 FIXME("(%p)->()\n", This);
1328 return NS_ERROR_NOT_IMPLEMENTED;
1331 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1333 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1335 FIXME("(%p)->()\n", This);
1337 return NS_ERROR_NOT_IMPLEMENTED;
1340 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1342 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1344 FIXME("(%p)->()\n", This);
1346 return NS_ERROR_NOT_IMPLEMENTED;
1349 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1351 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1353 FIXME("(%p)->()\n", This);
1355 return NS_ERROR_NOT_IMPLEMENTED;
1358 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1360 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1362 FIXME("(%p)->()\n", This);
1364 return NS_ERROR_NOT_IMPLEMENTED;
1367 #undef NSHTTPINTERNAL_THIS
1369 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1370 nsHttpChannelInternal_QueryInterface,
1371 nsHttpChannelInternal_AddRef,
1372 nsHttpChannelInternal_Release,
1373 nsHttpChannelInternal_GetDocumentURI,
1374 nsHttpChannelInternal_SetDocumentURI,
1375 nsHttpChannelInternal_GetRequestVersion,
1376 nsHttpChannelInternal_GetResponseVersion,
1377 nsHttpChannelInternal_SetCookie,
1378 nsHttpChannelInternal_SetupFallbackChannel,
1379 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1380 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1383 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1385 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, nsQIResult result)
1387 nsWineURI *This = NSURI_THIS(iface);
1389 *result = NULL;
1391 if(IsEqualGUID(&IID_nsISupports, riid)) {
1392 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1393 *result = NSURI(This);
1394 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1395 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1396 *result = NSURI(This);
1397 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1398 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1399 *result = NSURL(This);
1400 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1401 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1402 *result = This;
1405 if(*result) {
1406 nsIURI_AddRef(NSURI(This));
1407 return NS_OK;
1410 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1411 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1414 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1416 nsWineURI *This = NSURI_THIS(iface);
1417 LONG ref = InterlockedIncrement(&This->ref);
1419 TRACE("(%p) ref=%d\n", This, ref);
1421 return ref;
1424 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1426 nsWineURI *This = NSURI_THIS(iface);
1427 LONG ref = InterlockedDecrement(&This->ref);
1429 TRACE("(%p) ref=%d\n", This, ref);
1431 if(!ref) {
1432 if(This->window_ref)
1433 windowref_release(This->window_ref);
1434 if(This->container)
1435 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1436 if(This->nsurl)
1437 nsIURL_Release(This->nsurl);
1438 if(This->uri)
1439 nsIURI_Release(This->uri);
1440 heap_free(This->wine_url);
1441 heap_free(This);
1444 return ref;
1447 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1449 nsWineURI *This = NSURI_THIS(iface);
1451 TRACE("(%p)->(%p)\n", This, aSpec);
1453 if(This->use_wine_url) {
1454 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1455 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1456 nsACString_SetData(aSpec, speca);
1458 return NS_OK;
1461 if(This->uri)
1462 return nsIURI_GetSpec(This->uri, aSpec);
1464 TRACE("returning error\n");
1465 return NS_ERROR_NOT_IMPLEMENTED;
1469 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1471 nsWineURI *This = NSURI_THIS(iface);
1473 TRACE("(%p)->(%p)\n", This, aSpec);
1475 if(This->uri)
1476 return nsIURI_SetSpec(This->uri, aSpec);
1478 FIXME("default action not implemented\n");
1479 return NS_ERROR_NOT_IMPLEMENTED;
1482 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1484 nsWineURI *This = NSURI_THIS(iface);
1486 TRACE("(%p)->(%p)\n", This, aPrePath);
1488 if(This->uri)
1489 return nsIURI_GetPrePath(This->uri, aPrePath);
1491 FIXME("default action not implemented\n");
1492 return NS_ERROR_NOT_IMPLEMENTED;
1495 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1497 nsWineURI *This = NSURI_THIS(iface);
1499 TRACE("(%p)->(%p)\n", This, aScheme);
1501 if(This->use_wine_url) {
1503 * For Gecko we set scheme to unknown so it won't be handled
1504 * as any special case.
1506 nsACString_SetData(aScheme, "wine");
1507 return NS_OK;
1510 if(This->uri)
1511 return nsIURI_GetScheme(This->uri, aScheme);
1513 TRACE("returning error\n");
1514 return NS_ERROR_NOT_IMPLEMENTED;
1517 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1519 nsWineURI *This = NSURI_THIS(iface);
1521 TRACE("(%p)->(%p)\n", This, aScheme);
1523 if(This->uri)
1524 return nsIURI_SetScheme(This->uri, aScheme);
1526 FIXME("default action not implemented\n");
1527 return NS_ERROR_NOT_IMPLEMENTED;
1530 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1532 nsWineURI *This = NSURI_THIS(iface);
1534 TRACE("(%p)->(%p)\n", This, aUserPass);
1536 if(This->uri)
1537 return nsIURI_GetUserPass(This->uri, aUserPass);
1539 FIXME("default action not implemented\n");
1540 return NS_ERROR_NOT_IMPLEMENTED;
1543 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1545 nsWineURI *This = NSURI_THIS(iface);
1547 TRACE("(%p)->(%p)\n", This, aUserPass);
1549 if(This->uri)
1550 return nsIURI_SetUserPass(This->uri, aUserPass);
1552 FIXME("default action not implemented\n");
1553 return NS_ERROR_NOT_IMPLEMENTED;
1556 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1558 nsWineURI *This = NSURI_THIS(iface);
1560 TRACE("(%p)->(%p)\n", This, aUsername);
1562 if(This->uri)
1563 return nsIURI_GetUsername(This->uri, aUsername);
1565 FIXME("default action not implemented\n");
1566 return NS_ERROR_NOT_IMPLEMENTED;
1569 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1571 nsWineURI *This = NSURI_THIS(iface);
1573 TRACE("(%p)->(%p)\n", This, aUsername);
1575 if(This->uri)
1576 return nsIURI_SetUsername(This->uri, aUsername);
1578 FIXME("default action not implemented\n");
1579 return NS_ERROR_NOT_IMPLEMENTED;
1582 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1584 nsWineURI *This = NSURI_THIS(iface);
1586 TRACE("(%p)->(%p)\n", This, aPassword);
1588 if(This->uri)
1589 return nsIURI_GetPassword(This->uri, aPassword);
1591 FIXME("default action not implemented\n");
1592 return NS_ERROR_NOT_IMPLEMENTED;
1595 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1597 nsWineURI *This = NSURI_THIS(iface);
1599 TRACE("(%p)->(%p)\n", This, aPassword);
1601 if(This->uri)
1602 return nsIURI_SetPassword(This->uri, aPassword);
1604 FIXME("default action not implemented\n");
1605 return NS_ERROR_NOT_IMPLEMENTED;
1608 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1610 nsWineURI *This = NSURI_THIS(iface);
1612 TRACE("(%p)->(%p)\n", This, aHostPort);
1614 if(This->uri)
1615 return nsIURI_GetHostPort(This->uri, aHostPort);
1617 FIXME("default action not implemented\n");
1618 return NS_ERROR_NOT_IMPLEMENTED;
1621 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1623 nsWineURI *This = NSURI_THIS(iface);
1625 TRACE("(%p)->(%p)\n", This, aHostPort);
1627 if(This->uri)
1628 return nsIURI_SetHostPort(This->uri, aHostPort);
1630 FIXME("default action not implemented\n");
1631 return NS_ERROR_NOT_IMPLEMENTED;
1634 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1636 nsWineURI *This = NSURI_THIS(iface);
1638 TRACE("(%p)->(%p)\n", This, aHost);
1640 if(This->uri)
1641 return nsIURI_GetHost(This->uri, aHost);
1643 FIXME("default action not implemented\n");
1644 return NS_ERROR_NOT_IMPLEMENTED;
1647 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1649 nsWineURI *This = NSURI_THIS(iface);
1651 TRACE("(%p)->(%p)\n", This, aHost);
1653 if(This->uri)
1654 return nsIURI_SetHost(This->uri, aHost);
1656 FIXME("default action not implemented\n");
1657 return NS_ERROR_NOT_IMPLEMENTED;
1660 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1662 nsWineURI *This = NSURI_THIS(iface);
1664 TRACE("(%p)->(%p)\n", This, aPort);
1666 if(This->uri)
1667 return nsIURI_GetPort(This->uri, aPort);
1669 FIXME("default action not implemented\n");
1670 return NS_ERROR_NOT_IMPLEMENTED;
1673 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1675 nsWineURI *This = NSURI_THIS(iface);
1677 TRACE("(%p)->(%d)\n", This, aPort);
1679 if(This->uri)
1680 return nsIURI_SetPort(This->uri, aPort);
1682 FIXME("default action not implemented\n");
1683 return NS_ERROR_NOT_IMPLEMENTED;
1686 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
1688 nsWineURI *This = NSURI_THIS(iface);
1690 TRACE("(%p)->(%p)\n", This, aPath);
1692 if(This->uri)
1693 return nsIURI_GetPath(This->uri, aPath);
1695 FIXME("default action not implemented\n");
1696 return NS_ERROR_NOT_IMPLEMENTED;
1699 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
1701 nsWineURI *This = NSURI_THIS(iface);
1702 const char *path;
1704 nsACString_GetData(aPath, &path);
1705 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1708 if(This->wine_url) {
1709 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1710 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1711 LPWSTR pathw;
1712 HRESULT hres;
1714 pathw = heap_strdupAtoW(path);
1715 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1716 heap_free(pathw);
1717 if(SUCCEEDED(hres))
1718 set_wine_url(This, new_url);
1719 else
1720 WARN("UrlCombine failed: %08x\n", hres);
1723 if(!This->uri)
1724 return NS_OK;
1726 return nsIURI_SetPath(This->uri, aPath);
1729 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
1731 nsWineURI *This = NSURI_THIS(iface);
1732 nsWineURI *wine_uri;
1733 nsresult nsres;
1735 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1737 if(This->uri)
1738 return nsIURI_Equals(This->uri, other, _retval);
1740 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&wine_uri);
1741 if(NS_FAILED(nsres)) {
1742 TRACE("Could not get nsWineURI interface\n");
1743 *_retval = FALSE;
1744 return NS_OK;
1747 *_retval = wine_uri->wine_url && !UrlCompareW(This->wine_url, wine_uri->wine_url, TRUE);
1748 nsIURI_Release(NSURI(wine_uri));
1750 return NS_OK;
1753 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
1755 nsWineURI *This = NSURI_THIS(iface);
1757 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1759 if(This->use_wine_url) {
1760 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1761 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1763 *_retval = lstrlenW(This->wine_url) > len
1764 && This->wine_url[len] == ':'
1765 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1766 return NS_OK;
1769 if(This->uri)
1770 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1772 TRACE("returning error\n");
1773 return NS_ERROR_NOT_IMPLEMENTED;
1776 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
1778 nsWineURI *This = NSURI_THIS(iface);
1779 nsIURI *nsuri = NULL;
1780 nsWineURI *wine_uri;
1781 nsresult nsres;
1783 TRACE("(%p)->(%p)\n", This, _retval);
1785 if(This->uri) {
1786 nsres = nsIURI_Clone(This->uri, &nsuri);
1787 if(NS_FAILED(nsres)) {
1788 WARN("Clone failed: %08x\n", nsres);
1789 return nsres;
1793 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1794 if(NS_FAILED(nsres)) {
1795 WARN("create_uri failed: %08x\n", nsres);
1796 return nsres;
1799 set_wine_url(wine_uri, This->wine_url);
1801 *_retval = NSURI(wine_uri);
1802 return NS_OK;
1805 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *arelativePath,
1806 nsACString *_retval)
1808 nsWineURI *This = NSURI_THIS(iface);
1810 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1812 if(This->uri)
1813 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1815 FIXME("default action not implemented\n");
1816 return NS_ERROR_NOT_IMPLEMENTED;
1819 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
1821 nsWineURI *This = NSURI_THIS(iface);
1823 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1825 if(This->use_wine_url)
1826 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1828 if(This->uri)
1829 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1831 TRACE("returning error\n");
1832 return NS_ERROR_NOT_IMPLEMENTED;
1835 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
1837 nsWineURI *This = NSURI_THIS(iface);
1839 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1841 if(This->uri)
1842 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1844 FIXME("default action not implemented\n");
1845 return NS_ERROR_NOT_IMPLEMENTED;
1848 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
1850 nsWineURI *This = NSURI_THIS(iface);
1852 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1854 if(This->uri)
1855 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1857 FIXME("default action not implemented\n");
1858 return NS_ERROR_NOT_IMPLEMENTED;
1861 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
1863 nsWineURI *This = NSURI_THIS(iface);
1865 TRACE("(%p)->(%p)\n", This, aFilePath);
1867 if(This->nsurl)
1868 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1870 FIXME("default action not implemented\n");
1871 return NS_ERROR_NOT_IMPLEMENTED;
1874 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
1876 nsWineURI *This = NSURI_THIS(iface);
1878 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1880 if(This->nsurl)
1881 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1883 FIXME("default action not implemented\n");
1884 return NS_ERROR_NOT_IMPLEMENTED;
1887 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
1889 nsWineURI *This = NSURI_THIS(iface);
1891 TRACE("(%p)->(%p)\n", This, aParam);
1893 if(This->nsurl)
1894 return nsIURL_GetParam(This->nsurl, aParam);
1896 FIXME("default action not implemented\n");
1897 return NS_ERROR_NOT_IMPLEMENTED;
1900 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
1902 nsWineURI *This = NSURI_THIS(iface);
1904 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1906 if(This->nsurl)
1907 return nsIURL_SetParam(This->nsurl, aParam);
1909 FIXME("default action not implemented\n");
1910 return NS_ERROR_NOT_IMPLEMENTED;
1913 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
1915 nsWineURI *This = NSURI_THIS(iface);
1917 TRACE("(%p)->(%p)\n", This, aQuery);
1919 if(This->nsurl)
1920 return nsIURL_GetQuery(This->nsurl, aQuery);
1922 FIXME("default action not implemented\n");
1923 return NS_ERROR_NOT_IMPLEMENTED;
1926 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
1928 nsWineURI *This = NSURI_THIS(iface);
1929 const WCHAR *ptr1, *ptr2;
1930 const char *query;
1931 WCHAR *new_url, *ptr;
1932 DWORD len, size;
1934 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1936 if(This->nsurl)
1937 nsIURL_SetQuery(This->nsurl, aQuery);
1939 if(!This->wine_url)
1940 return NS_OK;
1942 nsACString_GetData(aQuery, &query);
1943 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1944 ptr1 = strchrW(This->wine_url, '?');
1945 if(ptr1) {
1946 size += ptr1-This->wine_url;
1947 ptr2 = strchrW(ptr1, '#');
1948 if(ptr2)
1949 size += strlenW(ptr2);
1950 }else {
1951 ptr1 = This->wine_url + strlenW(This->wine_url);
1952 ptr2 = NULL;
1953 size += strlenW(This->wine_url);
1956 if(*query)
1957 size++;
1959 new_url = heap_alloc(size*sizeof(WCHAR));
1960 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1961 ptr = new_url + (ptr1-This->wine_url);
1962 if(*query) {
1963 *ptr++ = '?';
1964 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1965 ptr += len-1;
1967 if(ptr2)
1968 strcpyW(ptr, ptr2);
1969 else
1970 *ptr = 0;
1972 TRACE("setting %s\n", debugstr_w(new_url));
1974 heap_free(This->wine_url);
1975 This->wine_url = new_url;
1976 return NS_OK;
1979 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
1981 nsWineURI *This = NSURI_THIS(iface);
1983 TRACE("(%p)->(%p)\n", This, aRef);
1985 if(This->nsurl)
1986 return nsIURL_GetRef(This->nsurl, aRef);
1988 FIXME("default action not implemented\n");
1989 return NS_ERROR_NOT_IMPLEMENTED;
1992 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
1994 nsWineURI *This = NSURI_THIS(iface);
1995 const char *refa;
1997 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1999 if(This->nsurl)
2000 return nsIURL_SetRef(This->nsurl, aRef);
2002 nsACString_GetData(aRef, &refa);
2003 if(!*refa)
2004 return NS_OK;
2006 FIXME("default action not implemented\n");
2007 return NS_ERROR_NOT_IMPLEMENTED;
2010 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
2012 nsWineURI *This = NSURI_THIS(iface);
2014 TRACE("(%p)->(%p)\n", This, aDirectory);
2016 if(This->nsurl)
2017 return nsIURL_GetDirectory(This->nsurl, aDirectory);
2019 FIXME("default action not implemented\n");
2020 return NS_ERROR_NOT_IMPLEMENTED;
2023 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2025 nsWineURI *This = NSURI_THIS(iface);
2027 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2029 if(This->nsurl)
2030 return nsIURL_SetDirectory(This->nsurl, aDirectory);
2032 FIXME("default action not implemented\n");
2033 return NS_ERROR_NOT_IMPLEMENTED;
2036 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2038 nsWineURI *This = NSURI_THIS(iface);
2040 TRACE("(%p)->(%p)\n", This, aFileName);
2042 if(This->nsurl)
2043 return nsIURL_GetFileName(This->nsurl, aFileName);
2045 FIXME("default action not implemented\n");
2046 return NS_ERROR_NOT_IMPLEMENTED;
2049 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2051 nsWineURI *This = NSURI_THIS(iface);
2053 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2055 if(This->nsurl)
2056 return nsIURL_SetFileName(This->nsurl, aFileName);
2058 FIXME("default action not implemented\n");
2059 return NS_ERROR_NOT_IMPLEMENTED;
2062 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2064 nsWineURI *This = NSURI_THIS(iface);
2066 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2068 if(This->nsurl)
2069 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2071 FIXME("default action not implemented\n");
2072 return NS_ERROR_NOT_IMPLEMENTED;
2075 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2077 nsWineURI *This = NSURI_THIS(iface);
2079 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2081 if(This->nsurl)
2082 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2084 FIXME("default action not implemented\n");
2085 return NS_ERROR_NOT_IMPLEMENTED;
2088 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2090 nsWineURI *This = NSURI_THIS(iface);
2092 TRACE("(%p)->(%p)\n", This, aFileExtension);
2094 if(This->nsurl)
2095 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2097 FIXME("default action not implemented\n");
2098 return NS_ERROR_NOT_IMPLEMENTED;
2101 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2103 nsWineURI *This = NSURI_THIS(iface);
2105 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2107 if(This->nsurl)
2108 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2110 FIXME("default action not implemented\n");
2111 return NS_ERROR_NOT_IMPLEMENTED;
2114 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2116 nsWineURI *This = NSURI_THIS(iface);
2118 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2120 if(This->nsurl)
2121 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2123 FIXME("default action not implemented\n");
2124 return NS_ERROR_NOT_IMPLEMENTED;
2127 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2129 nsWineURI *This = NSURI_THIS(iface);
2131 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2133 if(This->nsurl)
2134 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2136 FIXME("default action not implemented\n");
2137 return NS_ERROR_NOT_IMPLEMENTED;
2140 #undef NSURI_THIS
2142 static const nsIURLVtbl nsURLVtbl = {
2143 nsURI_QueryInterface,
2144 nsURI_AddRef,
2145 nsURI_Release,
2146 nsURI_GetSpec,
2147 nsURI_SetSpec,
2148 nsURI_GetPrePath,
2149 nsURI_GetScheme,
2150 nsURI_SetScheme,
2151 nsURI_GetUserPass,
2152 nsURI_SetUserPass,
2153 nsURI_GetUsername,
2154 nsURI_SetUsername,
2155 nsURI_GetPassword,
2156 nsURI_SetPassword,
2157 nsURI_GetHostPort,
2158 nsURI_SetHostPort,
2159 nsURI_GetHost,
2160 nsURI_SetHost,
2161 nsURI_GetPort,
2162 nsURI_SetPort,
2163 nsURI_GetPath,
2164 nsURI_SetPath,
2165 nsURI_Equals,
2166 nsURI_SchemeIs,
2167 nsURI_Clone,
2168 nsURI_Resolve,
2169 nsURI_GetAsciiSpec,
2170 nsURI_GetAsciiHost,
2171 nsURI_GetOriginCharset,
2172 nsURL_GetFilePath,
2173 nsURL_SetFilePath,
2174 nsURL_GetParam,
2175 nsURL_SetParam,
2176 nsURL_GetQuery,
2177 nsURL_SetQuery,
2178 nsURL_GetRef,
2179 nsURL_SetRef,
2180 nsURL_GetDirectory,
2181 nsURL_SetDirectory,
2182 nsURL_GetFileName,
2183 nsURL_SetFileName,
2184 nsURL_GetFileBaseName,
2185 nsURL_SetFileBaseName,
2186 nsURL_GetFileExtension,
2187 nsURL_SetFileExtension,
2188 nsURL_GetCommonBaseSpec,
2189 nsURL_GetRelativeSpec
2192 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2194 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2196 ret->lpIURLVtbl = &nsURLVtbl;
2197 ret->ref = 1;
2198 ret->uri = uri;
2200 set_uri_nscontainer(ret, container);
2201 set_uri_window(ret, window);
2203 if(uri)
2204 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2206 TRACE("retval=%p\n", ret);
2207 *_retval = ret;
2208 return NS_OK;
2211 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2213 nsWineURI *uri;
2214 nsresult nsres;
2216 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2217 if(NS_FAILED(nsres))
2218 return E_FAIL;
2220 set_wine_url(uri, url);
2221 uri->is_doc_uri = TRUE;
2223 *ret = uri;
2224 return S_OK;
2227 typedef struct {
2228 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2230 LONG ref;
2232 nsIProtocolHandler *nshandler;
2233 } nsProtocolHandler;
2235 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2237 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2239 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2240 nsQIResult result)
2242 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2244 *result = NULL;
2246 if(IsEqualGUID(&IID_nsISupports, riid)) {
2247 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2248 *result = NSPROTHANDLER(This);
2249 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2250 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2251 *result = NSPROTHANDLER(This);
2252 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2253 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2254 return NS_NOINTERFACE;
2257 if(*result) {
2258 nsISupports_AddRef((nsISupports*)*result);
2259 return NS_OK;
2262 WARN("(%s %p)\n", debugstr_guid(riid), result);
2263 return NS_NOINTERFACE;
2266 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2268 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2269 LONG ref = InterlockedIncrement(&This->ref);
2271 TRACE("(%p) ref=%d\n", This, ref);
2273 return ref;
2276 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2278 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2279 LONG ref = InterlockedDecrement(&This->ref);
2281 TRACE("(%p) ref=%d\n", This, ref);
2283 if(!ref) {
2284 if(This->nshandler)
2285 nsIProtocolHandler_Release(This->nshandler);
2286 heap_free(This);
2289 return ref;
2292 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2294 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2296 TRACE("(%p)->(%p)\n", This, aScheme);
2298 if(This->nshandler)
2299 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2300 return NS_ERROR_NOT_IMPLEMENTED;
2303 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2304 PRInt32 *aDefaultPort)
2306 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2308 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2310 if(This->nshandler)
2311 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2312 return NS_ERROR_NOT_IMPLEMENTED;
2315 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2316 PRUint32 *aProtocolFlags)
2318 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2320 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2322 if(This->nshandler)
2323 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2324 return NS_ERROR_NOT_IMPLEMENTED;
2327 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2328 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2330 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2332 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2334 if(This->nshandler)
2335 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2336 return NS_ERROR_NOT_IMPLEMENTED;
2339 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2340 nsIURI *aURI, nsIChannel **_retval)
2342 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2344 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2346 if(This->nshandler)
2347 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2348 return NS_ERROR_NOT_IMPLEMENTED;
2351 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2352 PRInt32 port, const char *scheme, PRBool *_retval)
2354 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2356 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2358 if(This->nshandler)
2359 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2360 return NS_ERROR_NOT_IMPLEMENTED;
2363 #undef NSPROTHANDLER_THIS
2365 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2366 nsProtocolHandler_QueryInterface,
2367 nsProtocolHandler_AddRef,
2368 nsProtocolHandler_Release,
2369 nsProtocolHandler_GetScheme,
2370 nsProtocolHandler_GetDefaultPort,
2371 nsProtocolHandler_GetProtocolFlags,
2372 nsProtocolHandler_NewURI,
2373 nsProtocolHandler_NewChannel,
2374 nsProtocolHandler_AllowPort
2377 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2379 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2381 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2382 ret->ref = 1;
2383 ret->nshandler = nshandler;
2385 return NSPROTHANDLER(ret);
2388 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2390 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2392 return 2;
2395 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2397 return 1;
2400 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2401 nsIProtocolHandler **_retval)
2403 nsIExternalProtocolHandler *nsexthandler;
2404 nsIProtocolHandler *nshandler;
2405 nsresult nsres;
2407 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2409 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2410 if(NS_FAILED(nsres)) {
2411 WARN("GetProtocolHandler failed: %08x\n", nsres);
2412 return nsres;
2415 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2416 (void**)&nsexthandler);
2417 if(NS_FAILED(nsres)) {
2418 *_retval = nshandler;
2419 return NS_OK;
2422 nsIExternalProtocolHandler_Release(nsexthandler);
2423 *_retval = create_protocol_handler(nshandler);
2424 TRACE("return %p\n", *_retval);
2425 return NS_OK;
2428 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2429 PRUint32 *_retval)
2431 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2432 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2435 static BOOL is_gecko_special_uri(const char *spec)
2437 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2438 int i;
2440 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2441 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2442 return TRUE;
2445 return FALSE;
2448 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2449 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2451 nsWineURI *wine_uri, *base_wine_uri = NULL;
2452 const char *spec = NULL;
2453 HTMLWindow *window = NULL;
2454 nsIURI *uri = NULL;
2455 LPCWSTR base_wine_url = NULL;
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 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2489 if(NS_FAILED(nsres))
2490 TRACE("NewURI failed: %08x\n", nsres);
2492 nsres = create_uri(uri, window, NULL, &wine_uri);
2493 *_retval = (nsIURI*)wine_uri;
2495 if(window)
2496 IHTMLWindow2_Release(HTMLWINDOW2(window));
2498 if(base_wine_url) {
2499 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2500 DWORD len;
2501 HRESULT hres;
2503 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2505 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2506 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2507 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2508 if(SUCCEEDED(hres))
2509 set_wine_url(wine_uri, url);
2510 else
2511 WARN("CoCombineUrl failed: %08x\n", hres);
2512 }else {
2513 WCHAR url[INTERNET_MAX_URL_LENGTH];
2515 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2516 set_wine_url(wine_uri, url);
2519 if(base_wine_uri)
2520 nsIURI_Release(NSURI(base_wine_uri));
2522 return nsres;
2525 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2526 nsIURI **_retval)
2528 TRACE("(%p %p)\n", aFile, _retval);
2529 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2532 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2533 nsIChannel **_retval)
2535 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2536 nsChannel *ret;
2537 nsWineURI *wine_uri;
2538 nsresult nsres;
2540 TRACE("(%p %p)\n", aURI, _retval);
2542 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2543 if(NS_FAILED(nsres)) {
2544 TRACE("Could not get nsWineURI: %08x\n", nsres);
2545 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2548 ret = heap_alloc_zero(sizeof(nsChannel));
2550 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2551 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2552 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2553 ret->ref = 1;
2554 ret->uri = wine_uri;
2555 list_init(&ret->response_headers);
2557 nsIURI_AddRef(aURI);
2558 ret->original_uri = aURI;
2559 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2560 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2562 *_retval = NSCHANNEL(ret);
2563 return NS_OK;
2566 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2567 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2569 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2570 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2573 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2575 TRACE("(%p)\n", aOffline);
2576 return nsIIOService_GetOffline(nsio, aOffline);
2579 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2581 TRACE("(%x)\n", aOffline);
2582 return nsIIOService_SetOffline(nsio, aOffline);
2585 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2586 const char *aScheme, PRBool *_retval)
2588 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2589 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2592 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2593 nsACString * _retval)
2595 TRACE("(%p %p)\n", urlString, _retval);
2596 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2599 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2600 nsIOService_QueryInterface,
2601 nsIOService_AddRef,
2602 nsIOService_Release,
2603 nsIOService_GetProtocolHandler,
2604 nsIOService_GetProtocolFlags,
2605 nsIOService_NewURI,
2606 nsIOService_NewFileURI,
2607 nsIOService_NewChannelFromURI,
2608 nsIOService_NewChannel,
2609 nsIOService_GetOffline,
2610 nsIOService_SetOffline,
2611 nsIOService_AllowPort,
2612 nsIOService_ExtractScheme
2615 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2617 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2618 nsQIResult result)
2620 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2623 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2625 return 2;
2628 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2630 return 1;
2633 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2634 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2636 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2638 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2641 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2643 TRACE("()\n");
2645 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2648 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2650 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2652 if(aFlags == (1<<11)) {
2653 *_retval = FALSE;
2654 return NS_OK;
2657 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2660 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2662 TRACE("(%p %p)\n", aURI, _retval);
2664 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2667 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2668 PRUint32 aEscapeType, nsACString *_retval)
2670 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2672 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2675 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2676 nsACString *_retval)
2678 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2680 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2683 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2684 PRUint32 aFlags, nsACString *_retval)
2686 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2688 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2691 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2692 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2694 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2696 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2699 static const nsINetUtilVtbl nsNetUtilVtbl = {
2700 nsNetUtil_QueryInterface,
2701 nsNetUtil_AddRef,
2702 nsNetUtil_Release,
2703 nsNetUtil_ParseContentType,
2704 nsNetUtil_ProtocolHasFlags,
2705 nsNetUtil_URIChainHasFlags,
2706 nsNetUtil_ToImmutableURI,
2707 nsNetUtil_EscapeString,
2708 nsNetUtil_EscapeURL,
2709 nsNetUtil_UnescapeString,
2710 nsNetUtil_ExtractCharsetFromContentType
2713 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2715 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2716 nsQIResult result)
2718 *result = NULL;
2720 if(IsEqualGUID(&IID_nsISupports, riid))
2721 *result = &nsIOService;
2722 else if(IsEqualGUID(&IID_nsIIOService, riid))
2723 *result = &nsIOService;
2724 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2725 *result = &nsNetUtil;
2727 if(*result) {
2728 nsISupports_AddRef((nsISupports*)*result);
2729 return NS_OK;
2732 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2733 return NS_NOINTERFACE;
2736 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2737 nsQIResult result)
2739 *result = NULL;
2741 if(IsEqualGUID(&IID_nsISupports, riid)) {
2742 TRACE("(IID_nsISupports %p)\n", result);
2743 *result = iface;
2744 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2745 TRACE("(IID_nsIFactory %p)\n", result);
2746 *result = iface;
2749 if(*result) {
2750 nsIFactory_AddRef(iface);
2751 return NS_OK;
2754 WARN("(%s %p)\n", debugstr_guid(riid), result);
2755 return NS_NOINTERFACE;
2758 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2760 return 2;
2763 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2765 return 1;
2768 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2769 nsISupports *aOuter, const nsIID *iid, void **result)
2771 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2774 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2776 WARN("(%x)\n", lock);
2777 return NS_OK;
2780 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2781 nsIOServiceFactory_QueryInterface,
2782 nsIOServiceFactory_AddRef,
2783 nsIOServiceFactory_Release,
2784 nsIOServiceFactory_CreateInstance,
2785 nsIOServiceFactory_LockFactory
2788 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2790 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2792 nsIFactory *old_factory = NULL;
2793 nsresult nsres;
2795 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2796 &IID_nsIFactory, (void**)&old_factory);
2797 if(NS_FAILED(nsres)) {
2798 ERR("Could not get factory: %08x\n", nsres);
2799 return;
2802 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2803 if(NS_FAILED(nsres)) {
2804 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2805 nsIFactory_Release(old_factory);
2806 return;
2809 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2810 if(NS_FAILED(nsres)) {
2811 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2812 nsIIOService_Release(nsio);
2813 return;
2816 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2817 nsIFactory_Release(old_factory);
2818 if(NS_FAILED(nsres))
2819 ERR("UnregisterFactory failed: %08x\n", nsres);
2821 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2822 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2823 if(NS_FAILED(nsres))
2824 ERR("RegisterFactory failed: %08x\n", nsres);
2827 void release_nsio(void)
2829 if(net_util) {
2830 nsINetUtil_Release(net_util);
2831 net_util = NULL;
2834 if(nsio) {
2835 nsIIOService_Release(nsio);
2836 nsio = NULL;