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
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};
55 const nsIURLVtbl *lpIURLVtbl;
61 NSContainer *container;
62 windowref_t *window_ref;
63 nsChannelBSC *channel_bsc;
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)
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);
99 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
103 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
105 IOleCommandTarget *cmdtrg = NULL;
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");
130 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
132 HTMLDocumentObj *doc = container->doc;
137 NSContainer *container_iter = container;
139 hlnf = HLNF_OPENINNEWWINDOW;
140 while(!container_iter->doc)
141 container_iter = container_iter->parent;
142 doc = container_iter->doc;
148 if(!hlnf && !exec_shldocvw_67(doc, channel->uri->wine_url))
151 hres = hlink_frame_navigate(&doc->basedoc, channel->uri->wine_url, channel->post_data_stream, hlnf);
155 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
157 nsIWebNavigation *web_navigation;
158 nsIDocShell *doc_shell;
161 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
162 if(NS_FAILED(nsres)) {
163 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
167 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
168 nsIWebNavigation_Release(web_navigation);
169 if(NS_FAILED(nsres)) {
170 ERR("Could not get nsIDocShell: %08x\n", nsres);
175 uri->channel_bsc = channelbsc;
176 nsres = nsIDocShell_LoadURI(doc_shell, NSURI(uri), NULL, flags, FALSE);
177 uri->channel_bsc = NULL;
178 nsIDocShell_Release(doc_shell);
179 if(NS_FAILED(nsres)) {
180 WARN("LoadURI failed: %08x\n", nsres);
187 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
189 OLECHAR *new_url = NULL, *url;
196 url = heap_strdupW(uri->wine_url);
197 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
199 if(hres != S_OK || !new_url)
202 if(strcmpW(url, new_url)) {
203 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
207 CoTaskMemFree(new_url);
211 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
218 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
219 if(NS_FAILED(nsres)) {
220 WARN("Could not get nsWineURI: %08x\n", nsres);
221 return NS_ERROR_NOT_IMPLEMENTED;
224 if(!wine_uri->is_doc_uri) {
225 if(!wine_uri->container) {
226 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
227 wine_uri->container = nscontainer;
230 wine_uri->is_doc_uri = TRUE;
231 *_retval = translate_url(nscontainer->doc->basedoc.doc_obj, wine_uri);
234 nsIURI_Release(NSURI(wine_uri));
238 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
240 static const WCHAR wszFtp[] = {'f','t','p',':'};
241 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
242 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
244 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
249 new_url = heap_strdupW(url);
251 return E_OUTOFMEMORY;
252 heap_free(This->wine_url);
253 This->wine_url = new_url;
256 /* FIXME: Always use wine url */
258 strncmpW(url, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
259 && strncmpW(url, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
260 && strncmpW(url, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
262 This->use_wine_url = TRUE;
265 heap_free(This->wine_url);
266 This->wine_url = NULL;
267 This->use_wine_url = FALSE;
273 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
275 if(This->container) {
276 if(This->container == nscontainer)
278 TRACE("Changing %p -> %p\n", This->container, nscontainer);
279 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
283 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
284 This->container = nscontainer;
287 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
289 if(This->window_ref) {
290 if(This->window_ref->window == window)
292 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
293 windowref_release(This->window_ref);
297 windowref_addref(window->window_ref);
298 This->window_ref = window->window_ref;
301 set_uri_nscontainer(This, window->doc_obj->nscontainer);
303 This->window_ref = NULL;
307 static inline BOOL is_http_channel(nsChannel *This)
309 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTP;
312 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
314 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
316 nsChannel *This = NSCHANNEL_THIS(iface);
318 if(IsEqualGUID(&IID_nsISupports, riid)) {
319 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
320 *result = NSCHANNEL(This);
321 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
322 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
323 *result = NSCHANNEL(This);
324 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
325 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
326 *result = NSCHANNEL(This);
327 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
328 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
329 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
330 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
331 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
332 *result = NSUPCHANNEL(This);
333 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
334 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
335 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
337 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
342 nsIChannel_AddRef(NSCHANNEL(This));
346 return NS_NOINTERFACE;
349 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
351 nsChannel *This = NSCHANNEL_THIS(iface);
352 nsrefcnt ref = InterlockedIncrement(&This->ref);
354 TRACE("(%p) ref=%d\n", This, ref);
359 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
361 nsChannel *This = NSCHANNEL_THIS(iface);
362 LONG ref = InterlockedDecrement(&This->ref);
365 nsIURI_Release(NSURI(This->uri));
367 nsISupports_Release(This->owner);
368 if(This->post_data_stream)
369 nsIInputStream_Release(This->post_data_stream);
371 nsILoadGroup_Release(This->load_group);
372 if(This->notif_callback)
373 nsIInterfaceRequestor_Release(This->notif_callback);
374 if(This->original_uri)
375 nsIURI_Release(This->original_uri);
376 heap_free(This->content_type);
377 heap_free(This->charset);
384 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
386 nsChannel *This = NSCHANNEL_THIS(iface);
388 FIXME("(%p)->(%p)\n", This, aName);
390 return NS_ERROR_NOT_IMPLEMENTED;
393 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
395 nsChannel *This = NSCHANNEL_THIS(iface);
397 FIXME("(%p)->(%p)\n", This, _retval);
399 return NS_ERROR_NOT_IMPLEMENTED;
402 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
404 nsChannel *This = NSCHANNEL_THIS(iface);
406 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
408 return *aStatus = NS_OK;
411 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
413 nsChannel *This = NSCHANNEL_THIS(iface);
415 FIXME("(%p)->(%08x)\n", This, aStatus);
417 return NS_ERROR_NOT_IMPLEMENTED;
420 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
422 nsChannel *This = NSCHANNEL_THIS(iface);
424 FIXME("(%p)\n", This);
426 return NS_ERROR_NOT_IMPLEMENTED;
429 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
431 nsChannel *This = NSCHANNEL_THIS(iface);
433 FIXME("(%p)\n", This);
435 return NS_ERROR_NOT_IMPLEMENTED;
438 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
440 nsChannel *This = NSCHANNEL_THIS(iface);
442 TRACE("(%p)->(%p)\n", This, aLoadGroup);
445 nsILoadGroup_AddRef(This->load_group);
447 *aLoadGroup = This->load_group;
451 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
453 nsChannel *This = NSCHANNEL_THIS(iface);
455 TRACE("(%p)->(%p)\n", This, aLoadGroup);
458 nsILoadGroup_Release(This->load_group);
460 nsILoadGroup_AddRef(aLoadGroup);
461 This->load_group = aLoadGroup;
466 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
468 nsChannel *This = NSCHANNEL_THIS(iface);
470 TRACE("(%p)->(%p)\n", This, aLoadFlags);
472 *aLoadFlags = This->load_flags;
476 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
478 nsChannel *This = NSCHANNEL_THIS(iface);
480 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
482 This->load_flags = aLoadFlags;
486 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
488 nsChannel *This = NSCHANNEL_THIS(iface);
490 TRACE("(%p)->(%p)\n", This, aOriginalURI);
492 if(This->original_uri)
493 nsIURI_AddRef(This->original_uri);
495 *aOriginalURI = This->original_uri;
499 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
501 nsChannel *This = NSCHANNEL_THIS(iface);
503 TRACE("(%p)->(%p)\n", This, aOriginalURI);
505 if(This->original_uri)
506 nsIURI_Release(This->original_uri);
508 nsIURI_AddRef(aOriginalURI);
509 This->original_uri = aOriginalURI;
513 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
515 nsChannel *This = NSCHANNEL_THIS(iface);
517 TRACE("(%p)->(%p)\n", This, aURI);
519 nsIURI_AddRef(NSURI(This->uri));
520 *aURI = (nsIURI*)This->uri;
525 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
527 nsChannel *This = NSCHANNEL_THIS(iface);
529 TRACE("(%p)->(%p)\n", This, aOwner);
532 nsISupports_AddRef(This->owner);
533 *aOwner = This->owner;
538 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
540 nsChannel *This = NSCHANNEL_THIS(iface);
542 TRACE("(%p)->(%p)\n", This, aOwner);
545 nsISupports_AddRef(aOwner);
547 nsISupports_Release(This->owner);
548 This->owner = aOwner;
553 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
554 nsIInterfaceRequestor **aNotificationCallbacks)
556 nsChannel *This = NSCHANNEL_THIS(iface);
558 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
560 if(This->notif_callback)
561 nsIInterfaceRequestor_AddRef(This->notif_callback);
562 *aNotificationCallbacks = This->notif_callback;
567 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
568 nsIInterfaceRequestor *aNotificationCallbacks)
570 nsChannel *This = NSCHANNEL_THIS(iface);
572 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
574 if(This->notif_callback)
575 nsIInterfaceRequestor_Release(This->notif_callback);
576 if(aNotificationCallbacks)
577 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
579 This->notif_callback = aNotificationCallbacks;
584 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
586 nsChannel *This = NSCHANNEL_THIS(iface);
588 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
590 return NS_ERROR_NOT_IMPLEMENTED;
593 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
595 nsChannel *This = NSCHANNEL_THIS(iface);
597 TRACE("(%p)->(%p)\n", This, aContentType);
599 if(This->content_type) {
600 nsACString_SetData(aContentType, This->content_type);
604 WARN("unknown type\n");
605 return NS_ERROR_FAILURE;
608 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
609 const nsACString *aContentType)
611 nsChannel *This = NSCHANNEL_THIS(iface);
612 const char *content_type;
614 TRACE("(%p)->(%p)\n", This, aContentType);
616 nsACString_GetData(aContentType, &content_type);
618 TRACE("content_type %s\n", content_type);
620 heap_free(This->content_type);
621 This->content_type = heap_strdupA(content_type);
626 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
627 nsACString *aContentCharset)
629 nsChannel *This = NSCHANNEL_THIS(iface);
631 TRACE("(%p)->(%p)\n", This, aContentCharset);
634 nsACString_SetData(aContentCharset, This->charset);
638 nsACString_SetData(aContentCharset, "");
642 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
643 const nsACString *aContentCharset)
645 nsChannel *This = NSCHANNEL_THIS(iface);
647 FIXME("(%p)->(%p)\n", This, aContentCharset);
649 return NS_ERROR_NOT_IMPLEMENTED;
652 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
654 nsChannel *This = NSCHANNEL_THIS(iface);
656 FIXME("(%p)->(%p)\n", This, aContentLength);
658 return NS_ERROR_NOT_IMPLEMENTED;
661 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
663 nsChannel *This = NSCHANNEL_THIS(iface);
665 FIXME("(%p)->(%d)\n", This, aContentLength);
667 return NS_ERROR_NOT_IMPLEMENTED;
670 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
672 nsChannel *This = NSCHANNEL_THIS(iface);
674 FIXME("(%p)->(%p)\n", This, _retval);
676 return NS_ERROR_NOT_IMPLEMENTED;
679 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
685 if(!channel->original_uri) {
686 ERR("original_uri == NULL\n");
690 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsWineURI, (void**)&wine_uri);
691 if(NS_FAILED(nsres)) {
692 ERR("Could not get nsWineURI: %08x\n", nsres);
696 if(wine_uri->wine_url) {
697 hres = CreateURLMoniker(NULL, wine_uri->wine_url, mon);
699 WARN("CreateURLMoniker failed: %08x\n", hres);
701 TRACE("wine_url == NULL\n");
705 nsIURI_Release(NSURI(wine_uri));
710 static HTMLWindow *get_window_from_load_group(nsChannel *This)
719 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
720 if(NS_FAILED(nsres)) {
721 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
728 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
729 nsIRequest_Release(req);
730 if(NS_FAILED(nsres)) {
731 WARN("Could not get nsIChannel interface: %08x\n", nsres);
735 nsres = nsIChannel_GetURI(channel, &uri);
736 nsIChannel_Release(channel);
737 if(NS_FAILED(nsres)) {
738 ERR("GetURI failed: %08x\n", nsres);
742 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
744 if(NS_FAILED(nsres)) {
745 TRACE("Could not get nsWineURI: %08x\n", nsres);
749 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
751 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
752 nsIURI_Release(NSURI(wine_uri));
757 static HTMLWindow *get_channel_window(nsChannel *This)
759 nsIRequestObserver *req_observer;
760 nsIWebProgress *web_progress;
761 nsIDOMWindow *nswindow;
765 if(!This->load_group) {
766 ERR("NULL load_group\n");
770 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
771 if(NS_FAILED(nsres) || !req_observer) {
772 ERR("GetGroupObserver failed: %08x\n", nsres);
776 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
777 nsIRequestObserver_Release(req_observer);
778 if(NS_FAILED(nsres)) {
779 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
783 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
784 nsIWebProgress_Release(web_progress);
785 if(NS_FAILED(nsres) || !nswindow) {
786 ERR("GetDOMWindow failed: %08x\n", nsres);
790 window = nswindow_to_window(nswindow);
791 nsIDOMWindow_Release(nswindow);
794 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
796 FIXME("NULL window for %p\n", nswindow);
802 HTMLDocumentNode *doc;
803 nsChannelBSC *bscallback;
804 } start_binding_task_t;
806 static void start_binding_proc(task_t *_task)
808 start_binding_task_t *task = (start_binding_task_t*)_task;
810 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
816 nsChannelBSC *bscallback;
817 } start_doc_binding_task_t;
819 static void start_doc_binding_proc(task_t *_task)
821 start_doc_binding_task_t *task = (start_doc_binding_task_t*)_task;
823 start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
824 IUnknown_Release((IUnknown*)task->bscallback);
827 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
828 nsISupports *context)
830 nsChannelBSC *bscallback;
831 IMoniker *mon = NULL;
834 hres = create_mon_for_nschannel(This, &mon);
836 return NS_ERROR_UNEXPECTED;
839 set_current_mon(window, mon);
841 bscallback = create_channelbsc(mon);
842 IMoniker_Release(mon);
844 channelbsc_set_channel(bscallback, This, listener, context);
847 start_doc_binding_task_t *task;
849 set_window_bscallback(window, bscallback);
851 task = heap_alloc(sizeof(start_doc_binding_task_t));
852 task->window = window;
853 task->bscallback = bscallback;
854 push_task(&task->header, start_doc_binding_proc, window->task_magic);
856 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
858 task->doc = window->doc;
859 task->bscallback = bscallback;
860 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
866 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
867 nsISupports *aContext)
869 nsChannel *This = NSCHANNEL_THIS(iface);
870 HTMLWindow *window = NULL;
872 nsresult nsres = NS_OK;
874 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
876 if(This->uri->is_doc_uri) {
877 window = get_channel_window(This);
879 set_uri_window(This->uri, window);
880 }else if(This->uri->container) {
883 /* nscontainer->doc should be NULL which means navigation to a new window */
884 if(This->uri->container->doc)
885 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
887 b = before_async_open(This, This->uri->container);
889 FIXME("Navigation not cancelled\n");
890 return NS_ERROR_UNEXPECTED;
895 if(This->uri->window_ref && This->uri->window_ref->window) {
896 window = This->uri->window_ref->window;
897 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
898 }else if(This->load_group) {
899 window = get_window_from_load_group(This);
901 set_uri_window(This->uri, window);
906 ERR("window = NULL\n");
907 return NS_ERROR_UNEXPECTED;
910 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
911 if(This->uri->channel_bsc) {
912 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
914 if(window->doc_obj->mime) {
915 heap_free(This->content_type);
916 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
921 open = before_async_open(This, window->doc_obj->nscontainer);
924 nsres = NS_ERROR_UNEXPECTED;
930 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
932 IHTMLWindow2_Release(HTMLWINDOW2(window));
936 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
938 nsChannel *This = NSCHANNEL_THIS(iface);
940 FIXME("(%p)->(%p)\n", This, aRequestMethod);
942 return NS_ERROR_NOT_IMPLEMENTED;
945 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
946 const nsACString *aRequestMethod)
948 nsChannel *This = NSCHANNEL_THIS(iface);
950 FIXME("(%p)->(%p)\n", This, aRequestMethod);
952 return NS_ERROR_NOT_IMPLEMENTED;
955 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
957 nsChannel *This = NSCHANNEL_THIS(iface);
959 FIXME("(%p)->(%p)\n", This, aReferrer);
961 return NS_ERROR_NOT_IMPLEMENTED;
964 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
966 nsChannel *This = NSCHANNEL_THIS(iface);
968 FIXME("(%p)->(%p)\n", This, aReferrer);
973 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
974 const nsACString *aHeader, nsACString *_retval)
976 nsChannel *This = NSCHANNEL_THIS(iface);
978 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
980 return NS_ERROR_NOT_IMPLEMENTED;
983 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
984 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
986 nsChannel *This = NSCHANNEL_THIS(iface);
988 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
993 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
994 nsIHttpHeaderVisitor *aVisitor)
996 nsChannel *This = NSCHANNEL_THIS(iface);
998 FIXME("(%p)->(%p)\n", This, aVisitor);
1000 return NS_ERROR_NOT_IMPLEMENTED;
1003 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
1005 nsChannel *This = NSCHANNEL_THIS(iface);
1007 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
1009 return NS_ERROR_NOT_IMPLEMENTED;
1012 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1014 nsChannel *This = NSCHANNEL_THIS(iface);
1016 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1018 return NS_ERROR_NOT_IMPLEMENTED;
1021 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1023 nsChannel *This = NSCHANNEL_THIS(iface);
1025 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1027 return NS_ERROR_NOT_IMPLEMENTED;
1030 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1032 nsChannel *This = NSCHANNEL_THIS(iface);
1034 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1036 return NS_ERROR_NOT_IMPLEMENTED;
1039 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1041 nsChannel *This = NSCHANNEL_THIS(iface);
1043 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1045 if(This->response_status) {
1046 *aResponseStatus = This->response_status;
1050 WARN("No response status\n");
1051 return NS_ERROR_UNEXPECTED;
1054 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1055 nsACString *aResponseStatusText)
1057 nsChannel *This = NSCHANNEL_THIS(iface);
1059 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1061 return NS_ERROR_NOT_IMPLEMENTED;
1064 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1065 PRBool *aRequestSucceeded)
1067 nsChannel *This = NSCHANNEL_THIS(iface);
1069 FIXME("(%p)->(%p)\n", This, aRequestSucceeded);
1071 return NS_ERROR_NOT_IMPLEMENTED;
1074 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1075 const nsACString *header, nsACString *_retval)
1077 nsChannel *This = NSCHANNEL_THIS(iface);
1079 FIXME("(%p)->(%p %p)\n", This, header, _retval);
1081 return NS_ERROR_NOT_IMPLEMENTED;
1084 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1085 const nsACString *header, const nsACString *value, PRBool merge)
1087 nsChannel *This = NSCHANNEL_THIS(iface);
1089 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
1091 return NS_ERROR_NOT_IMPLEMENTED;
1094 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1095 nsIHttpHeaderVisitor *aVisitor)
1097 nsChannel *This = NSCHANNEL_THIS(iface);
1099 FIXME("(%p)->(%p)\n", This, aVisitor);
1101 return NS_ERROR_NOT_IMPLEMENTED;
1104 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1106 nsChannel *This = NSCHANNEL_THIS(iface);
1108 FIXME("(%p)->(%p)\n", This, _retval);
1110 return NS_ERROR_NOT_IMPLEMENTED;
1113 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1115 nsChannel *This = NSCHANNEL_THIS(iface);
1117 FIXME("(%p)->(%p)\n", This, _retval);
1119 return NS_ERROR_NOT_IMPLEMENTED;
1122 #undef NSCHANNEL_THIS
1124 static const nsIHttpChannelVtbl nsChannelVtbl = {
1125 nsChannel_QueryInterface,
1129 nsChannel_IsPending,
1130 nsChannel_GetStatus,
1134 nsChannel_GetLoadGroup,
1135 nsChannel_SetLoadGroup,
1136 nsChannel_GetLoadFlags,
1137 nsChannel_SetLoadFlags,
1138 nsChannel_GetOriginalURI,
1139 nsChannel_SetOriginalURI,
1143 nsChannel_GetNotificationCallbacks,
1144 nsChannel_SetNotificationCallbacks,
1145 nsChannel_GetSecurityInfo,
1146 nsChannel_GetContentType,
1147 nsChannel_SetContentType,
1148 nsChannel_GetContentCharset,
1149 nsChannel_SetContentCharset,
1150 nsChannel_GetContentLength,
1151 nsChannel_SetContentLength,
1153 nsChannel_AsyncOpen,
1154 nsChannel_GetRequestMethod,
1155 nsChannel_SetRequestMethod,
1156 nsChannel_GetReferrer,
1157 nsChannel_SetReferrer,
1158 nsChannel_GetRequestHeader,
1159 nsChannel_SetRequestHeader,
1160 nsChannel_VisitRequestHeaders,
1161 nsChannel_GetAllowPipelining,
1162 nsChannel_SetAllowPipelining,
1163 nsChannel_GetRedirectionLimit,
1164 nsChannel_SetRedirectionLimit,
1165 nsChannel_GetResponseStatus,
1166 nsChannel_GetResponseStatusText,
1167 nsChannel_GetRequestSucceeded,
1168 nsChannel_GetResponseHeader,
1169 nsChannel_SetResponseHeader,
1170 nsChannel_VisitResponseHeaders,
1171 nsChannel_IsNoStoreResponse,
1172 nsChannel_IsNoCacheResponse
1175 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1177 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1180 nsChannel *This = NSUPCHANNEL_THIS(iface);
1181 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1184 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1186 nsChannel *This = NSUPCHANNEL_THIS(iface);
1187 return nsIChannel_AddRef(NSCHANNEL(This));
1190 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1192 nsChannel *This = NSUPCHANNEL_THIS(iface);
1193 return nsIChannel_Release(NSCHANNEL(This));
1196 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1197 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1199 nsChannel *This = NSUPCHANNEL_THIS(iface);
1200 const char *content_type;
1202 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1204 if(This->post_data_stream)
1205 nsIInputStream_Release(This->post_data_stream);
1208 nsACString_GetData(aContentType, &content_type);
1210 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1213 if(aContentLength != -1)
1214 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1216 if(This->post_data_stream)
1217 nsIInputStream_Release(This->post_data_stream);
1218 This->post_data_stream = aStream;
1220 nsIInputStream_AddRef(aStream);
1225 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1226 nsIInputStream **aUploadStream)
1228 nsChannel *This = NSUPCHANNEL_THIS(iface);
1230 TRACE("(%p)->(%p)\n", This, aUploadStream);
1232 if(This->post_data_stream)
1233 nsIInputStream_AddRef(This->post_data_stream);
1235 *aUploadStream = This->post_data_stream;
1239 #undef NSUPCHANNEL_THIS
1241 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1242 nsUploadChannel_QueryInterface,
1243 nsUploadChannel_AddRef,
1244 nsUploadChannel_Release,
1245 nsUploadChannel_SetUploadStream,
1246 nsUploadChannel_GetUploadStream
1249 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1251 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1254 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1255 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1258 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1260 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1261 return nsIChannel_AddRef(NSCHANNEL(This));
1264 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1266 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1267 return nsIChannel_Release(NSCHANNEL(This));
1270 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1272 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1274 FIXME("(%p)->()\n", This);
1276 return NS_ERROR_NOT_IMPLEMENTED;
1279 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1281 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1283 FIXME("(%p)->()\n", This);
1285 return NS_ERROR_NOT_IMPLEMENTED;
1288 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1290 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1292 FIXME("(%p)->()\n", This);
1294 return NS_ERROR_NOT_IMPLEMENTED;
1297 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1299 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1301 FIXME("(%p)->()\n", This);
1303 return NS_ERROR_NOT_IMPLEMENTED;
1306 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1308 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1310 FIXME("(%p)->()\n", This);
1312 return NS_ERROR_NOT_IMPLEMENTED;
1315 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1317 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1319 FIXME("(%p)->()\n", This);
1321 return NS_ERROR_NOT_IMPLEMENTED;
1324 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1326 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1328 FIXME("(%p)->()\n", This);
1330 return NS_ERROR_NOT_IMPLEMENTED;
1333 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1335 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1337 FIXME("(%p)->()\n", This);
1339 return NS_ERROR_NOT_IMPLEMENTED;
1342 #undef NSHTTPINTERNAL_THIS
1344 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1345 nsHttpChannelInternal_QueryInterface,
1346 nsHttpChannelInternal_AddRef,
1347 nsHttpChannelInternal_Release,
1348 nsHttpChannelInternal_GetDocumentURI,
1349 nsHttpChannelInternal_SetDocumentURI,
1350 nsHttpChannelInternal_GetRequestVersion,
1351 nsHttpChannelInternal_GetResponseVersion,
1352 nsHttpChannelInternal_SetCookie,
1353 nsHttpChannelInternal_SetupFallbackChannel,
1354 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1355 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1358 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1360 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, nsQIResult result)
1362 nsWineURI *This = NSURI_THIS(iface);
1366 if(IsEqualGUID(&IID_nsISupports, riid)) {
1367 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1368 *result = NSURI(This);
1369 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1370 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1371 *result = NSURI(This);
1372 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1373 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1374 *result = NSURL(This);
1375 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1376 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1381 nsIURI_AddRef(NSURI(This));
1385 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1386 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1389 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1391 nsWineURI *This = NSURI_THIS(iface);
1392 LONG ref = InterlockedIncrement(&This->ref);
1394 TRACE("(%p) ref=%d\n", This, ref);
1399 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1401 nsWineURI *This = NSURI_THIS(iface);
1402 LONG ref = InterlockedDecrement(&This->ref);
1404 TRACE("(%p) ref=%d\n", This, ref);
1407 if(This->window_ref)
1408 windowref_release(This->window_ref);
1410 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1412 nsIURL_Release(This->nsurl);
1414 nsIURI_Release(This->uri);
1415 heap_free(This->wine_url);
1422 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1424 nsWineURI *This = NSURI_THIS(iface);
1426 TRACE("(%p)->(%p)\n", This, aSpec);
1428 if(This->use_wine_url) {
1429 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1430 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1431 nsACString_SetData(aSpec, speca);
1437 return nsIURI_GetSpec(This->uri, aSpec);
1439 TRACE("returning error\n");
1440 return NS_ERROR_NOT_IMPLEMENTED;
1444 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1446 nsWineURI *This = NSURI_THIS(iface);
1448 TRACE("(%p)->(%p)\n", This, aSpec);
1451 return nsIURI_SetSpec(This->uri, aSpec);
1453 FIXME("default action not implemented\n");
1454 return NS_ERROR_NOT_IMPLEMENTED;
1457 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1459 nsWineURI *This = NSURI_THIS(iface);
1461 TRACE("(%p)->(%p)\n", This, aPrePath);
1464 return nsIURI_GetPrePath(This->uri, aPrePath);
1466 FIXME("default action not implemented\n");
1467 return NS_ERROR_NOT_IMPLEMENTED;
1470 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1472 nsWineURI *This = NSURI_THIS(iface);
1474 TRACE("(%p)->(%p)\n", This, aScheme);
1476 if(This->use_wine_url) {
1478 * For Gecko we set scheme to unknown so it won't be handled
1479 * as any special case.
1481 nsACString_SetData(aScheme, "wine");
1486 return nsIURI_GetScheme(This->uri, aScheme);
1488 TRACE("returning error\n");
1489 return NS_ERROR_NOT_IMPLEMENTED;
1492 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1494 nsWineURI *This = NSURI_THIS(iface);
1496 TRACE("(%p)->(%p)\n", This, aScheme);
1499 return nsIURI_SetScheme(This->uri, aScheme);
1501 FIXME("default action not implemented\n");
1502 return NS_ERROR_NOT_IMPLEMENTED;
1505 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1507 nsWineURI *This = NSURI_THIS(iface);
1509 TRACE("(%p)->(%p)\n", This, aUserPass);
1512 return nsIURI_GetUserPass(This->uri, aUserPass);
1514 FIXME("default action not implemented\n");
1515 return NS_ERROR_NOT_IMPLEMENTED;
1518 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1520 nsWineURI *This = NSURI_THIS(iface);
1522 TRACE("(%p)->(%p)\n", This, aUserPass);
1525 return nsIURI_SetUserPass(This->uri, aUserPass);
1527 FIXME("default action not implemented\n");
1528 return NS_ERROR_NOT_IMPLEMENTED;
1531 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1533 nsWineURI *This = NSURI_THIS(iface);
1535 TRACE("(%p)->(%p)\n", This, aUsername);
1538 return nsIURI_GetUsername(This->uri, aUsername);
1540 FIXME("default action not implemented\n");
1541 return NS_ERROR_NOT_IMPLEMENTED;
1544 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1546 nsWineURI *This = NSURI_THIS(iface);
1548 TRACE("(%p)->(%p)\n", This, aUsername);
1551 return nsIURI_SetUsername(This->uri, aUsername);
1553 FIXME("default action not implemented\n");
1554 return NS_ERROR_NOT_IMPLEMENTED;
1557 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1559 nsWineURI *This = NSURI_THIS(iface);
1561 TRACE("(%p)->(%p)\n", This, aPassword);
1564 return nsIURI_GetPassword(This->uri, aPassword);
1566 FIXME("default action not implemented\n");
1567 return NS_ERROR_NOT_IMPLEMENTED;
1570 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1572 nsWineURI *This = NSURI_THIS(iface);
1574 TRACE("(%p)->(%p)\n", This, aPassword);
1577 return nsIURI_SetPassword(This->uri, aPassword);
1579 FIXME("default action not implemented\n");
1580 return NS_ERROR_NOT_IMPLEMENTED;
1583 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1585 nsWineURI *This = NSURI_THIS(iface);
1587 TRACE("(%p)->(%p)\n", This, aHostPort);
1590 return nsIURI_GetHostPort(This->uri, aHostPort);
1592 FIXME("default action not implemented\n");
1593 return NS_ERROR_NOT_IMPLEMENTED;
1596 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1598 nsWineURI *This = NSURI_THIS(iface);
1600 TRACE("(%p)->(%p)\n", This, aHostPort);
1603 return nsIURI_SetHostPort(This->uri, aHostPort);
1605 FIXME("default action not implemented\n");
1606 return NS_ERROR_NOT_IMPLEMENTED;
1609 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1611 nsWineURI *This = NSURI_THIS(iface);
1613 TRACE("(%p)->(%p)\n", This, aHost);
1616 return nsIURI_GetHost(This->uri, aHost);
1618 FIXME("default action not implemented\n");
1619 return NS_ERROR_NOT_IMPLEMENTED;
1622 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1624 nsWineURI *This = NSURI_THIS(iface);
1626 TRACE("(%p)->(%p)\n", This, aHost);
1629 return nsIURI_SetHost(This->uri, aHost);
1631 FIXME("default action not implemented\n");
1632 return NS_ERROR_NOT_IMPLEMENTED;
1635 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1637 nsWineURI *This = NSURI_THIS(iface);
1639 TRACE("(%p)->(%p)\n", This, aPort);
1642 return nsIURI_GetPort(This->uri, aPort);
1644 FIXME("default action not implemented\n");
1645 return NS_ERROR_NOT_IMPLEMENTED;
1648 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1650 nsWineURI *This = NSURI_THIS(iface);
1652 TRACE("(%p)->(%d)\n", This, aPort);
1655 return nsIURI_SetPort(This->uri, aPort);
1657 FIXME("default action not implemented\n");
1658 return NS_ERROR_NOT_IMPLEMENTED;
1661 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
1663 nsWineURI *This = NSURI_THIS(iface);
1665 TRACE("(%p)->(%p)\n", This, aPath);
1668 return nsIURI_GetPath(This->uri, aPath);
1670 FIXME("default action not implemented\n");
1671 return NS_ERROR_NOT_IMPLEMENTED;
1674 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
1676 nsWineURI *This = NSURI_THIS(iface);
1679 nsACString_GetData(aPath, &path);
1680 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1683 if(This->wine_url) {
1684 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1685 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1689 pathw = heap_strdupAtoW(path);
1690 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1693 set_wine_url(This, new_url);
1695 WARN("UrlCombine failed: %08x\n", hres);
1701 return nsIURI_SetPath(This->uri, aPath);
1704 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
1706 nsWineURI *This = NSURI_THIS(iface);
1707 nsWineURI *wine_uri;
1710 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1713 return nsIURI_Equals(This->uri, other, _retval);
1715 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&wine_uri);
1716 if(NS_FAILED(nsres)) {
1717 TRACE("Could not get nsWineURI interface\n");
1722 *_retval = wine_uri->wine_url && !UrlCompareW(This->wine_url, wine_uri->wine_url, TRUE);
1723 nsIURI_Release(NSURI(wine_uri));
1728 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
1730 nsWineURI *This = NSURI_THIS(iface);
1732 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1734 if(This->use_wine_url) {
1735 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1736 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1738 *_retval = lstrlenW(This->wine_url) > len
1739 && This->wine_url[len] == ':'
1740 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1745 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1747 TRACE("returning error\n");
1748 return NS_ERROR_NOT_IMPLEMENTED;
1751 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
1753 nsWineURI *This = NSURI_THIS(iface);
1754 nsIURI *nsuri = NULL;
1755 nsWineURI *wine_uri;
1758 TRACE("(%p)->(%p)\n", This, _retval);
1761 nsres = nsIURI_Clone(This->uri, &nsuri);
1762 if(NS_FAILED(nsres)) {
1763 WARN("Clone failed: %08x\n", nsres);
1768 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1769 if(NS_FAILED(nsres)) {
1770 WARN("create_uri failed: %08x\n", nsres);
1774 set_wine_url(wine_uri, This->wine_url);
1776 *_retval = NSURI(wine_uri);
1780 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *arelativePath,
1781 nsACString *_retval)
1783 nsWineURI *This = NSURI_THIS(iface);
1785 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1788 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1790 FIXME("default action not implemented\n");
1791 return NS_ERROR_NOT_IMPLEMENTED;
1794 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
1796 nsWineURI *This = NSURI_THIS(iface);
1798 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1800 if(This->use_wine_url)
1801 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1804 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1806 TRACE("returning error\n");
1807 return NS_ERROR_NOT_IMPLEMENTED;
1810 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
1812 nsWineURI *This = NSURI_THIS(iface);
1814 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1817 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1819 FIXME("default action not implemented\n");
1820 return NS_ERROR_NOT_IMPLEMENTED;
1823 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
1825 nsWineURI *This = NSURI_THIS(iface);
1827 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1830 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1832 FIXME("default action not implemented\n");
1833 return NS_ERROR_NOT_IMPLEMENTED;
1836 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
1838 nsWineURI *This = NSURI_THIS(iface);
1840 TRACE("(%p)->(%p)\n", This, aFilePath);
1843 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1845 FIXME("default action not implemented\n");
1846 return NS_ERROR_NOT_IMPLEMENTED;
1849 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
1851 nsWineURI *This = NSURI_THIS(iface);
1853 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1856 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1858 FIXME("default action not implemented\n");
1859 return NS_ERROR_NOT_IMPLEMENTED;
1862 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
1864 nsWineURI *This = NSURI_THIS(iface);
1866 TRACE("(%p)->(%p)\n", This, aParam);
1869 return nsIURL_GetParam(This->nsurl, aParam);
1871 FIXME("default action not implemented\n");
1872 return NS_ERROR_NOT_IMPLEMENTED;
1875 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
1877 nsWineURI *This = NSURI_THIS(iface);
1879 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1882 return nsIURL_SetParam(This->nsurl, aParam);
1884 FIXME("default action not implemented\n");
1885 return NS_ERROR_NOT_IMPLEMENTED;
1888 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
1890 nsWineURI *This = NSURI_THIS(iface);
1892 TRACE("(%p)->(%p)\n", This, aQuery);
1895 return nsIURL_GetQuery(This->nsurl, aQuery);
1897 FIXME("default action not implemented\n");
1898 return NS_ERROR_NOT_IMPLEMENTED;
1901 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
1903 nsWineURI *This = NSURI_THIS(iface);
1904 const WCHAR *ptr1, *ptr2;
1906 WCHAR *new_url, *ptr;
1909 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1912 nsIURL_SetQuery(This->nsurl, aQuery);
1917 nsACString_GetData(aQuery, &query);
1918 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1919 ptr1 = strchrW(This->wine_url, '?');
1921 size += ptr1-This->wine_url;
1922 ptr2 = strchrW(ptr1, '#');
1924 size += strlenW(ptr2);
1926 ptr1 = This->wine_url + strlenW(This->wine_url);
1928 size += strlenW(This->wine_url);
1934 new_url = heap_alloc(size*sizeof(WCHAR));
1935 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1936 ptr = new_url + (ptr1-This->wine_url);
1939 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1947 TRACE("setting %s\n", debugstr_w(new_url));
1949 heap_free(This->wine_url);
1950 This->wine_url = new_url;
1954 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
1956 nsWineURI *This = NSURI_THIS(iface);
1958 TRACE("(%p)->(%p)\n", This, aRef);
1961 return nsIURL_GetRef(This->nsurl, aRef);
1963 FIXME("default action not implemented\n");
1964 return NS_ERROR_NOT_IMPLEMENTED;
1967 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
1969 nsWineURI *This = NSURI_THIS(iface);
1972 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1975 return nsIURL_SetRef(This->nsurl, aRef);
1977 nsACString_GetData(aRef, &refa);
1981 FIXME("default action not implemented\n");
1982 return NS_ERROR_NOT_IMPLEMENTED;
1985 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
1987 nsWineURI *This = NSURI_THIS(iface);
1989 TRACE("(%p)->(%p)\n", This, aDirectory);
1992 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1994 FIXME("default action not implemented\n");
1995 return NS_ERROR_NOT_IMPLEMENTED;
1998 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
2000 nsWineURI *This = NSURI_THIS(iface);
2002 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
2005 return nsIURL_SetDirectory(This->nsurl, aDirectory);
2007 FIXME("default action not implemented\n");
2008 return NS_ERROR_NOT_IMPLEMENTED;
2011 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
2013 nsWineURI *This = NSURI_THIS(iface);
2015 TRACE("(%p)->(%p)\n", This, aFileName);
2018 return nsIURL_GetFileName(This->nsurl, aFileName);
2020 FIXME("default action not implemented\n");
2021 return NS_ERROR_NOT_IMPLEMENTED;
2024 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2026 nsWineURI *This = NSURI_THIS(iface);
2028 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2031 return nsIURL_SetFileName(This->nsurl, aFileName);
2033 FIXME("default action not implemented\n");
2034 return NS_ERROR_NOT_IMPLEMENTED;
2037 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2039 nsWineURI *This = NSURI_THIS(iface);
2041 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2044 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2046 FIXME("default action not implemented\n");
2047 return NS_ERROR_NOT_IMPLEMENTED;
2050 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2052 nsWineURI *This = NSURI_THIS(iface);
2054 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2057 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2059 FIXME("default action not implemented\n");
2060 return NS_ERROR_NOT_IMPLEMENTED;
2063 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2065 nsWineURI *This = NSURI_THIS(iface);
2067 TRACE("(%p)->(%p)\n", This, aFileExtension);
2070 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2072 FIXME("default action not implemented\n");
2073 return NS_ERROR_NOT_IMPLEMENTED;
2076 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2078 nsWineURI *This = NSURI_THIS(iface);
2080 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2083 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2085 FIXME("default action not implemented\n");
2086 return NS_ERROR_NOT_IMPLEMENTED;
2089 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2091 nsWineURI *This = NSURI_THIS(iface);
2093 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2096 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2098 FIXME("default action not implemented\n");
2099 return NS_ERROR_NOT_IMPLEMENTED;
2102 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2104 nsWineURI *This = NSURI_THIS(iface);
2106 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2109 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2111 FIXME("default action not implemented\n");
2112 return NS_ERROR_NOT_IMPLEMENTED;
2117 static const nsIURLVtbl nsURLVtbl = {
2118 nsURI_QueryInterface,
2146 nsURI_GetOriginCharset,
2159 nsURL_GetFileBaseName,
2160 nsURL_SetFileBaseName,
2161 nsURL_GetFileExtension,
2162 nsURL_SetFileExtension,
2163 nsURL_GetCommonBaseSpec,
2164 nsURL_GetRelativeSpec
2167 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2169 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2171 ret->lpIURLVtbl = &nsURLVtbl;
2175 set_uri_nscontainer(ret, container);
2176 set_uri_window(ret, window);
2179 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2183 TRACE("retval=%p\n", ret);
2188 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2193 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2194 if(NS_FAILED(nsres))
2197 set_wine_url(uri, url);
2198 uri->is_doc_uri = TRUE;
2205 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2209 nsIProtocolHandler *nshandler;
2210 } nsProtocolHandler;
2212 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2214 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2216 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2219 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2223 if(IsEqualGUID(&IID_nsISupports, riid)) {
2224 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2225 *result = NSPROTHANDLER(This);
2226 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2227 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2228 *result = NSPROTHANDLER(This);
2229 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2230 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2231 return NS_NOINTERFACE;
2235 nsISupports_AddRef((nsISupports*)*result);
2239 WARN("(%s %p)\n", debugstr_guid(riid), result);
2240 return NS_NOINTERFACE;
2243 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2245 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2246 LONG ref = InterlockedIncrement(&This->ref);
2248 TRACE("(%p) ref=%d\n", This, ref);
2253 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2255 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2256 LONG ref = InterlockedDecrement(&This->ref);
2258 TRACE("(%p) ref=%d\n", This, ref);
2262 nsIProtocolHandler_Release(This->nshandler);
2269 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2271 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2273 TRACE("(%p)->(%p)\n", This, aScheme);
2276 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2277 return NS_ERROR_NOT_IMPLEMENTED;
2280 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2281 PRInt32 *aDefaultPort)
2283 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2285 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2288 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2289 return NS_ERROR_NOT_IMPLEMENTED;
2292 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2293 PRUint32 *aProtocolFlags)
2295 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2297 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2300 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2301 return NS_ERROR_NOT_IMPLEMENTED;
2304 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2305 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2307 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2309 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2312 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2313 return NS_ERROR_NOT_IMPLEMENTED;
2316 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2317 nsIURI *aURI, nsIChannel **_retval)
2319 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2321 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2324 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2325 return NS_ERROR_NOT_IMPLEMENTED;
2328 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2329 PRInt32 port, const char *scheme, PRBool *_retval)
2331 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2333 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2336 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2337 return NS_ERROR_NOT_IMPLEMENTED;
2340 #undef NSPROTHANDLER_THIS
2342 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2343 nsProtocolHandler_QueryInterface,
2344 nsProtocolHandler_AddRef,
2345 nsProtocolHandler_Release,
2346 nsProtocolHandler_GetScheme,
2347 nsProtocolHandler_GetDefaultPort,
2348 nsProtocolHandler_GetProtocolFlags,
2349 nsProtocolHandler_NewURI,
2350 nsProtocolHandler_NewChannel,
2351 nsProtocolHandler_AllowPort
2354 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2356 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2358 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2360 ret->nshandler = nshandler;
2362 return NSPROTHANDLER(ret);
2365 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2367 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2372 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2377 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2378 nsIProtocolHandler **_retval)
2380 nsIExternalProtocolHandler *nsexthandler;
2381 nsIProtocolHandler *nshandler;
2384 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2386 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2387 if(NS_FAILED(nsres)) {
2388 WARN("GetProtocolHandler failed: %08x\n", nsres);
2392 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2393 (void**)&nsexthandler);
2394 if(NS_FAILED(nsres)) {
2395 *_retval = nshandler;
2399 nsIExternalProtocolHandler_Release(nsexthandler);
2400 *_retval = create_protocol_handler(nshandler);
2401 TRACE("return %p\n", *_retval);
2405 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2408 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2409 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2412 static BOOL is_gecko_special_uri(const char *spec)
2414 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2417 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2418 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2425 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2426 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2428 nsWineURI *wine_uri, *base_wine_uri = NULL;
2429 const char *spec = NULL;
2430 HTMLWindow *window = NULL;
2432 LPCWSTR base_wine_url = NULL;
2433 BOOL is_wine_uri = FALSE;
2436 nsACString_GetData(aSpec, &spec);
2438 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2441 if(is_gecko_special_uri(spec))
2442 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2444 if(!strncmp(spec, "wine:", 5)) {
2450 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2452 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
2453 if(NS_SUCCEEDED(nsres)) {
2454 base_wine_url = base_wine_uri->wine_url;
2455 if(base_wine_uri->window_ref && base_wine_uri->window_ref->window) {
2456 window = base_wine_uri->window_ref->window;
2457 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2459 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2460 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2461 TRACE("not wraping\n");
2462 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2464 WARN("Could not get base nsWineURI: %08x\n", nsres);
2468 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2469 if(NS_FAILED(nsres))
2470 TRACE("NewURI failed: %08x\n", nsres);
2472 nsres = create_uri(uri, window, NULL, &wine_uri);
2473 *_retval = (nsIURI*)wine_uri;
2476 IHTMLWindow2_Release(HTMLWINDOW2(window));
2479 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2483 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2485 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2486 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2487 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2489 set_wine_url(wine_uri, url);
2491 WARN("CoCombineUrl failed: %08x\n", hres);
2492 }else if(is_wine_uri) {
2493 WCHAR url[INTERNET_MAX_URL_LENGTH];
2495 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2496 set_wine_url(wine_uri, url);
2500 nsIURI_Release(NSURI(base_wine_uri));
2505 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2508 TRACE("(%p %p)\n", aFile, _retval);
2509 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2512 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2513 nsIChannel **_retval)
2515 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2517 nsWineURI *wine_uri;
2520 TRACE("(%p %p)\n", aURI, _retval);
2522 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2523 if(NS_FAILED(nsres)) {
2524 TRACE("Could not get nsWineURI: %08x\n", nsres);
2525 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2528 ret = heap_alloc_zero(sizeof(nsChannel));
2530 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2531 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2532 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2534 ret->uri = wine_uri;
2536 nsIURI_AddRef(aURI);
2537 ret->original_uri = aURI;
2538 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2539 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2541 *_retval = NSCHANNEL(ret);
2545 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2546 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2548 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2549 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2552 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2554 TRACE("(%p)\n", aOffline);
2555 return nsIIOService_GetOffline(nsio, aOffline);
2558 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2560 TRACE("(%x)\n", aOffline);
2561 return nsIIOService_SetOffline(nsio, aOffline);
2564 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2565 const char *aScheme, PRBool *_retval)
2567 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2568 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2571 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2572 nsACString * _retval)
2574 TRACE("(%p %p)\n", urlString, _retval);
2575 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2578 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2579 nsIOService_QueryInterface,
2581 nsIOService_Release,
2582 nsIOService_GetProtocolHandler,
2583 nsIOService_GetProtocolFlags,
2585 nsIOService_NewFileURI,
2586 nsIOService_NewChannelFromURI,
2587 nsIOService_NewChannel,
2588 nsIOService_GetOffline,
2589 nsIOService_SetOffline,
2590 nsIOService_AllowPort,
2591 nsIOService_ExtractScheme
2594 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2596 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2599 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2602 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2607 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2612 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2613 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2615 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2617 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2620 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2624 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2627 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2629 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2631 if(aFlags == (1<<11)) {
2636 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2639 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2641 TRACE("(%p %p)\n", aURI, _retval);
2643 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2646 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2647 PRUint32 aEscapeType, nsACString *_retval)
2649 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2651 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2654 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2655 nsACString *_retval)
2657 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2659 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2662 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2663 PRUint32 aFlags, nsACString *_retval)
2665 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2667 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2670 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2671 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2673 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2675 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2678 static const nsINetUtilVtbl nsNetUtilVtbl = {
2679 nsNetUtil_QueryInterface,
2682 nsNetUtil_ParseContentType,
2683 nsNetUtil_ProtocolHasFlags,
2684 nsNetUtil_URIChainHasFlags,
2685 nsNetUtil_ToImmutableURI,
2686 nsNetUtil_EscapeString,
2687 nsNetUtil_EscapeURL,
2688 nsNetUtil_UnescapeString,
2689 nsNetUtil_ExtractCharsetFromContentType
2692 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2694 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2699 if(IsEqualGUID(&IID_nsISupports, riid))
2700 *result = &nsIOService;
2701 else if(IsEqualGUID(&IID_nsIIOService, riid))
2702 *result = &nsIOService;
2703 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2704 *result = &nsNetUtil;
2707 nsISupports_AddRef((nsISupports*)*result);
2711 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2712 return NS_NOINTERFACE;
2715 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2720 if(IsEqualGUID(&IID_nsISupports, riid)) {
2721 TRACE("(IID_nsISupports %p)\n", result);
2723 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2724 TRACE("(IID_nsIFactory %p)\n", result);
2729 nsIFactory_AddRef(iface);
2733 WARN("(%s %p)\n", debugstr_guid(riid), result);
2734 return NS_NOINTERFACE;
2737 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2742 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2747 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2748 nsISupports *aOuter, const nsIID *iid, void **result)
2750 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2753 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2755 WARN("(%x)\n", lock);
2759 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2760 nsIOServiceFactory_QueryInterface,
2761 nsIOServiceFactory_AddRef,
2762 nsIOServiceFactory_Release,
2763 nsIOServiceFactory_CreateInstance,
2764 nsIOServiceFactory_LockFactory
2767 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2769 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2771 nsIFactory *old_factory = NULL;
2774 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2775 &IID_nsIFactory, (void**)&old_factory);
2776 if(NS_FAILED(nsres)) {
2777 ERR("Could not get factory: %08x\n", nsres);
2781 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2782 if(NS_FAILED(nsres)) {
2783 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2784 nsIFactory_Release(old_factory);
2788 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2789 if(NS_FAILED(nsres)) {
2790 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2791 nsIIOService_Release(nsio);
2795 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2796 nsIFactory_Release(old_factory);
2797 if(NS_FAILED(nsres))
2798 ERR("UnregisterFactory failed: %08x\n", nsres);
2800 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2801 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2802 if(NS_FAILED(nsres))
2803 ERR("RegisterFactory failed: %08x\n", nsres);
2806 void release_nsio(void)
2809 nsINetUtil_Release(net_util);
2814 nsIIOService_Release(nsio);