2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID =
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static const IID IID_nsWineURI =
47 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
49 static nsIIOService *nsio = NULL;
50 static nsINetUtil *net_util;
52 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
54 static const char *request_method_strings[] = {"GET", "PUT", "POST"};
57 const nsIURLVtbl *lpIURLVtbl;
63 NSContainer *container;
64 windowref_t *window_ref;
65 nsChannelBSC *channel_bsc;
71 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
72 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
74 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
76 static const char *debugstr_nsacstr(const nsACString *nsstr)
80 nsACString_GetData(nsstr, &data);
81 return debugstr_a(data);
84 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
86 const WCHAR *ptr = nsuri;
88 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
90 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
91 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
93 if(*ptr || ret_empty) {
94 *ret = SysAllocString(ptr);
101 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
105 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
107 IOleCommandTarget *cmdtrg = NULL;
110 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
111 if(SUCCEEDED(hres)) {
112 VARIANT varUrl, varRes;
114 V_VT(&varUrl) = VT_BSTR;
115 V_BSTR(&varUrl) = SysAllocString(url);
116 V_VT(&varRes) = VT_BOOL;
118 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
120 IOleCommandTarget_Release(cmdtrg);
121 SysFreeString(V_BSTR(&varUrl));
123 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
124 TRACE("got VARIANT_FALSE, do not load\n");
132 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
134 HTMLDocumentObj *doc = container->doc;
140 NSContainer *container_iter = container;
142 hlnf = HLNF_OPENINNEWWINDOW;
143 while(!container_iter->doc)
144 container_iter = container_iter->parent;
145 doc = container_iter->doc;
151 if(!hlnf && !exec_shldocvw_67(doc, channel->uri->wine_url))
154 hres = hlink_frame_navigate(&doc->basedoc, channel->uri->wine_url, channel->post_data_stream, hlnf, &cancel);
155 return FAILED(hres) || cancel;
158 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
160 nsIWebNavigation *web_navigation;
161 nsIDocShell *doc_shell;
162 HTMLDocumentNode *doc;
165 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
166 if(NS_FAILED(nsres)) {
167 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
171 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
172 nsIWebNavigation_Release(web_navigation);
173 if(NS_FAILED(nsres)) {
174 ERR("Could not get nsIDocShell: %08x\n", nsres);
178 uri->channel_bsc = channelbsc;
180 doc->skip_mutation_notif = TRUE;
181 nsres = nsIDocShell_LoadURI(doc_shell, NSURI(uri), NULL, flags, FALSE);
182 if(doc == window->doc)
183 doc->skip_mutation_notif = FALSE;
184 uri->channel_bsc = NULL;
185 nsIDocShell_Release(doc_shell);
186 if(NS_FAILED(nsres)) {
187 WARN("LoadURI failed: %08x\n", nsres);
194 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
196 OLECHAR *new_url = NULL, *url;
203 url = heap_strdupW(uri->wine_url);
204 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
205 if(hres == S_OK && new_url) {
206 if(strcmpW(url, new_url)) {
207 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
210 CoTaskMemFree(new_url);
217 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
224 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
225 if(NS_FAILED(nsres)) {
226 WARN("Could not get nsWineURI: %08x\n", nsres);
227 return NS_ERROR_NOT_IMPLEMENTED;
230 if(!wine_uri->is_doc_uri) {
231 wine_uri->is_doc_uri = TRUE;
233 if(!wine_uri->container) {
234 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
235 wine_uri->container = nscontainer;
239 *_retval = translate_url(nscontainer->doc, wine_uri);
242 nsIURI_Release(NSURI(wine_uri));
246 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
248 static const WCHAR wszFtp[] = {'f','t','p',':'};
249 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
250 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
252 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
257 new_url = heap_strdupW(url);
259 return E_OUTOFMEMORY;
260 heap_free(This->wine_url);
261 This->wine_url = new_url;
264 /* FIXME: Always use wine url */
266 strncmpW(url, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
267 && strncmpW(url, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
268 && strncmpW(url, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
270 This->use_wine_url = TRUE;
273 heap_free(This->wine_url);
274 This->wine_url = NULL;
275 This->use_wine_url = FALSE;
281 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
283 if(This->container) {
284 if(This->container == nscontainer)
286 TRACE("Changing %p -> %p\n", This->container, nscontainer);
287 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
291 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
292 This->container = nscontainer;
295 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
297 if(This->window_ref) {
298 if(This->window_ref->window == window)
300 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
301 windowref_release(This->window_ref);
305 windowref_addref(window->window_ref);
306 This->window_ref = window->window_ref;
309 set_uri_nscontainer(This, window->doc_obj->nscontainer);
311 This->window_ref = NULL;
315 static inline BOOL is_http_channel(nsChannel *This)
317 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTPS;
320 static http_header_t *find_http_header(struct list *headers, const WCHAR *name, int len)
324 LIST_FOR_EACH_ENTRY(iter, headers, http_header_t, entry) {
325 if(!strcmpiW(iter->header, name))
332 static nsresult get_channel_http_header(struct list *headers, const nsACString *header_name_str,
335 const char *header_namea;
336 http_header_t *header;
340 nsACString_GetData(header_name_str, &header_namea);
341 header_name = heap_strdupAtoW(header_namea);
343 return NS_ERROR_UNEXPECTED;
345 header = find_http_header(headers, header_name, strlenW(header_name));
346 heap_free(header_name);
348 return NS_ERROR_NOT_AVAILABLE;
350 data = heap_strdupWtoA(header->data);
352 return NS_ERROR_UNEXPECTED;
354 nsACString_SetData(_retval, data);
359 HRESULT set_http_header(struct list *headers, const WCHAR *name, int name_len,
360 const WCHAR *value, int value_len)
362 http_header_t *header;
364 TRACE("%s: %s\n", debugstr_wn(name, name_len), debugstr_wn(value, value_len));
366 header = find_http_header(headers, name, name_len);
370 new_data = heap_strndupW(value, value_len);
372 return E_OUTOFMEMORY;
374 heap_free(header->data);
375 header->data = new_data;
377 header = heap_alloc(sizeof(http_header_t));
379 return E_OUTOFMEMORY;
381 header->header = heap_strndupW(name, name_len);
382 header->data = heap_strndupW(value, value_len);
383 if(!header->header || !header->data) {
384 heap_free(header->header);
385 heap_free(header->data);
387 return E_OUTOFMEMORY;
390 list_add_tail(headers, &header->entry);
396 static nsresult set_channel_http_header(struct list *headers, const nsACString *name_str,
397 const nsACString *value_str)
399 const char *namea, *valuea;
403 nsACString_GetData(name_str, &namea);
404 name = heap_strdupAtoW(namea);
406 return NS_ERROR_UNEXPECTED;
408 nsACString_GetData(value_str, &valuea);
409 value = heap_strdupAtoW(valuea);
412 return NS_ERROR_UNEXPECTED;
415 hres = set_http_header(headers, name, strlenW(name), value, strlenW(value));
419 return SUCCEEDED(hres) ? NS_OK : NS_ERROR_UNEXPECTED;
422 static void free_http_headers(struct list *list)
424 http_header_t *iter, *iter_next;
426 LIST_FOR_EACH_ENTRY_SAFE(iter, iter_next, list, http_header_t, entry) {
427 list_remove(&iter->entry);
428 heap_free(iter->header);
429 heap_free(iter->data);
434 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
436 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, void **result)
438 nsChannel *This = NSCHANNEL_THIS(iface);
440 if(IsEqualGUID(&IID_nsISupports, riid)) {
441 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
442 *result = NSCHANNEL(This);
443 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
444 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
445 *result = NSCHANNEL(This);
446 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
447 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
448 *result = NSCHANNEL(This);
449 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
450 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
451 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
452 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
453 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
454 *result = NSUPCHANNEL(This);
455 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
456 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
457 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
459 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
464 nsIChannel_AddRef(NSCHANNEL(This));
468 return NS_NOINTERFACE;
471 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
473 nsChannel *This = NSCHANNEL_THIS(iface);
474 nsrefcnt ref = InterlockedIncrement(&This->ref);
476 TRACE("(%p) ref=%d\n", This, ref);
481 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
483 nsChannel *This = NSCHANNEL_THIS(iface);
484 LONG ref = InterlockedDecrement(&This->ref);
487 nsIURI_Release(NSURI(This->uri));
489 nsISupports_Release(This->owner);
490 if(This->post_data_stream)
491 nsIInputStream_Release(This->post_data_stream);
493 nsILoadGroup_Release(This->load_group);
494 if(This->notif_callback)
495 nsIInterfaceRequestor_Release(This->notif_callback);
496 if(This->original_uri)
497 nsIURI_Release(This->original_uri);
499 nsIURI_Release(This->referrer);
501 free_http_headers(&This->response_headers);
502 free_http_headers(&This->request_headers);
504 heap_free(This->content_type);
505 heap_free(This->charset);
512 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
514 nsChannel *This = NSCHANNEL_THIS(iface);
516 TRACE("(%p)->(%p)\n", This, aName);
518 return nsIURI_GetSpec(NSURI(This->uri), aName);
521 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
523 nsChannel *This = NSCHANNEL_THIS(iface);
525 FIXME("(%p)->(%p)\n", This, _retval);
527 return NS_ERROR_NOT_IMPLEMENTED;
530 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
532 nsChannel *This = NSCHANNEL_THIS(iface);
534 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
536 return *aStatus = NS_OK;
539 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
541 nsChannel *This = NSCHANNEL_THIS(iface);
543 FIXME("(%p)->(%08x)\n", This, aStatus);
545 return NS_ERROR_NOT_IMPLEMENTED;
548 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
550 nsChannel *This = NSCHANNEL_THIS(iface);
552 FIXME("(%p)\n", This);
554 return NS_ERROR_NOT_IMPLEMENTED;
557 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
559 nsChannel *This = NSCHANNEL_THIS(iface);
561 FIXME("(%p)\n", This);
563 return NS_ERROR_NOT_IMPLEMENTED;
566 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
568 nsChannel *This = NSCHANNEL_THIS(iface);
570 TRACE("(%p)->(%p)\n", This, aLoadGroup);
573 nsILoadGroup_AddRef(This->load_group);
575 *aLoadGroup = This->load_group;
579 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
581 nsChannel *This = NSCHANNEL_THIS(iface);
583 TRACE("(%p)->(%p)\n", This, aLoadGroup);
586 nsILoadGroup_Release(This->load_group);
588 nsILoadGroup_AddRef(aLoadGroup);
589 This->load_group = aLoadGroup;
594 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
596 nsChannel *This = NSCHANNEL_THIS(iface);
598 TRACE("(%p)->(%p)\n", This, aLoadFlags);
600 *aLoadFlags = This->load_flags;
604 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
606 nsChannel *This = NSCHANNEL_THIS(iface);
608 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
610 This->load_flags = aLoadFlags;
614 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
616 nsChannel *This = NSCHANNEL_THIS(iface);
618 TRACE("(%p)->(%p)\n", This, aOriginalURI);
620 if(This->original_uri)
621 nsIURI_AddRef(This->original_uri);
623 *aOriginalURI = This->original_uri;
627 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
629 nsChannel *This = NSCHANNEL_THIS(iface);
631 TRACE("(%p)->(%p)\n", This, aOriginalURI);
633 if(This->original_uri)
634 nsIURI_Release(This->original_uri);
636 nsIURI_AddRef(aOriginalURI);
637 This->original_uri = aOriginalURI;
641 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
643 nsChannel *This = NSCHANNEL_THIS(iface);
645 TRACE("(%p)->(%p)\n", This, aURI);
647 nsIURI_AddRef(NSURI(This->uri));
648 *aURI = (nsIURI*)This->uri;
653 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
655 nsChannel *This = NSCHANNEL_THIS(iface);
657 TRACE("(%p)->(%p)\n", This, aOwner);
660 nsISupports_AddRef(This->owner);
661 *aOwner = This->owner;
666 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
668 nsChannel *This = NSCHANNEL_THIS(iface);
670 TRACE("(%p)->(%p)\n", This, aOwner);
673 nsISupports_AddRef(aOwner);
675 nsISupports_Release(This->owner);
676 This->owner = aOwner;
681 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
682 nsIInterfaceRequestor **aNotificationCallbacks)
684 nsChannel *This = NSCHANNEL_THIS(iface);
686 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
688 if(This->notif_callback)
689 nsIInterfaceRequestor_AddRef(This->notif_callback);
690 *aNotificationCallbacks = This->notif_callback;
695 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
696 nsIInterfaceRequestor *aNotificationCallbacks)
698 nsChannel *This = NSCHANNEL_THIS(iface);
700 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
702 if(This->notif_callback)
703 nsIInterfaceRequestor_Release(This->notif_callback);
704 if(aNotificationCallbacks)
705 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
707 This->notif_callback = aNotificationCallbacks;
712 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
714 nsChannel *This = NSCHANNEL_THIS(iface);
716 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
718 return NS_ERROR_NOT_IMPLEMENTED;
721 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
723 nsChannel *This = NSCHANNEL_THIS(iface);
725 TRACE("(%p)->(%p)\n", This, aContentType);
727 if(This->content_type) {
728 nsACString_SetData(aContentType, This->content_type);
732 WARN("unknown type\n");
733 return NS_ERROR_FAILURE;
736 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
737 const nsACString *aContentType)
739 nsChannel *This = NSCHANNEL_THIS(iface);
740 const char *content_type;
742 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aContentType));
744 nsACString_GetData(aContentType, &content_type);
745 heap_free(This->content_type);
746 This->content_type = heap_strdupA(content_type);
751 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
752 nsACString *aContentCharset)
754 nsChannel *This = NSCHANNEL_THIS(iface);
756 TRACE("(%p)->(%p)\n", This, aContentCharset);
759 nsACString_SetData(aContentCharset, This->charset);
763 nsACString_SetData(aContentCharset, "");
767 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
768 const nsACString *aContentCharset)
770 nsChannel *This = NSCHANNEL_THIS(iface);
772 FIXME("(%p)->(%s)\n", This, debugstr_nsacstr(aContentCharset));
774 return NS_ERROR_NOT_IMPLEMENTED;
777 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
779 nsChannel *This = NSCHANNEL_THIS(iface);
781 FIXME("(%p)->(%p)\n", This, aContentLength);
783 return NS_ERROR_NOT_IMPLEMENTED;
786 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
788 nsChannel *This = NSCHANNEL_THIS(iface);
790 FIXME("(%p)->(%d)\n", This, aContentLength);
792 return NS_ERROR_NOT_IMPLEMENTED;
795 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
797 nsChannel *This = NSCHANNEL_THIS(iface);
799 FIXME("(%p)->(%p)\n", This, _retval);
801 return NS_ERROR_NOT_IMPLEMENTED;
804 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
810 if(!channel->original_uri) {
811 ERR("original_uri == NULL\n");
815 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsWineURI, (void**)&wine_uri);
816 if(NS_FAILED(nsres)) {
817 ERR("Could not get nsWineURI: %08x\n", nsres);
821 if(wine_uri->wine_url) {
822 hres = CreateURLMoniker(NULL, wine_uri->wine_url, mon);
824 WARN("CreateURLMoniker failed: %08x\n", hres);
826 TRACE("wine_url == NULL\n");
830 nsIURI_Release(NSURI(wine_uri));
835 static HTMLWindow *get_window_from_load_group(nsChannel *This)
844 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
845 if(NS_FAILED(nsres)) {
846 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
853 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
854 nsIRequest_Release(req);
855 if(NS_FAILED(nsres)) {
856 WARN("Could not get nsIChannel interface: %08x\n", nsres);
860 nsres = nsIChannel_GetURI(channel, &uri);
861 nsIChannel_Release(channel);
862 if(NS_FAILED(nsres)) {
863 ERR("GetURI failed: %08x\n", nsres);
867 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
869 if(NS_FAILED(nsres)) {
870 TRACE("Could not get nsWineURI: %08x\n", nsres);
874 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
876 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
877 nsIURI_Release(NSURI(wine_uri));
882 static HTMLWindow *get_channel_window(nsChannel *This)
884 nsIRequestObserver *req_observer;
885 nsIWebProgress *web_progress;
886 nsIDOMWindow *nswindow;
890 if(!This->load_group) {
891 ERR("NULL load_group\n");
895 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
896 if(NS_FAILED(nsres) || !req_observer) {
897 ERR("GetGroupObserver failed: %08x\n", nsres);
901 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
902 nsIRequestObserver_Release(req_observer);
903 if(NS_FAILED(nsres)) {
904 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
908 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
909 nsIWebProgress_Release(web_progress);
910 if(NS_FAILED(nsres) || !nswindow) {
911 ERR("GetDOMWindow failed: %08x\n", nsres);
915 window = nswindow_to_window(nswindow);
916 nsIDOMWindow_Release(nswindow);
919 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
921 FIXME("NULL window for %p\n", nswindow);
927 HTMLDocumentNode *doc;
928 nsChannelBSC *bscallback;
929 } start_binding_task_t;
931 static void start_binding_proc(task_t *_task)
933 start_binding_task_t *task = (start_binding_task_t*)_task;
935 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
937 IUnknown_Release((IUnknown*)task->bscallback);
940 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
941 nsISupports *context)
943 nsChannelBSC *bscallback;
944 IMoniker *mon = NULL;
947 hres = create_mon_for_nschannel(This, &mon);
949 return NS_ERROR_UNEXPECTED;
952 set_current_mon(window, mon);
954 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
955 IMoniker_Release(mon);
957 return NS_ERROR_UNEXPECTED;
959 channelbsc_set_channel(bscallback, This, listener, context);
962 set_window_bscallback(window, bscallback);
963 async_start_doc_binding(window, bscallback);
964 IUnknown_Release((IUnknown*)bscallback);
966 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
968 task->doc = window->doc;
969 task->bscallback = bscallback;
970 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
976 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
977 nsISupports *aContext)
979 nsChannel *This = NSCHANNEL_THIS(iface);
980 HTMLWindow *window = NULL;
982 nsresult nsres = NS_OK;
984 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
986 if(This->uri->is_doc_uri) {
987 window = get_channel_window(This);
989 set_uri_window(This->uri, window);
990 }else if(This->uri->container) {
993 /* nscontainer->doc should be NULL which means navigation to a new window */
994 if(This->uri->container->doc)
995 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
997 b = before_async_open(This, This->uri->container);
999 FIXME("Navigation not cancelled\n");
1000 return NS_ERROR_UNEXPECTED;
1005 if(This->uri->window_ref && This->uri->window_ref->window) {
1006 window = This->uri->window_ref->window;
1007 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
1008 }else if(This->load_group) {
1009 window = get_window_from_load_group(This);
1011 set_uri_window(This->uri, window);
1016 ERR("window = NULL\n");
1017 return NS_ERROR_UNEXPECTED;
1020 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
1021 if(This->uri->channel_bsc) {
1022 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
1024 if(window->doc_obj->mime) {
1025 heap_free(This->content_type);
1026 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
1031 open = !before_async_open(This, window->doc_obj->nscontainer);
1033 TRACE("canceled\n");
1034 nsres = NS_ERROR_UNEXPECTED;
1040 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
1042 if(NS_SUCCEEDED(nsres) && This->load_group) {
1043 nsres = nsILoadGroup_AddRequest(This->load_group, (nsIRequest*)NSCHANNEL(This), aContext);
1044 if(NS_FAILED(nsres))
1045 ERR("AddRequest failed: %08x\n", nsres);
1048 IHTMLWindow2_Release(HTMLWINDOW2(window));
1052 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
1054 nsChannel *This = NSCHANNEL_THIS(iface);
1056 TRACE("(%p)->(%p)\n", This, aRequestMethod);
1058 nsACString_SetData(aRequestMethod, request_method_strings[This->request_method]);
1062 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
1063 const nsACString *aRequestMethod)
1065 nsChannel *This = NSCHANNEL_THIS(iface);
1069 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRequestMethod));
1071 nsACString_GetData(aRequestMethod, &method);
1072 for(i=0; i < sizeof(request_method_strings)/sizeof(*request_method_strings); i++) {
1073 if(!strcasecmp(method, request_method_strings[i])) {
1074 This->request_method = i;
1079 ERR("Invalid method %s\n", debugstr_a(method));
1080 return NS_ERROR_UNEXPECTED;
1083 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
1085 nsChannel *This = NSCHANNEL_THIS(iface);
1087 TRACE("(%p)->(%p)\n", This, aReferrer);
1090 nsIURI_AddRef(This->referrer);
1091 *aReferrer = This->referrer;
1095 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
1097 nsChannel *This = NSCHANNEL_THIS(iface);
1099 TRACE("(%p)->(%p)\n", This, aReferrer);
1102 nsIURI_AddRef(aReferrer);
1104 nsIURI_Release(This->referrer);
1105 This->referrer = aReferrer;
1109 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
1110 const nsACString *aHeader, nsACString *_retval)
1112 nsChannel *This = NSCHANNEL_THIS(iface);
1114 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aHeader), _retval);
1116 return get_channel_http_header(&This->request_headers, aHeader, _retval);
1119 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
1120 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
1122 nsChannel *This = NSCHANNEL_THIS(iface);
1124 TRACE("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(aHeader), debugstr_nsacstr(aValue), aMerge);
1127 FIXME("aMerge not supported\n");
1129 return set_channel_http_header(&This->request_headers, aHeader, aValue);
1132 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
1133 nsIHttpHeaderVisitor *aVisitor)
1135 nsChannel *This = NSCHANNEL_THIS(iface);
1137 FIXME("(%p)->(%p)\n", This, aVisitor);
1139 return NS_ERROR_NOT_IMPLEMENTED;
1142 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1144 nsChannel *This = NSCHANNEL_THIS(iface);
1146 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1148 return NS_ERROR_NOT_IMPLEMENTED;
1151 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1153 nsChannel *This = NSCHANNEL_THIS(iface);
1155 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1157 return NS_ERROR_NOT_IMPLEMENTED;
1160 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1162 nsChannel *This = NSCHANNEL_THIS(iface);
1164 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1166 return NS_ERROR_NOT_IMPLEMENTED;
1169 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1171 nsChannel *This = NSCHANNEL_THIS(iface);
1173 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1175 return NS_ERROR_NOT_IMPLEMENTED;
1178 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1180 nsChannel *This = NSCHANNEL_THIS(iface);
1182 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1184 if(This->response_status) {
1185 *aResponseStatus = This->response_status;
1189 WARN("No response status\n");
1190 return NS_ERROR_UNEXPECTED;
1193 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1194 nsACString *aResponseStatusText)
1196 nsChannel *This = NSCHANNEL_THIS(iface);
1198 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1200 return NS_ERROR_NOT_IMPLEMENTED;
1203 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1204 PRBool *aRequestSucceeded)
1206 nsChannel *This = NSCHANNEL_THIS(iface);
1208 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1210 if(!This->response_status)
1211 return NS_ERROR_NOT_AVAILABLE;
1213 *aRequestSucceeded = This->response_status/100 == 2;
1218 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1219 const nsACString *header, nsACString *_retval)
1221 nsChannel *This = NSCHANNEL_THIS(iface);
1223 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(header), _retval);
1225 return get_channel_http_header(&This->response_headers, header, _retval);
1228 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1229 const nsACString *header, const nsACString *value, PRBool merge)
1231 nsChannel *This = NSCHANNEL_THIS(iface);
1233 FIXME("(%p)->(%s %s %x)\n", This, debugstr_nsacstr(header), debugstr_nsacstr(value), merge);
1235 return NS_ERROR_NOT_IMPLEMENTED;
1238 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1239 nsIHttpHeaderVisitor *aVisitor)
1241 nsChannel *This = NSCHANNEL_THIS(iface);
1243 FIXME("(%p)->(%p)\n", This, aVisitor);
1245 return NS_ERROR_NOT_IMPLEMENTED;
1248 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1250 nsChannel *This = NSCHANNEL_THIS(iface);
1252 FIXME("(%p)->(%p)\n", This, _retval);
1254 return NS_ERROR_NOT_IMPLEMENTED;
1257 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1259 nsChannel *This = NSCHANNEL_THIS(iface);
1261 FIXME("(%p)->(%p)\n", This, _retval);
1263 return NS_ERROR_NOT_IMPLEMENTED;
1266 #undef NSCHANNEL_THIS
1268 static const nsIHttpChannelVtbl nsChannelVtbl = {
1269 nsChannel_QueryInterface,
1273 nsChannel_IsPending,
1274 nsChannel_GetStatus,
1278 nsChannel_GetLoadGroup,
1279 nsChannel_SetLoadGroup,
1280 nsChannel_GetLoadFlags,
1281 nsChannel_SetLoadFlags,
1282 nsChannel_GetOriginalURI,
1283 nsChannel_SetOriginalURI,
1287 nsChannel_GetNotificationCallbacks,
1288 nsChannel_SetNotificationCallbacks,
1289 nsChannel_GetSecurityInfo,
1290 nsChannel_GetContentType,
1291 nsChannel_SetContentType,
1292 nsChannel_GetContentCharset,
1293 nsChannel_SetContentCharset,
1294 nsChannel_GetContentLength,
1295 nsChannel_SetContentLength,
1297 nsChannel_AsyncOpen,
1298 nsChannel_GetRequestMethod,
1299 nsChannel_SetRequestMethod,
1300 nsChannel_GetReferrer,
1301 nsChannel_SetReferrer,
1302 nsChannel_GetRequestHeader,
1303 nsChannel_SetRequestHeader,
1304 nsChannel_VisitRequestHeaders,
1305 nsChannel_GetAllowPipelining,
1306 nsChannel_SetAllowPipelining,
1307 nsChannel_GetRedirectionLimit,
1308 nsChannel_SetRedirectionLimit,
1309 nsChannel_GetResponseStatus,
1310 nsChannel_GetResponseStatusText,
1311 nsChannel_GetRequestSucceeded,
1312 nsChannel_GetResponseHeader,
1313 nsChannel_SetResponseHeader,
1314 nsChannel_VisitResponseHeaders,
1315 nsChannel_IsNoStoreResponse,
1316 nsChannel_IsNoCacheResponse
1319 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1321 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1324 nsChannel *This = NSUPCHANNEL_THIS(iface);
1325 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1328 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1330 nsChannel *This = NSUPCHANNEL_THIS(iface);
1331 return nsIChannel_AddRef(NSCHANNEL(This));
1334 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1336 nsChannel *This = NSUPCHANNEL_THIS(iface);
1337 return nsIChannel_Release(NSCHANNEL(This));
1340 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1341 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1343 nsChannel *This = NSUPCHANNEL_THIS(iface);
1344 const char *content_type;
1346 static const WCHAR content_typeW[] =
1347 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1349 TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
1351 This->parse_stream = TRUE;
1353 nsACString_GetData(aContentType, &content_type);
1357 ct = heap_strdupAtoW(content_type);
1359 return NS_ERROR_UNEXPECTED;
1361 set_http_header(&This->request_headers, content_typeW,
1362 sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
1364 This->parse_stream = FALSE;
1368 if(This->post_data_stream)
1369 nsIInputStream_Release(This->post_data_stream);
1371 if(aContentLength != -1)
1372 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1374 if(This->post_data_stream)
1375 nsIInputStream_Release(This->post_data_stream);
1376 This->post_data_stream = aStream;
1378 nsIInputStream_AddRef(aStream);
1380 This->request_method = METHOD_POST;
1384 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1385 nsIInputStream **aUploadStream)
1387 nsChannel *This = NSUPCHANNEL_THIS(iface);
1389 TRACE("(%p)->(%p)\n", This, aUploadStream);
1391 if(This->post_data_stream)
1392 nsIInputStream_AddRef(This->post_data_stream);
1394 *aUploadStream = This->post_data_stream;
1398 #undef NSUPCHANNEL_THIS
1400 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1401 nsUploadChannel_QueryInterface,
1402 nsUploadChannel_AddRef,
1403 nsUploadChannel_Release,
1404 nsUploadChannel_SetUploadStream,
1405 nsUploadChannel_GetUploadStream
1408 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1410 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1413 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1414 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1417 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1419 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1420 return nsIChannel_AddRef(NSCHANNEL(This));
1423 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1425 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1426 return nsIChannel_Release(NSCHANNEL(This));
1429 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1431 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1433 FIXME("(%p)->()\n", This);
1435 return NS_ERROR_NOT_IMPLEMENTED;
1438 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1440 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1442 FIXME("(%p)->()\n", This);
1444 return NS_ERROR_NOT_IMPLEMENTED;
1447 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1449 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1451 FIXME("(%p)->()\n", This);
1453 return NS_ERROR_NOT_IMPLEMENTED;
1456 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1458 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1460 FIXME("(%p)->()\n", This);
1462 return NS_ERROR_NOT_IMPLEMENTED;
1465 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1467 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1469 FIXME("(%p)->()\n", This);
1471 return NS_ERROR_NOT_IMPLEMENTED;
1474 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1476 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1478 FIXME("(%p)->()\n", This);
1480 return NS_ERROR_NOT_IMPLEMENTED;
1483 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1485 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1487 FIXME("(%p)->()\n", This);
1489 return NS_ERROR_NOT_IMPLEMENTED;
1492 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1494 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1496 FIXME("(%p)->()\n", This);
1498 return NS_ERROR_NOT_IMPLEMENTED;
1501 #undef NSHTTPINTERNAL_THIS
1503 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1504 nsHttpChannelInternal_QueryInterface,
1505 nsHttpChannelInternal_AddRef,
1506 nsHttpChannelInternal_Release,
1507 nsHttpChannelInternal_GetDocumentURI,
1508 nsHttpChannelInternal_SetDocumentURI,
1509 nsHttpChannelInternal_GetRequestVersion,
1510 nsHttpChannelInternal_GetResponseVersion,
1511 nsHttpChannelInternal_SetCookie,
1512 nsHttpChannelInternal_SetupFallbackChannel,
1513 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1514 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1517 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1519 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, void **result)
1521 nsWineURI *This = NSURI_THIS(iface);
1525 if(IsEqualGUID(&IID_nsISupports, riid)) {
1526 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1527 *result = NSURI(This);
1528 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1529 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1530 *result = NSURI(This);
1531 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1532 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1533 *result = NSURL(This);
1534 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1535 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1540 nsIURI_AddRef(NSURI(This));
1544 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1545 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1548 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1550 nsWineURI *This = NSURI_THIS(iface);
1551 LONG ref = InterlockedIncrement(&This->ref);
1553 TRACE("(%p) ref=%d\n", This, ref);
1558 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1560 nsWineURI *This = NSURI_THIS(iface);
1561 LONG ref = InterlockedDecrement(&This->ref);
1563 TRACE("(%p) ref=%d\n", This, ref);
1566 if(This->window_ref)
1567 windowref_release(This->window_ref);
1569 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1571 nsIURL_Release(This->nsurl);
1573 nsIURI_Release(This->uri);
1574 heap_free(This->wine_url);
1581 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1583 nsWineURI *This = NSURI_THIS(iface);
1585 TRACE("(%p)->(%p)\n", This, aSpec);
1587 if(This->use_wine_url) {
1588 char speca[INTERNET_MAX_URL_LENGTH];
1589 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca, sizeof(speca), NULL, NULL);
1590 nsACString_SetData(aSpec, speca);
1596 return nsIURI_GetSpec(This->uri, aSpec);
1598 TRACE("returning error\n");
1599 return NS_ERROR_NOT_IMPLEMENTED;
1603 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1605 nsWineURI *This = NSURI_THIS(iface);
1607 TRACE("(%p)->(%p)\n", This, debugstr_nsacstr(aSpec));
1610 return nsIURI_SetSpec(This->uri, aSpec);
1612 FIXME("default action not implemented\n");
1613 return NS_ERROR_NOT_IMPLEMENTED;
1616 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1618 nsWineURI *This = NSURI_THIS(iface);
1620 TRACE("(%p)->(%p)\n", This, aPrePath);
1623 return nsIURI_GetPrePath(This->uri, aPrePath);
1625 FIXME("default action not implemented\n");
1626 return NS_ERROR_NOT_IMPLEMENTED;
1629 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1631 nsWineURI *This = NSURI_THIS(iface);
1633 TRACE("(%p)->(%p)\n", This, aScheme);
1635 if(This->use_wine_url) {
1636 char scheme[INTERNET_MAX_SCHEME_LENGTH+1];
1640 ptr = strchrW(This->wine_url, ':');
1642 nsACString_SetData(aScheme, "wine");
1646 len = WideCharToMultiByte(CP_ACP, 0, This->wine_url, ptr-This->wine_url, scheme,
1647 sizeof(scheme), NULL, NULL);
1648 scheme[min(len,sizeof(scheme)-1)] = 0;
1649 nsACString_SetData(aScheme, strcmp(scheme, "about") ? scheme : "wine");
1654 return nsIURI_GetScheme(This->uri, aScheme);
1656 TRACE("returning error\n");
1657 return NS_ERROR_NOT_IMPLEMENTED;
1660 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1662 nsWineURI *This = NSURI_THIS(iface);
1664 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aScheme));
1667 return nsIURI_SetScheme(This->uri, aScheme);
1669 FIXME("default action not implemented\n");
1670 return NS_ERROR_NOT_IMPLEMENTED;
1673 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1675 nsWineURI *This = NSURI_THIS(iface);
1677 TRACE("(%p)->(%p)\n", This, aUserPass);
1680 return nsIURI_GetUserPass(This->uri, aUserPass);
1682 FIXME("default action not implemented\n");
1683 return NS_ERROR_NOT_IMPLEMENTED;
1686 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1688 nsWineURI *This = NSURI_THIS(iface);
1690 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUserPass));
1693 return nsIURI_SetUserPass(This->uri, aUserPass);
1695 FIXME("default action not implemented\n");
1696 return NS_ERROR_NOT_IMPLEMENTED;
1699 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1701 nsWineURI *This = NSURI_THIS(iface);
1703 TRACE("(%p)->(%p)\n", This, aUsername);
1706 return nsIURI_GetUsername(This->uri, aUsername);
1708 FIXME("default action not implemented\n");
1709 return NS_ERROR_NOT_IMPLEMENTED;
1712 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1714 nsWineURI *This = NSURI_THIS(iface);
1716 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aUsername));
1719 return nsIURI_SetUsername(This->uri, aUsername);
1721 FIXME("default action not implemented\n");
1722 return NS_ERROR_NOT_IMPLEMENTED;
1725 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1727 nsWineURI *This = NSURI_THIS(iface);
1729 TRACE("(%p)->(%p)\n", This, aPassword);
1732 return nsIURI_GetPassword(This->uri, aPassword);
1734 FIXME("default action not implemented\n");
1735 return NS_ERROR_NOT_IMPLEMENTED;
1738 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1740 nsWineURI *This = NSURI_THIS(iface);
1742 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPassword));
1745 return nsIURI_SetPassword(This->uri, aPassword);
1747 FIXME("default action not implemented\n");
1748 return NS_ERROR_NOT_IMPLEMENTED;
1751 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1753 nsWineURI *This = NSURI_THIS(iface);
1755 TRACE("(%p)->(%p)\n", This, aHostPort);
1758 return nsIURI_GetHostPort(This->uri, aHostPort);
1760 FIXME("default action not implemented\n");
1761 return NS_ERROR_NOT_IMPLEMENTED;
1764 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1766 nsWineURI *This = NSURI_THIS(iface);
1768 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHostPort));
1771 return nsIURI_SetHostPort(This->uri, aHostPort);
1773 FIXME("default action not implemented\n");
1774 return NS_ERROR_NOT_IMPLEMENTED;
1777 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1779 nsWineURI *This = NSURI_THIS(iface);
1781 TRACE("(%p)->(%p)\n", This, aHost);
1784 return nsIURI_GetHost(This->uri, aHost);
1786 FIXME("default action not implemented\n");
1787 return NS_ERROR_NOT_IMPLEMENTED;
1790 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1792 nsWineURI *This = NSURI_THIS(iface);
1794 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aHost));
1797 return nsIURI_SetHost(This->uri, aHost);
1799 FIXME("default action not implemented\n");
1800 return NS_ERROR_NOT_IMPLEMENTED;
1803 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1805 nsWineURI *This = NSURI_THIS(iface);
1807 TRACE("(%p)->(%p)\n", This, aPort);
1810 return nsIURI_GetPort(This->uri, aPort);
1812 FIXME("default action not implemented\n");
1813 return NS_ERROR_NOT_IMPLEMENTED;
1816 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1818 nsWineURI *This = NSURI_THIS(iface);
1820 TRACE("(%p)->(%d)\n", This, aPort);
1823 return nsIURI_SetPort(This->uri, aPort);
1825 FIXME("default action not implemented\n");
1826 return NS_ERROR_NOT_IMPLEMENTED;
1829 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
1831 nsWineURI *This = NSURI_THIS(iface);
1833 TRACE("(%p)->(%p)\n", This, aPath);
1836 return nsIURI_GetPath(This->uri, aPath);
1838 FIXME("default action not implemented\n");
1839 return NS_ERROR_NOT_IMPLEMENTED;
1842 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
1844 nsWineURI *This = NSURI_THIS(iface);
1847 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aPath));
1849 nsACString_GetData(aPath, &path);
1850 if(This->wine_url) {
1851 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1852 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1856 pathw = heap_strdupAtoW(path);
1857 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1860 set_wine_url(This, new_url);
1862 WARN("UrlCombine failed: %08x\n", hres);
1868 return nsIURI_SetPath(This->uri, aPath);
1871 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
1873 nsWineURI *This = NSURI_THIS(iface);
1874 nsWineURI *wine_uri;
1877 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1880 return nsIURI_Equals(This->uri, other, _retval);
1882 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&wine_uri);
1883 if(NS_FAILED(nsres)) {
1884 TRACE("Could not get nsWineURI interface\n");
1889 *_retval = wine_uri->wine_url && !UrlCompareW(This->wine_url, wine_uri->wine_url, TRUE);
1890 nsIURI_Release(NSURI(wine_uri));
1895 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
1897 nsWineURI *This = NSURI_THIS(iface);
1899 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1901 if(This->use_wine_url) {
1902 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1903 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1905 *_retval = lstrlenW(This->wine_url) > len
1906 && This->wine_url[len] == ':'
1907 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1912 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1914 TRACE("returning error\n");
1915 return NS_ERROR_NOT_IMPLEMENTED;
1918 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
1920 nsWineURI *This = NSURI_THIS(iface);
1921 nsIURI *nsuri = NULL;
1922 nsWineURI *wine_uri;
1925 TRACE("(%p)->(%p)\n", This, _retval);
1928 nsres = nsIURI_Clone(This->uri, &nsuri);
1929 if(NS_FAILED(nsres)) {
1930 WARN("Clone failed: %08x\n", nsres);
1935 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1936 if(NS_FAILED(nsres)) {
1937 WARN("create_uri failed: %08x\n", nsres);
1941 set_wine_url(wine_uri, This->wine_url);
1943 *_retval = NSURI(wine_uri);
1947 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *aRelativePath,
1948 nsACString *_retval)
1950 nsWineURI *This = NSURI_THIS(iface);
1951 WCHAR url[INTERNET_MAX_URL_LENGTH];
1958 TRACE("(%p)->(%s %p)\n", This, debugstr_nsacstr(aRelativePath), _retval);
1961 return nsIURI_Resolve(This->uri, aRelativePath, _retval);
1963 nsACString_GetData(aRelativePath, &patha);
1964 path = heap_strdupAtoW(patha);
1966 return NS_ERROR_OUT_OF_MEMORY;
1968 hres = CoInternetCombineUrl(This->wine_url, path,
1969 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
1970 url, sizeof(url)/sizeof(WCHAR), &len, 0);
1973 ERR("CoIntenetCombineUrl failed: %08x\n", hres);
1974 return NS_ERROR_FAILURE;
1977 urla = heap_strdupWtoA(url);
1979 return NS_ERROR_OUT_OF_MEMORY;
1981 TRACE("returning %s\n", debugstr_a(urla));
1982 nsACString_SetData(_retval, urla);
1987 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
1989 nsWineURI *This = NSURI_THIS(iface);
1991 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1993 if(This->use_wine_url)
1994 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1997 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1999 TRACE("returning error\n");
2000 return NS_ERROR_NOT_IMPLEMENTED;
2003 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
2005 nsWineURI *This = NSURI_THIS(iface);
2007 TRACE("(%p)->(%p)\n", This, aAsciiHost);
2010 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
2012 FIXME("default action not implemented\n");
2013 return NS_ERROR_NOT_IMPLEMENTED;
2016 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
2018 nsWineURI *This = NSURI_THIS(iface);
2020 TRACE("(%p)->(%p)\n", This, aOriginCharset);
2023 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
2025 FIXME("default action not implemented\n");
2026 return NS_ERROR_NOT_IMPLEMENTED;
2029 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
2031 nsWineURI *This = NSURI_THIS(iface);
2033 TRACE("(%p)->(%p)\n", This, aFilePath);
2036 return nsIURL_GetFilePath(This->nsurl, aFilePath);
2038 FIXME("default action not implemented\n");
2039 return NS_ERROR_NOT_IMPLEMENTED;
2042 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
2044 nsWineURI *This = NSURI_THIS(iface);
2046 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
2049 return nsIURL_SetFilePath(This->nsurl, aFilePath);
2051 FIXME("default action not implemented\n");
2052 return NS_ERROR_NOT_IMPLEMENTED;
2055 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
2057 nsWineURI *This = NSURI_THIS(iface);
2059 TRACE("(%p)->(%p)\n", This, aParam);
2062 return nsIURL_GetParam(This->nsurl, aParam);
2064 FIXME("default action not implemented\n");
2065 return NS_ERROR_NOT_IMPLEMENTED;
2068 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
2070 nsWineURI *This = NSURI_THIS(iface);
2072 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
2075 return nsIURL_SetParam(This->nsurl, aParam);
2077 FIXME("default action not implemented\n");
2078 return NS_ERROR_NOT_IMPLEMENTED;
2081 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
2083 nsWineURI *This = NSURI_THIS(iface);
2085 TRACE("(%p)->(%p)\n", This, aQuery);
2088 return nsIURL_GetQuery(This->nsurl, aQuery);
2090 FIXME("default action not implemented\n");
2091 return NS_ERROR_NOT_IMPLEMENTED;
2094 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
2096 nsWineURI *This = NSURI_THIS(iface);
2097 const WCHAR *ptr1, *ptr2;
2099 WCHAR *new_url, *ptr;
2102 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
2105 nsIURL_SetQuery(This->nsurl, aQuery);
2110 nsACString_GetData(aQuery, &query);
2111 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
2112 ptr1 = strchrW(This->wine_url, '?');
2114 size += ptr1-This->wine_url;
2115 ptr2 = strchrW(ptr1, '#');
2117 size += strlenW(ptr2);
2119 ptr1 = This->wine_url + strlenW(This->wine_url);
2121 size += strlenW(This->wine_url);
2127 new_url = heap_alloc(size*sizeof(WCHAR));
2128 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
2129 ptr = new_url + (ptr1-This->wine_url);
2132 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
2140 TRACE("setting %s\n", debugstr_w(new_url));
2142 heap_free(This->wine_url);
2143 This->wine_url = new_url;
2147 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
2149 nsWineURI *This = NSURI_THIS(iface);
2151 TRACE("(%p)->(%p)\n", This, aRef);
2154 return nsIURL_GetRef(This->nsurl, aRef);
2156 FIXME("default action not implemented\n");
2157 return NS_ERROR_NOT_IMPLEMENTED;
2160 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
2162 nsWineURI *This = NSURI_THIS(iface);
2165 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
2168 return nsIURL_SetRef(This->nsurl, aRef);
2170 nsACString_GetData(aRef, &refa);
2174 FIXME("default action not implemented\n");
2175 return NS_ERROR_NOT_IMPLEMENTED;
2178 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
2180 nsWineURI *This = NSURI_THIS(iface);
2182 TRACE("(%p)->(%p)\n", This, aDirectory);
2185 return nsIURL_GetDirectory(This->nsurl, aDirectory);
2187 FIXME("default action not implemented\n");
2188 return NS_ERROR_NOT_IMPLEMENTED;
2191 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2193 nsWineURI *This = NSURI_THIS(iface);
2195 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2198 return nsIURL_SetDirectory(This->nsurl, aDirectory);
2200 FIXME("default action not implemented\n");
2201 return NS_ERROR_NOT_IMPLEMENTED;
2204 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2206 nsWineURI *This = NSURI_THIS(iface);
2208 TRACE("(%p)->(%p)\n", This, aFileName);
2211 return nsIURL_GetFileName(This->nsurl, aFileName);
2213 FIXME("default action not implemented\n");
2214 return NS_ERROR_NOT_IMPLEMENTED;
2217 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2219 nsWineURI *This = NSURI_THIS(iface);
2221 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2224 return nsIURL_SetFileName(This->nsurl, aFileName);
2226 FIXME("default action not implemented\n");
2227 return NS_ERROR_NOT_IMPLEMENTED;
2230 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2232 nsWineURI *This = NSURI_THIS(iface);
2234 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2237 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2239 FIXME("default action not implemented\n");
2240 return NS_ERROR_NOT_IMPLEMENTED;
2243 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2245 nsWineURI *This = NSURI_THIS(iface);
2247 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2250 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2252 FIXME("default action not implemented\n");
2253 return NS_ERROR_NOT_IMPLEMENTED;
2256 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2258 nsWineURI *This = NSURI_THIS(iface);
2260 TRACE("(%p)->(%p)\n", This, aFileExtension);
2263 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2265 FIXME("default action not implemented\n");
2266 return NS_ERROR_NOT_IMPLEMENTED;
2269 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2271 nsWineURI *This = NSURI_THIS(iface);
2273 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2276 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2278 FIXME("default action not implemented\n");
2279 return NS_ERROR_NOT_IMPLEMENTED;
2282 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2284 nsWineURI *This = NSURI_THIS(iface);
2286 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2289 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2291 FIXME("default action not implemented\n");
2292 return NS_ERROR_NOT_IMPLEMENTED;
2295 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2297 nsWineURI *This = NSURI_THIS(iface);
2299 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2302 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2304 FIXME("default action not implemented\n");
2305 return NS_ERROR_NOT_IMPLEMENTED;
2310 static const nsIURLVtbl nsURLVtbl = {
2311 nsURI_QueryInterface,
2339 nsURI_GetOriginCharset,
2352 nsURL_GetFileBaseName,
2353 nsURL_SetFileBaseName,
2354 nsURL_GetFileExtension,
2355 nsURL_SetFileExtension,
2356 nsURL_GetCommonBaseSpec,
2357 nsURL_GetRelativeSpec
2360 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2362 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2364 ret->lpIURLVtbl = &nsURLVtbl;
2368 set_uri_nscontainer(ret, container);
2369 set_uri_window(ret, window);
2372 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2374 TRACE("retval=%p\n", ret);
2379 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2384 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2385 if(NS_FAILED(nsres))
2388 set_wine_url(uri, url);
2389 uri->is_doc_uri = TRUE;
2396 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2400 nsIProtocolHandler *nshandler;
2401 } nsProtocolHandler;
2403 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2405 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2407 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2410 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2414 if(IsEqualGUID(&IID_nsISupports, riid)) {
2415 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2416 *result = NSPROTHANDLER(This);
2417 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2418 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2419 *result = NSPROTHANDLER(This);
2420 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2421 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2422 return NS_NOINTERFACE;
2426 nsISupports_AddRef((nsISupports*)*result);
2430 WARN("(%s %p)\n", debugstr_guid(riid), result);
2431 return NS_NOINTERFACE;
2434 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2436 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2437 LONG ref = InterlockedIncrement(&This->ref);
2439 TRACE("(%p) ref=%d\n", This, ref);
2444 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2446 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2447 LONG ref = InterlockedDecrement(&This->ref);
2449 TRACE("(%p) ref=%d\n", This, ref);
2453 nsIProtocolHandler_Release(This->nshandler);
2460 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2462 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2464 TRACE("(%p)->(%p)\n", This, aScheme);
2467 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2468 return NS_ERROR_NOT_IMPLEMENTED;
2471 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2472 PRInt32 *aDefaultPort)
2474 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2476 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2479 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2480 return NS_ERROR_NOT_IMPLEMENTED;
2483 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2484 PRUint32 *aProtocolFlags)
2486 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2488 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2491 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2492 return NS_ERROR_NOT_IMPLEMENTED;
2495 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2496 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2498 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2500 TRACE("((%p)->%s %s %p %p)\n", This, debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2504 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2505 return NS_ERROR_NOT_IMPLEMENTED;
2508 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2509 nsIURI *aURI, nsIChannel **_retval)
2511 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2513 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2516 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2517 return NS_ERROR_NOT_IMPLEMENTED;
2520 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2521 PRInt32 port, const char *scheme, PRBool *_retval)
2523 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2525 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2528 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2529 return NS_ERROR_NOT_IMPLEMENTED;
2532 #undef NSPROTHANDLER_THIS
2534 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2535 nsProtocolHandler_QueryInterface,
2536 nsProtocolHandler_AddRef,
2537 nsProtocolHandler_Release,
2538 nsProtocolHandler_GetScheme,
2539 nsProtocolHandler_GetDefaultPort,
2540 nsProtocolHandler_GetProtocolFlags,
2541 nsProtocolHandler_NewURI,
2542 nsProtocolHandler_NewChannel,
2543 nsProtocolHandler_AllowPort
2546 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2548 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2550 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2552 ret->nshandler = nshandler;
2554 return NSPROTHANDLER(ret);
2557 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,void**);
2559 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2564 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2569 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2570 nsIProtocolHandler **_retval)
2572 nsIExternalProtocolHandler *nsexthandler;
2573 nsIProtocolHandler *nshandler;
2576 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2578 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2579 if(NS_FAILED(nsres)) {
2580 WARN("GetProtocolHandler failed: %08x\n", nsres);
2584 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2585 (void**)&nsexthandler);
2586 if(NS_FAILED(nsres)) {
2587 *_retval = nshandler;
2591 nsIExternalProtocolHandler_Release(nsexthandler);
2592 *_retval = create_protocol_handler(nshandler);
2593 TRACE("return %p\n", *_retval);
2597 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2600 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2601 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2604 static BOOL is_gecko_special_uri(const char *spec)
2606 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2609 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2610 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2614 if(!strncasecmp(spec, "file:", 5)) {
2615 const char *ptr = spec+5;
2618 return is_gecko_path(ptr);
2624 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2625 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2627 nsWineURI *wine_uri, *base_wine_uri = NULL;
2628 const char *spec = NULL;
2629 HTMLWindow *window = NULL;
2631 LPCWSTR base_wine_url = NULL;
2632 nsACString spec_str;
2636 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset),
2639 nsACString_GetData(aSpec, &spec);
2640 if(is_gecko_special_uri(spec))
2641 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2643 if(!strncmp(spec, "wine:", 5))
2647 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2649 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
2650 if(NS_SUCCEEDED(nsres)) {
2651 base_wine_url = base_wine_uri->wine_url;
2652 if(base_wine_uri->window_ref && base_wine_uri->window_ref->window) {
2653 window = base_wine_uri->window_ref->window;
2654 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2656 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2657 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2658 TRACE("not wraping\n");
2659 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2661 WARN("Could not get base nsWineURI: %08x\n", nsres);
2665 nsACString_InitDepend(&spec_str, spec);
2666 nsres = nsIIOService_NewURI(nsio, &spec_str, aOriginCharset, aBaseURI, &uri);
2667 nsACString_Finish(&spec_str);
2668 if(NS_FAILED(nsres))
2669 TRACE("NewURI failed: %08x\n", nsres);
2671 nsres = create_uri(uri, window, NULL, &wine_uri);
2672 *_retval = (nsIURI*)wine_uri;
2675 IHTMLWindow2_Release(HTMLWINDOW2(window));
2678 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2682 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2684 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2685 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2686 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2688 set_wine_url(wine_uri, url);
2690 WARN("CoCombineUrl failed: %08x\n", hres);
2692 WCHAR url[INTERNET_MAX_URL_LENGTH];
2694 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2695 set_wine_url(wine_uri, url);
2699 nsIURI_Release(NSURI(base_wine_uri));
2704 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2707 TRACE("(%p %p)\n", aFile, _retval);
2708 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2711 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2712 nsIChannel **_retval)
2714 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2716 nsWineURI *wine_uri;
2719 TRACE("(%p %p)\n", aURI, _retval);
2721 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2722 if(NS_FAILED(nsres)) {
2723 TRACE("Could not get nsWineURI: %08x\n", nsres);
2724 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2727 ret = heap_alloc_zero(sizeof(nsChannel));
2729 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2730 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2731 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2733 ret->uri = wine_uri;
2734 ret->request_method = METHOD_GET;
2735 list_init(&ret->response_headers);
2736 list_init(&ret->request_headers);
2738 nsIURI_AddRef(aURI);
2739 ret->original_uri = aURI;
2740 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2741 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2743 *_retval = NSCHANNEL(ret);
2747 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2748 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2750 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec), debugstr_a(aOriginCharset), aBaseURI, _retval);
2751 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2754 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2756 TRACE("(%p)\n", aOffline);
2757 return nsIIOService_GetOffline(nsio, aOffline);
2760 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2762 TRACE("(%x)\n", aOffline);
2763 return nsIIOService_SetOffline(nsio, aOffline);
2766 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2767 const char *aScheme, PRBool *_retval)
2769 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2770 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2773 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2774 nsACString * _retval)
2776 TRACE("(%s %p)\n", debugstr_nsacstr(urlString), _retval);
2777 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2780 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2781 nsIOService_QueryInterface,
2783 nsIOService_Release,
2784 nsIOService_GetProtocolHandler,
2785 nsIOService_GetProtocolFlags,
2787 nsIOService_NewFileURI,
2788 nsIOService_NewChannelFromURI,
2789 nsIOService_NewChannel,
2790 nsIOService_GetOffline,
2791 nsIOService_SetOffline,
2792 nsIOService_AllowPort,
2793 nsIOService_ExtractScheme
2796 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2798 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2801 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2804 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2809 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2814 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2815 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2817 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aHadCharset, aContentType);
2819 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2822 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2826 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2829 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2831 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2833 if(aFlags == (1<<11)) {
2838 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2841 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2843 TRACE("(%p %p)\n", aURI, _retval);
2845 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2848 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2849 PRUint32 aEscapeType, nsACString *_retval)
2851 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString), aEscapeType, _retval);
2853 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2856 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2857 nsACString *_retval)
2859 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
2861 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2864 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2865 PRUint32 aFlags, nsACString *_retval)
2867 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr), aFlags, _retval);
2869 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2872 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2873 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2875 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader), aCharset, aCharsetStart,
2876 aCharsetEnd, _retval);
2878 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2881 static const nsINetUtilVtbl nsNetUtilVtbl = {
2882 nsNetUtil_QueryInterface,
2885 nsNetUtil_ParseContentType,
2886 nsNetUtil_ProtocolHasFlags,
2887 nsNetUtil_URIChainHasFlags,
2888 nsNetUtil_ToImmutableURI,
2889 nsNetUtil_EscapeString,
2890 nsNetUtil_EscapeURL,
2891 nsNetUtil_UnescapeString,
2892 nsNetUtil_ExtractCharsetFromContentType
2895 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2897 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2902 if(IsEqualGUID(&IID_nsISupports, riid))
2903 *result = &nsIOService;
2904 else if(IsEqualGUID(&IID_nsIIOService, riid))
2905 *result = &nsIOService;
2906 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2907 *result = &nsNetUtil;
2910 nsISupports_AddRef((nsISupports*)*result);
2914 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2915 return NS_NOINTERFACE;
2918 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2923 if(IsEqualGUID(&IID_nsISupports, riid)) {
2924 TRACE("(IID_nsISupports %p)\n", result);
2926 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2927 TRACE("(IID_nsIFactory %p)\n", result);
2932 nsIFactory_AddRef(iface);
2936 WARN("(%s %p)\n", debugstr_guid(riid), result);
2937 return NS_NOINTERFACE;
2940 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2945 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2950 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2951 nsISupports *aOuter, const nsIID *iid, void **result)
2953 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2956 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2958 WARN("(%x)\n", lock);
2962 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2963 nsIOServiceFactory_QueryInterface,
2964 nsIOServiceFactory_AddRef,
2965 nsIOServiceFactory_Release,
2966 nsIOServiceFactory_CreateInstance,
2967 nsIOServiceFactory_LockFactory
2970 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2972 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2974 nsIFactory *old_factory = NULL;
2977 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2978 &IID_nsIFactory, (void**)&old_factory);
2979 if(NS_FAILED(nsres)) {
2980 ERR("Could not get factory: %08x\n", nsres);
2984 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2985 if(NS_FAILED(nsres)) {
2986 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2987 nsIFactory_Release(old_factory);
2991 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2992 if(NS_FAILED(nsres)) {
2993 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2994 nsIIOService_Release(nsio);
2998 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2999 nsIFactory_Release(old_factory);
3000 if(NS_FAILED(nsres))
3001 ERR("UnregisterFactory failed: %08x\n", nsres);
3003 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
3004 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
3005 if(NS_FAILED(nsres))
3006 ERR("RegisterFactory failed: %08x\n", nsres);
3009 void release_nsio(void)
3012 nsINetUtil_Release(net_util);
3017 nsIIOService_Release(nsio);