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}};
47 static nsIIOService *nsio = NULL;
48 static nsINetUtil *net_util;
50 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
53 const nsIWineURIVtbl *lpWineURIVtbl;
59 NSContainer *container;
60 windowref_t *window_ref;
61 nsChannelBSC *channel_bsc;
67 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
68 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
70 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
72 static const char *debugstr_nsacstr(const nsACString *nsstr)
76 nsACString_GetData(nsstr, &data);
77 return debugstr_a(data);
80 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
82 const WCHAR *ptr = nsuri;
84 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
86 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
87 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
89 if(*ptr || ret_empty) {
90 *ret = SysAllocString(ptr);
97 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
101 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
103 IOleCommandTarget *cmdtrg = NULL;
106 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
107 if(SUCCEEDED(hres)) {
108 VARIANT varUrl, varRes;
110 V_VT(&varUrl) = VT_BSTR;
111 V_BSTR(&varUrl) = SysAllocString(url);
112 V_VT(&varRes) = VT_BOOL;
114 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
116 IOleCommandTarget_Release(cmdtrg);
117 SysFreeString(V_BSTR(&varUrl));
119 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
120 TRACE("got VARIANT_FALSE, do not load\n");
128 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
130 HTMLDocumentObj *doc = container->doc;
135 NSContainer *container_iter = container;
137 hlnf = HLNF_OPENINNEWWINDOW;
138 while(!container_iter->doc)
139 container_iter = container_iter->parent;
140 doc = container_iter->doc;
146 if(!hlnf && !exec_shldocvw_67(doc, channel->uri->wine_url))
149 hres = hlink_frame_navigate(&doc->basedoc, channel->uri->wine_url, channel->post_data_stream, hlnf);
153 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
155 nsIWebNavigation *web_navigation;
156 nsIDocShell *doc_shell;
159 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
160 if(NS_FAILED(nsres)) {
161 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
165 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
166 nsIWebNavigation_Release(web_navigation);
167 if(NS_FAILED(nsres)) {
168 ERR("Could not get nsIDocShell: %08x\n", nsres);
173 uri->channel_bsc = channelbsc;
174 nsres = nsIDocShell_LoadURI(doc_shell, NSURI(uri), NULL, flags, FALSE);
175 uri->channel_bsc = NULL;
176 nsIDocShell_Release(doc_shell);
177 if(NS_FAILED(nsres)) {
178 WARN("LoadURI failed: %08x\n", nsres);
185 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
187 OLECHAR *new_url = NULL, *url;
194 url = heap_strdupW(uri->wine_url);
195 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
197 if(hres != S_OK || !new_url)
200 if(strcmpW(url, new_url)) {
201 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
205 CoTaskMemFree(new_url);
209 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
216 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
217 if(NS_FAILED(nsres)) {
218 WARN("Could not get nsWineURI: %08x\n", nsres);
219 return NS_ERROR_NOT_IMPLEMENTED;
222 if(!wine_uri->is_doc_uri) {
223 if(!wine_uri->container) {
224 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
225 wine_uri->container = nscontainer;
228 wine_uri->is_doc_uri = TRUE;
229 *_retval = translate_url(nscontainer->doc->basedoc.doc_obj, wine_uri);
232 nsIURI_Release(NSURI(wine_uri));
236 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
238 nsIWineURI_SetWineURL(NSWINEURI(This), url);
242 static inline BOOL is_http_channel(nsChannel *This)
244 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTP;
247 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
249 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
251 nsChannel *This = NSCHANNEL_THIS(iface);
253 if(IsEqualGUID(&IID_nsISupports, riid)) {
254 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
255 *result = NSCHANNEL(This);
256 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
257 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
258 *result = NSCHANNEL(This);
259 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
260 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
261 *result = NSCHANNEL(This);
262 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
263 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
264 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
265 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
266 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
267 *result = NSUPCHANNEL(This);
268 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
269 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
270 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
272 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
277 nsIChannel_AddRef(NSCHANNEL(This));
281 return NS_NOINTERFACE;
284 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
286 nsChannel *This = NSCHANNEL_THIS(iface);
287 nsrefcnt ref = InterlockedIncrement(&This->ref);
289 TRACE("(%p) ref=%d\n", This, ref);
294 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
296 nsChannel *This = NSCHANNEL_THIS(iface);
297 LONG ref = InterlockedDecrement(&This->ref);
300 nsIURI_Release(NSURI(This->uri));
302 nsISupports_Release(This->owner);
303 if(This->post_data_stream)
304 nsIInputStream_Release(This->post_data_stream);
306 nsILoadGroup_Release(This->load_group);
307 if(This->notif_callback)
308 nsIInterfaceRequestor_Release(This->notif_callback);
309 if(This->original_uri)
310 nsIURI_Release(This->original_uri);
311 heap_free(This->content_type);
312 heap_free(This->charset);
319 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
321 nsChannel *This = NSCHANNEL_THIS(iface);
323 FIXME("(%p)->(%p)\n", This, aName);
325 return NS_ERROR_NOT_IMPLEMENTED;
328 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
330 nsChannel *This = NSCHANNEL_THIS(iface);
332 FIXME("(%p)->(%p)\n", This, _retval);
334 return NS_ERROR_NOT_IMPLEMENTED;
337 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
339 nsChannel *This = NSCHANNEL_THIS(iface);
341 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
343 return *aStatus = NS_OK;
346 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
348 nsChannel *This = NSCHANNEL_THIS(iface);
350 FIXME("(%p)->(%08x)\n", This, aStatus);
352 return NS_ERROR_NOT_IMPLEMENTED;
355 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
357 nsChannel *This = NSCHANNEL_THIS(iface);
359 FIXME("(%p)\n", This);
361 return NS_ERROR_NOT_IMPLEMENTED;
364 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
366 nsChannel *This = NSCHANNEL_THIS(iface);
368 FIXME("(%p)\n", This);
370 return NS_ERROR_NOT_IMPLEMENTED;
373 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
375 nsChannel *This = NSCHANNEL_THIS(iface);
377 TRACE("(%p)->(%p)\n", This, aLoadGroup);
380 nsILoadGroup_AddRef(This->load_group);
382 *aLoadGroup = This->load_group;
386 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
388 nsChannel *This = NSCHANNEL_THIS(iface);
390 TRACE("(%p)->(%p)\n", This, aLoadGroup);
393 nsILoadGroup_Release(This->load_group);
395 nsILoadGroup_AddRef(aLoadGroup);
396 This->load_group = aLoadGroup;
401 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
403 nsChannel *This = NSCHANNEL_THIS(iface);
405 TRACE("(%p)->(%p)\n", This, aLoadFlags);
407 *aLoadFlags = This->load_flags;
411 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
413 nsChannel *This = NSCHANNEL_THIS(iface);
415 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
417 This->load_flags = aLoadFlags;
421 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
423 nsChannel *This = NSCHANNEL_THIS(iface);
425 TRACE("(%p)->(%p)\n", This, aOriginalURI);
427 if(This->original_uri)
428 nsIURI_AddRef(This->original_uri);
430 *aOriginalURI = This->original_uri;
434 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
436 nsChannel *This = NSCHANNEL_THIS(iface);
438 TRACE("(%p)->(%p)\n", This, aOriginalURI);
440 if(This->original_uri)
441 nsIURI_Release(This->original_uri);
443 nsIURI_AddRef(aOriginalURI);
444 This->original_uri = aOriginalURI;
448 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
450 nsChannel *This = NSCHANNEL_THIS(iface);
452 TRACE("(%p)->(%p)\n", This, aURI);
454 nsIURI_AddRef(NSURI(This->uri));
455 *aURI = (nsIURI*)This->uri;
460 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
462 nsChannel *This = NSCHANNEL_THIS(iface);
464 TRACE("(%p)->(%p)\n", This, aOwner);
467 nsISupports_AddRef(This->owner);
468 *aOwner = This->owner;
473 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
475 nsChannel *This = NSCHANNEL_THIS(iface);
477 TRACE("(%p)->(%p)\n", This, aOwner);
480 nsISupports_AddRef(aOwner);
482 nsISupports_Release(This->owner);
483 This->owner = aOwner;
488 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
489 nsIInterfaceRequestor **aNotificationCallbacks)
491 nsChannel *This = NSCHANNEL_THIS(iface);
493 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
495 if(This->notif_callback)
496 nsIInterfaceRequestor_AddRef(This->notif_callback);
497 *aNotificationCallbacks = This->notif_callback;
502 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
503 nsIInterfaceRequestor *aNotificationCallbacks)
505 nsChannel *This = NSCHANNEL_THIS(iface);
507 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
509 if(This->notif_callback)
510 nsIInterfaceRequestor_Release(This->notif_callback);
511 if(aNotificationCallbacks)
512 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
514 This->notif_callback = aNotificationCallbacks;
519 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
521 nsChannel *This = NSCHANNEL_THIS(iface);
523 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
525 return NS_ERROR_NOT_IMPLEMENTED;
528 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
530 nsChannel *This = NSCHANNEL_THIS(iface);
532 TRACE("(%p)->(%p)\n", This, aContentType);
534 if(This->content_type) {
535 nsACString_SetData(aContentType, This->content_type);
539 WARN("unknown type\n");
540 return NS_ERROR_FAILURE;
543 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
544 const nsACString *aContentType)
546 nsChannel *This = NSCHANNEL_THIS(iface);
547 const char *content_type;
549 TRACE("(%p)->(%p)\n", This, aContentType);
551 nsACString_GetData(aContentType, &content_type);
553 TRACE("content_type %s\n", content_type);
555 heap_free(This->content_type);
556 This->content_type = heap_strdupA(content_type);
561 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
562 nsACString *aContentCharset)
564 nsChannel *This = NSCHANNEL_THIS(iface);
566 TRACE("(%p)->(%p)\n", This, aContentCharset);
569 nsACString_SetData(aContentCharset, This->charset);
573 nsACString_SetData(aContentCharset, "");
577 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
578 const nsACString *aContentCharset)
580 nsChannel *This = NSCHANNEL_THIS(iface);
582 FIXME("(%p)->(%p)\n", This, aContentCharset);
584 return NS_ERROR_NOT_IMPLEMENTED;
587 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
589 nsChannel *This = NSCHANNEL_THIS(iface);
591 FIXME("(%p)->(%p)\n", This, aContentLength);
593 return NS_ERROR_NOT_IMPLEMENTED;
596 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
598 nsChannel *This = NSCHANNEL_THIS(iface);
600 FIXME("(%p)->(%d)\n", This, aContentLength);
602 return NS_ERROR_NOT_IMPLEMENTED;
605 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
607 nsChannel *This = NSCHANNEL_THIS(iface);
609 FIXME("(%p)->(%p)\n", This, _retval);
611 return NS_ERROR_NOT_IMPLEMENTED;
614 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
616 nsIWineURI *wine_uri;
621 if(!channel->original_uri) {
622 ERR("original_uri == NULL\n");
626 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
627 if(NS_FAILED(nsres)) {
628 ERR("Could not get nsIWineURI: %08x\n", nsres);
632 nsIWineURI_GetWineURL(wine_uri, &wine_url);
633 nsIWineURI_Release(wine_uri);
635 TRACE("wine_url == NULL\n");
639 hres = CreateURLMoniker(NULL, wine_url, mon);
641 WARN("CreateURLMoniker failed: %08x\n", hres);
646 static HTMLWindow *get_window_from_load_group(nsChannel *This)
651 nsIWineURI *wine_uri;
655 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
656 if(NS_FAILED(nsres)) {
657 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
664 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
665 nsIRequest_Release(req);
666 if(NS_FAILED(nsres)) {
667 WARN("Could not get nsIChannel interface: %08x\n", nsres);
671 nsres = nsIChannel_GetURI(channel, &uri);
672 nsIChannel_Release(channel);
673 if(NS_FAILED(nsres)) {
674 ERR("GetURI failed: %08x\n", nsres);
678 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
680 if(NS_FAILED(nsres)) {
681 TRACE("Could not get nsIWineURI: %08x\n", nsres);
685 nsIWineURI_GetWindow(wine_uri, &window);
686 nsIWineURI_Release(wine_uri);
691 static HTMLWindow *get_channel_window(nsChannel *This)
693 nsIRequestObserver *req_observer;
694 nsIWebProgress *web_progress;
695 nsIDOMWindow *nswindow;
699 if(!This->load_group) {
700 ERR("NULL load_group\n");
704 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
705 if(NS_FAILED(nsres) || !req_observer) {
706 ERR("GetGroupObserver failed: %08x\n", nsres);
710 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
711 nsIRequestObserver_Release(req_observer);
712 if(NS_FAILED(nsres)) {
713 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
717 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
718 nsIWebProgress_Release(web_progress);
719 if(NS_FAILED(nsres) || !nswindow) {
720 ERR("GetDOMWindow failed: %08x\n", nsres);
724 window = nswindow_to_window(nswindow);
725 nsIDOMWindow_Release(nswindow);
728 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
730 FIXME("NULL window for %p\n", nswindow);
736 HTMLDocumentNode *doc;
737 nsChannelBSC *bscallback;
738 } start_binding_task_t;
740 static void start_binding_proc(task_t *_task)
742 start_binding_task_t *task = (start_binding_task_t*)_task;
744 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
750 nsChannelBSC *bscallback;
751 } start_doc_binding_task_t;
753 static void start_doc_binding_proc(task_t *_task)
755 start_doc_binding_task_t *task = (start_doc_binding_task_t*)_task;
757 start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
758 IUnknown_Release((IUnknown*)task->bscallback);
761 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
762 nsISupports *context)
764 nsChannelBSC *bscallback;
765 IMoniker *mon = NULL;
768 hres = create_mon_for_nschannel(This, &mon);
770 return NS_ERROR_UNEXPECTED;
773 set_current_mon(window, mon);
775 bscallback = create_channelbsc(mon);
776 IMoniker_Release(mon);
778 channelbsc_set_channel(bscallback, This, listener, context);
781 start_doc_binding_task_t *task;
783 set_window_bscallback(window, bscallback);
785 task = heap_alloc(sizeof(start_doc_binding_task_t));
786 task->window = window;
787 task->bscallback = bscallback;
788 push_task(&task->header, start_doc_binding_proc, window->task_magic);
790 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
792 task->doc = window->doc;
793 task->bscallback = bscallback;
794 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
800 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
801 nsISupports *aContext)
803 nsChannel *This = NSCHANNEL_THIS(iface);
804 HTMLWindow *window = NULL;
806 nsresult nsres = NS_OK;
808 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
810 if(This->uri->is_doc_uri) {
811 window = get_channel_window(This);
813 nsIWineURI_SetWindow(NSWINEURI(This->uri), window);
814 }else if(This->uri->container) {
817 /* nscontainer->doc should be NULL which means navigation to a new window */
818 if(This->uri->container->doc)
819 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
821 b = before_async_open(This, This->uri->container);
823 FIXME("Navigation not cancelled\n");
824 return NS_ERROR_UNEXPECTED;
829 nsIWineURI_GetWindow(NSWINEURI(This->uri), &window);
831 if(!window && This->load_group) {
832 window = get_window_from_load_group(This);
834 nsIWineURI_SetWindow(NSWINEURI(This->uri), window);
839 ERR("window = NULL\n");
840 return NS_ERROR_UNEXPECTED;
843 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
844 if(This->uri->channel_bsc) {
845 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
847 if(window->doc_obj->mime) {
848 heap_free(This->content_type);
849 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
854 open = before_async_open(This, window->doc_obj->nscontainer);
857 nsres = NS_ERROR_UNEXPECTED;
863 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
865 IHTMLWindow2_Release(HTMLWINDOW2(window));
869 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
871 nsChannel *This = NSCHANNEL_THIS(iface);
873 FIXME("(%p)->(%p)\n", This, aRequestMethod);
875 return NS_ERROR_NOT_IMPLEMENTED;
878 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
879 const nsACString *aRequestMethod)
881 nsChannel *This = NSCHANNEL_THIS(iface);
883 FIXME("(%p)->(%p)\n", This, aRequestMethod);
885 return NS_ERROR_NOT_IMPLEMENTED;
888 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
890 nsChannel *This = NSCHANNEL_THIS(iface);
892 FIXME("(%p)->(%p)\n", This, aReferrer);
894 return NS_ERROR_NOT_IMPLEMENTED;
897 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
899 nsChannel *This = NSCHANNEL_THIS(iface);
901 FIXME("(%p)->(%p)\n", This, aReferrer);
906 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
907 const nsACString *aHeader, nsACString *_retval)
909 nsChannel *This = NSCHANNEL_THIS(iface);
911 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
913 return NS_ERROR_NOT_IMPLEMENTED;
916 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
917 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
919 nsChannel *This = NSCHANNEL_THIS(iface);
921 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
926 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
927 nsIHttpHeaderVisitor *aVisitor)
929 nsChannel *This = NSCHANNEL_THIS(iface);
931 FIXME("(%p)->(%p)\n", This, aVisitor);
933 return NS_ERROR_NOT_IMPLEMENTED;
936 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
938 nsChannel *This = NSCHANNEL_THIS(iface);
940 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
942 return NS_ERROR_NOT_IMPLEMENTED;
945 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
947 nsChannel *This = NSCHANNEL_THIS(iface);
949 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
951 return NS_ERROR_NOT_IMPLEMENTED;
954 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
956 nsChannel *This = NSCHANNEL_THIS(iface);
958 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
960 return NS_ERROR_NOT_IMPLEMENTED;
963 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
965 nsChannel *This = NSCHANNEL_THIS(iface);
967 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
969 return NS_ERROR_NOT_IMPLEMENTED;
972 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
974 nsChannel *This = NSCHANNEL_THIS(iface);
976 TRACE("(%p)->(%p)\n", This, aResponseStatus);
978 if(This->response_status) {
979 *aResponseStatus = This->response_status;
983 WARN("No response status\n");
984 return NS_ERROR_UNEXPECTED;
987 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
988 nsACString *aResponseStatusText)
990 nsChannel *This = NSCHANNEL_THIS(iface);
992 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
994 return NS_ERROR_NOT_IMPLEMENTED;
997 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
998 PRBool *aRequestSucceeded)
1000 nsChannel *This = NSCHANNEL_THIS(iface);
1002 FIXME("(%p)->(%p)\n", This, aRequestSucceeded);
1004 return NS_ERROR_NOT_IMPLEMENTED;
1007 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1008 const nsACString *header, nsACString *_retval)
1010 nsChannel *This = NSCHANNEL_THIS(iface);
1012 FIXME("(%p)->(%p %p)\n", This, header, _retval);
1014 return NS_ERROR_NOT_IMPLEMENTED;
1017 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1018 const nsACString *header, const nsACString *value, PRBool merge)
1020 nsChannel *This = NSCHANNEL_THIS(iface);
1022 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
1024 return NS_ERROR_NOT_IMPLEMENTED;
1027 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1028 nsIHttpHeaderVisitor *aVisitor)
1030 nsChannel *This = NSCHANNEL_THIS(iface);
1032 FIXME("(%p)->(%p)\n", This, aVisitor);
1034 return NS_ERROR_NOT_IMPLEMENTED;
1037 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1039 nsChannel *This = NSCHANNEL_THIS(iface);
1041 FIXME("(%p)->(%p)\n", This, _retval);
1043 return NS_ERROR_NOT_IMPLEMENTED;
1046 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1048 nsChannel *This = NSCHANNEL_THIS(iface);
1050 FIXME("(%p)->(%p)\n", This, _retval);
1052 return NS_ERROR_NOT_IMPLEMENTED;
1055 #undef NSCHANNEL_THIS
1057 static const nsIHttpChannelVtbl nsChannelVtbl = {
1058 nsChannel_QueryInterface,
1062 nsChannel_IsPending,
1063 nsChannel_GetStatus,
1067 nsChannel_GetLoadGroup,
1068 nsChannel_SetLoadGroup,
1069 nsChannel_GetLoadFlags,
1070 nsChannel_SetLoadFlags,
1071 nsChannel_GetOriginalURI,
1072 nsChannel_SetOriginalURI,
1076 nsChannel_GetNotificationCallbacks,
1077 nsChannel_SetNotificationCallbacks,
1078 nsChannel_GetSecurityInfo,
1079 nsChannel_GetContentType,
1080 nsChannel_SetContentType,
1081 nsChannel_GetContentCharset,
1082 nsChannel_SetContentCharset,
1083 nsChannel_GetContentLength,
1084 nsChannel_SetContentLength,
1086 nsChannel_AsyncOpen,
1087 nsChannel_GetRequestMethod,
1088 nsChannel_SetRequestMethod,
1089 nsChannel_GetReferrer,
1090 nsChannel_SetReferrer,
1091 nsChannel_GetRequestHeader,
1092 nsChannel_SetRequestHeader,
1093 nsChannel_VisitRequestHeaders,
1094 nsChannel_GetAllowPipelining,
1095 nsChannel_SetAllowPipelining,
1096 nsChannel_GetRedirectionLimit,
1097 nsChannel_SetRedirectionLimit,
1098 nsChannel_GetResponseStatus,
1099 nsChannel_GetResponseStatusText,
1100 nsChannel_GetRequestSucceeded,
1101 nsChannel_GetResponseHeader,
1102 nsChannel_SetResponseHeader,
1103 nsChannel_VisitResponseHeaders,
1104 nsChannel_IsNoStoreResponse,
1105 nsChannel_IsNoCacheResponse
1108 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1110 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1113 nsChannel *This = NSUPCHANNEL_THIS(iface);
1114 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1117 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1119 nsChannel *This = NSUPCHANNEL_THIS(iface);
1120 return nsIChannel_AddRef(NSCHANNEL(This));
1123 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1125 nsChannel *This = NSUPCHANNEL_THIS(iface);
1126 return nsIChannel_Release(NSCHANNEL(This));
1129 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1130 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1132 nsChannel *This = NSUPCHANNEL_THIS(iface);
1133 const char *content_type;
1135 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1137 if(This->post_data_stream)
1138 nsIInputStream_Release(This->post_data_stream);
1141 nsACString_GetData(aContentType, &content_type);
1143 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1146 if(aContentLength != -1)
1147 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1149 if(This->post_data_stream)
1150 nsIInputStream_Release(This->post_data_stream);
1151 This->post_data_stream = aStream;
1153 nsIInputStream_AddRef(aStream);
1158 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1159 nsIInputStream **aUploadStream)
1161 nsChannel *This = NSUPCHANNEL_THIS(iface);
1163 TRACE("(%p)->(%p)\n", This, aUploadStream);
1165 if(This->post_data_stream)
1166 nsIInputStream_AddRef(This->post_data_stream);
1168 *aUploadStream = This->post_data_stream;
1172 #undef NSUPCHANNEL_THIS
1174 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1175 nsUploadChannel_QueryInterface,
1176 nsUploadChannel_AddRef,
1177 nsUploadChannel_Release,
1178 nsUploadChannel_SetUploadStream,
1179 nsUploadChannel_GetUploadStream
1182 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1184 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1187 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1188 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1191 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1193 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1194 return nsIChannel_AddRef(NSCHANNEL(This));
1197 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1199 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1200 return nsIChannel_Release(NSCHANNEL(This));
1203 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1205 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1207 FIXME("(%p)->()\n", This);
1209 return NS_ERROR_NOT_IMPLEMENTED;
1212 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1214 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1216 FIXME("(%p)->()\n", This);
1218 return NS_ERROR_NOT_IMPLEMENTED;
1221 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1223 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1225 FIXME("(%p)->()\n", This);
1227 return NS_ERROR_NOT_IMPLEMENTED;
1230 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1232 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1234 FIXME("(%p)->()\n", This);
1236 return NS_ERROR_NOT_IMPLEMENTED;
1239 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1241 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1243 FIXME("(%p)->()\n", This);
1245 return NS_ERROR_NOT_IMPLEMENTED;
1248 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1250 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1252 FIXME("(%p)->()\n", This);
1254 return NS_ERROR_NOT_IMPLEMENTED;
1257 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1259 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1261 FIXME("(%p)->()\n", This);
1263 return NS_ERROR_NOT_IMPLEMENTED;
1266 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1268 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1270 FIXME("(%p)->()\n", This);
1272 return NS_ERROR_NOT_IMPLEMENTED;
1275 #undef NSHTTPINTERNAL_THIS
1277 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1278 nsHttpChannelInternal_QueryInterface,
1279 nsHttpChannelInternal_AddRef,
1280 nsHttpChannelInternal_Release,
1281 nsHttpChannelInternal_GetDocumentURI,
1282 nsHttpChannelInternal_SetDocumentURI,
1283 nsHttpChannelInternal_GetRequestVersion,
1284 nsHttpChannelInternal_GetResponseVersion,
1285 nsHttpChannelInternal_SetCookie,
1286 nsHttpChannelInternal_SetupFallbackChannel,
1287 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1288 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1291 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, WineURI, iface)
1293 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1295 nsWineURI *This = NSURI_THIS(iface);
1299 if(IsEqualGUID(&IID_nsISupports, riid)) {
1300 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1301 *result = NSURI(This);
1302 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1303 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1304 *result = NSURI(This);
1305 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1306 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1307 *result = NSURI(This);
1308 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1309 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1310 *result = NSURI(This);
1314 nsIURI_AddRef(NSURI(This));
1318 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1319 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1322 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1324 nsWineURI *This = NSURI_THIS(iface);
1325 LONG ref = InterlockedIncrement(&This->ref);
1327 TRACE("(%p) ref=%d\n", This, ref);
1332 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1334 nsWineURI *This = NSURI_THIS(iface);
1335 LONG ref = InterlockedDecrement(&This->ref);
1337 TRACE("(%p) ref=%d\n", This, ref);
1340 if(This->window_ref)
1341 windowref_release(This->window_ref);
1343 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1345 nsIURL_Release(This->nsurl);
1347 nsIURI_Release(This->uri);
1348 heap_free(This->wine_url);
1355 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1357 nsWineURI *This = NSURI_THIS(iface);
1359 TRACE("(%p)->(%p)\n", This, aSpec);
1361 if(This->use_wine_url) {
1362 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1363 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1364 nsACString_SetData(aSpec, speca);
1370 return nsIURI_GetSpec(This->uri, aSpec);
1372 TRACE("returning error\n");
1373 return NS_ERROR_NOT_IMPLEMENTED;
1377 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1379 nsWineURI *This = NSURI_THIS(iface);
1381 TRACE("(%p)->(%p)\n", This, aSpec);
1384 return nsIURI_SetSpec(This->uri, aSpec);
1386 FIXME("default action not implemented\n");
1387 return NS_ERROR_NOT_IMPLEMENTED;
1390 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1392 nsWineURI *This = NSURI_THIS(iface);
1394 TRACE("(%p)->(%p)\n", This, aPrePath);
1397 return nsIURI_GetPrePath(This->uri, aPrePath);
1399 FIXME("default action not implemented\n");
1400 return NS_ERROR_NOT_IMPLEMENTED;
1403 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1405 nsWineURI *This = NSURI_THIS(iface);
1407 TRACE("(%p)->(%p)\n", This, aScheme);
1409 if(This->use_wine_url) {
1411 * For Gecko we set scheme to unknown so it won't be handled
1412 * as any special case.
1414 nsACString_SetData(aScheme, "wine");
1419 return nsIURI_GetScheme(This->uri, aScheme);
1421 TRACE("returning error\n");
1422 return NS_ERROR_NOT_IMPLEMENTED;
1425 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1427 nsWineURI *This = NSURI_THIS(iface);
1429 TRACE("(%p)->(%p)\n", This, aScheme);
1432 return nsIURI_SetScheme(This->uri, aScheme);
1434 FIXME("default action not implemented\n");
1435 return NS_ERROR_NOT_IMPLEMENTED;
1438 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1440 nsWineURI *This = NSURI_THIS(iface);
1442 TRACE("(%p)->(%p)\n", This, aUserPass);
1445 return nsIURI_GetUserPass(This->uri, aUserPass);
1447 FIXME("default action not implemented\n");
1448 return NS_ERROR_NOT_IMPLEMENTED;
1451 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1453 nsWineURI *This = NSURI_THIS(iface);
1455 TRACE("(%p)->(%p)\n", This, aUserPass);
1458 return nsIURI_SetUserPass(This->uri, aUserPass);
1460 FIXME("default action not implemented\n");
1461 return NS_ERROR_NOT_IMPLEMENTED;
1464 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1466 nsWineURI *This = NSURI_THIS(iface);
1468 TRACE("(%p)->(%p)\n", This, aUsername);
1471 return nsIURI_GetUsername(This->uri, aUsername);
1473 FIXME("default action not implemented\n");
1474 return NS_ERROR_NOT_IMPLEMENTED;
1477 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1479 nsWineURI *This = NSURI_THIS(iface);
1481 TRACE("(%p)->(%p)\n", This, aUsername);
1484 return nsIURI_SetUsername(This->uri, aUsername);
1486 FIXME("default action not implemented\n");
1487 return NS_ERROR_NOT_IMPLEMENTED;
1490 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1492 nsWineURI *This = NSURI_THIS(iface);
1494 TRACE("(%p)->(%p)\n", This, aPassword);
1497 return nsIURI_GetPassword(This->uri, aPassword);
1499 FIXME("default action not implemented\n");
1500 return NS_ERROR_NOT_IMPLEMENTED;
1503 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1505 nsWineURI *This = NSURI_THIS(iface);
1507 TRACE("(%p)->(%p)\n", This, aPassword);
1510 return nsIURI_SetPassword(This->uri, aPassword);
1512 FIXME("default action not implemented\n");
1513 return NS_ERROR_NOT_IMPLEMENTED;
1516 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1518 nsWineURI *This = NSURI_THIS(iface);
1520 TRACE("(%p)->(%p)\n", This, aHostPort);
1523 return nsIURI_GetHostPort(This->uri, aHostPort);
1525 FIXME("default action not implemented\n");
1526 return NS_ERROR_NOT_IMPLEMENTED;
1529 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1531 nsWineURI *This = NSURI_THIS(iface);
1533 TRACE("(%p)->(%p)\n", This, aHostPort);
1536 return nsIURI_SetHostPort(This->uri, aHostPort);
1538 FIXME("default action not implemented\n");
1539 return NS_ERROR_NOT_IMPLEMENTED;
1542 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1544 nsWineURI *This = NSURI_THIS(iface);
1546 TRACE("(%p)->(%p)\n", This, aHost);
1549 return nsIURI_GetHost(This->uri, aHost);
1551 FIXME("default action not implemented\n");
1552 return NS_ERROR_NOT_IMPLEMENTED;
1555 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1557 nsWineURI *This = NSURI_THIS(iface);
1559 TRACE("(%p)->(%p)\n", This, aHost);
1562 return nsIURI_SetHost(This->uri, aHost);
1564 FIXME("default action not implemented\n");
1565 return NS_ERROR_NOT_IMPLEMENTED;
1568 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1570 nsWineURI *This = NSURI_THIS(iface);
1572 TRACE("(%p)->(%p)\n", This, aPort);
1575 return nsIURI_GetPort(This->uri, aPort);
1577 FIXME("default action not implemented\n");
1578 return NS_ERROR_NOT_IMPLEMENTED;
1581 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1583 nsWineURI *This = NSURI_THIS(iface);
1585 TRACE("(%p)->(%d)\n", This, aPort);
1588 return nsIURI_SetPort(This->uri, aPort);
1590 FIXME("default action not implemented\n");
1591 return NS_ERROR_NOT_IMPLEMENTED;
1594 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1596 nsWineURI *This = NSURI_THIS(iface);
1598 TRACE("(%p)->(%p)\n", This, aPath);
1601 return nsIURI_GetPath(This->uri, aPath);
1603 FIXME("default action not implemented\n");
1604 return NS_ERROR_NOT_IMPLEMENTED;
1607 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1609 nsWineURI *This = NSURI_THIS(iface);
1612 nsACString_GetData(aPath, &path);
1613 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1616 if(This->wine_url) {
1617 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1618 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1622 pathw = heap_strdupAtoW(path);
1623 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1626 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1628 WARN("UrlCombine failed: %08x\n", hres);
1634 return nsIURI_SetPath(This->uri, aPath);
1637 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1639 nsWineURI *This = NSURI_THIS(iface);
1640 nsIWineURI *wine_uri;
1641 LPCWSTR other_url = NULL;
1644 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1647 return nsIURI_Equals(This->uri, other, _retval);
1649 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1650 if(NS_FAILED(nsres)) {
1651 TRACE("Could not get nsIWineURI interface\n");
1656 nsIWineURI_GetWineURL(wine_uri, &other_url);
1657 *_retval = other_url && !UrlCompareW(This->wine_url, other_url, TRUE);
1658 nsIWineURI_Release(wine_uri);
1663 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1665 nsWineURI *This = NSURI_THIS(iface);
1667 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1669 if(This->use_wine_url) {
1670 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1671 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1673 *_retval = lstrlenW(This->wine_url) > len
1674 && This->wine_url[len] == ':'
1675 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1680 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1682 TRACE("returning error\n");
1683 return NS_ERROR_NOT_IMPLEMENTED;
1686 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1688 nsWineURI *This = NSURI_THIS(iface);
1689 nsIURI *nsuri = NULL;
1690 nsWineURI *wine_uri;
1693 TRACE("(%p)->(%p)\n", This, _retval);
1696 nsres = nsIURI_Clone(This->uri, &nsuri);
1697 if(NS_FAILED(nsres)) {
1698 WARN("Clone failed: %08x\n", nsres);
1703 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1704 if(NS_FAILED(nsres)) {
1705 WARN("create_uri failed: %08x\n", nsres);
1709 *_retval = NSURI(wine_uri);
1710 return nsIWineURI_SetWineURL(NSWINEURI(wine_uri), This->wine_url);
1713 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1714 nsACString *_retval)
1716 nsWineURI *This = NSURI_THIS(iface);
1718 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1721 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1723 FIXME("default action not implemented\n");
1724 return NS_ERROR_NOT_IMPLEMENTED;
1727 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1729 nsWineURI *This = NSURI_THIS(iface);
1731 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1733 if(This->use_wine_url)
1734 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1737 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1739 TRACE("returning error\n");
1740 return NS_ERROR_NOT_IMPLEMENTED;
1743 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1745 nsWineURI *This = NSURI_THIS(iface);
1747 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1750 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1752 FIXME("default action not implemented\n");
1753 return NS_ERROR_NOT_IMPLEMENTED;
1756 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1758 nsWineURI *This = NSURI_THIS(iface);
1760 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1763 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1765 FIXME("default action not implemented\n");
1766 return NS_ERROR_NOT_IMPLEMENTED;
1769 static nsresult NSAPI nsURL_GetFilePath(nsIWineURI *iface, nsACString *aFilePath)
1771 nsWineURI *This = NSURI_THIS(iface);
1773 TRACE("(%p)->(%p)\n", This, aFilePath);
1776 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1778 FIXME("default action not implemented\n");
1779 return NS_ERROR_NOT_IMPLEMENTED;
1782 static nsresult NSAPI nsURL_SetFilePath(nsIWineURI *iface, const nsACString *aFilePath)
1784 nsWineURI *This = NSURI_THIS(iface);
1786 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1789 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1791 FIXME("default action not implemented\n");
1792 return NS_ERROR_NOT_IMPLEMENTED;
1795 static nsresult NSAPI nsURL_GetParam(nsIWineURI *iface, nsACString *aParam)
1797 nsWineURI *This = NSURI_THIS(iface);
1799 TRACE("(%p)->(%p)\n", This, aParam);
1802 return nsIURL_GetParam(This->nsurl, aParam);
1804 FIXME("default action not implemented\n");
1805 return NS_ERROR_NOT_IMPLEMENTED;
1808 static nsresult NSAPI nsURL_SetParam(nsIWineURI *iface, const nsACString *aParam)
1810 nsWineURI *This = NSURI_THIS(iface);
1812 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1815 return nsIURL_SetParam(This->nsurl, aParam);
1817 FIXME("default action not implemented\n");
1818 return NS_ERROR_NOT_IMPLEMENTED;
1821 static nsresult NSAPI nsURL_GetQuery(nsIWineURI *iface, nsACString *aQuery)
1823 nsWineURI *This = NSURI_THIS(iface);
1825 TRACE("(%p)->(%p)\n", This, aQuery);
1828 return nsIURL_GetQuery(This->nsurl, aQuery);
1830 FIXME("default action not implemented\n");
1831 return NS_ERROR_NOT_IMPLEMENTED;
1834 static nsresult NSAPI nsURL_SetQuery(nsIWineURI *iface, const nsACString *aQuery)
1836 nsWineURI *This = NSURI_THIS(iface);
1837 const WCHAR *ptr1, *ptr2;
1839 WCHAR *new_url, *ptr;
1842 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1845 nsIURL_SetQuery(This->nsurl, aQuery);
1850 nsACString_GetData(aQuery, &query);
1851 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1852 ptr1 = strchrW(This->wine_url, '?');
1854 size += ptr1-This->wine_url;
1855 ptr2 = strchrW(ptr1, '#');
1857 size += strlenW(ptr2);
1859 ptr1 = This->wine_url + strlenW(This->wine_url);
1861 size += strlenW(This->wine_url);
1867 new_url = heap_alloc(size*sizeof(WCHAR));
1868 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1869 ptr = new_url + (ptr1-This->wine_url);
1872 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1880 TRACE("setting %s\n", debugstr_w(new_url));
1882 heap_free(This->wine_url);
1883 This->wine_url = new_url;
1887 static nsresult NSAPI nsURL_GetRef(nsIWineURI *iface, nsACString *aRef)
1889 nsWineURI *This = NSURI_THIS(iface);
1891 TRACE("(%p)->(%p)\n", This, aRef);
1894 return nsIURL_GetRef(This->nsurl, aRef);
1896 FIXME("default action not implemented\n");
1897 return NS_ERROR_NOT_IMPLEMENTED;
1900 static nsresult NSAPI nsURL_SetRef(nsIWineURI *iface, const nsACString *aRef)
1902 nsWineURI *This = NSURI_THIS(iface);
1905 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1908 return nsIURL_SetRef(This->nsurl, aRef);
1910 nsACString_GetData(aRef, &refa);
1914 FIXME("default action not implemented\n");
1915 return NS_ERROR_NOT_IMPLEMENTED;
1918 static nsresult NSAPI nsURL_GetDirectory(nsIWineURI *iface, nsACString *aDirectory)
1920 nsWineURI *This = NSURI_THIS(iface);
1922 TRACE("(%p)->(%p)\n", This, aDirectory);
1925 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1927 FIXME("default action not implemented\n");
1928 return NS_ERROR_NOT_IMPLEMENTED;
1931 static nsresult NSAPI nsURL_SetDirectory(nsIWineURI *iface, const nsACString *aDirectory)
1933 nsWineURI *This = NSURI_THIS(iface);
1935 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
1938 return nsIURL_SetDirectory(This->nsurl, aDirectory);
1940 FIXME("default action not implemented\n");
1941 return NS_ERROR_NOT_IMPLEMENTED;
1944 static nsresult NSAPI nsURL_GetFileName(nsIWineURI *iface, nsACString *aFileName)
1946 nsWineURI *This = NSURI_THIS(iface);
1948 TRACE("(%p)->(%p)\n", This, aFileName);
1951 return nsIURL_GetFileName(This->nsurl, aFileName);
1953 FIXME("default action not implemented\n");
1954 return NS_ERROR_NOT_IMPLEMENTED;
1957 static nsresult NSAPI nsURL_SetFileName(nsIWineURI *iface, const nsACString *aFileName)
1959 nsWineURI *This = NSURI_THIS(iface);
1961 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
1964 return nsIURL_SetFileName(This->nsurl, aFileName);
1966 FIXME("default action not implemented\n");
1967 return NS_ERROR_NOT_IMPLEMENTED;
1970 static nsresult NSAPI nsURL_GetFileBaseName(nsIWineURI *iface, nsACString *aFileBaseName)
1972 nsWineURI *This = NSURI_THIS(iface);
1974 TRACE("(%p)->(%p)\n", This, aFileBaseName);
1977 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
1979 FIXME("default action not implemented\n");
1980 return NS_ERROR_NOT_IMPLEMENTED;
1983 static nsresult NSAPI nsURL_SetFileBaseName(nsIWineURI *iface, const nsACString *aFileBaseName)
1985 nsWineURI *This = NSURI_THIS(iface);
1987 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
1990 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
1992 FIXME("default action not implemented\n");
1993 return NS_ERROR_NOT_IMPLEMENTED;
1996 static nsresult NSAPI nsURL_GetFileExtension(nsIWineURI *iface, nsACString *aFileExtension)
1998 nsWineURI *This = NSURI_THIS(iface);
2000 TRACE("(%p)->(%p)\n", This, aFileExtension);
2003 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2005 FIXME("default action not implemented\n");
2006 return NS_ERROR_NOT_IMPLEMENTED;
2009 static nsresult NSAPI nsURL_SetFileExtension(nsIWineURI *iface, const nsACString *aFileExtension)
2011 nsWineURI *This = NSURI_THIS(iface);
2013 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2016 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2018 FIXME("default action not implemented\n");
2019 return NS_ERROR_NOT_IMPLEMENTED;
2022 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
2024 nsWineURI *This = NSURI_THIS(iface);
2026 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2029 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2031 FIXME("default action not implemented\n");
2032 return NS_ERROR_NOT_IMPLEMENTED;
2035 static nsresult NSAPI nsURL_GetRelativeSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
2037 nsWineURI *This = NSURI_THIS(iface);
2039 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2042 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2044 FIXME("default action not implemented\n");
2045 return NS_ERROR_NOT_IMPLEMENTED;
2048 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
2050 nsWineURI *This = NSURI_THIS(iface);
2052 TRACE("(%p)->(%p)\n", This, aContainer);
2055 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
2056 *aContainer = This->container;
2061 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
2063 nsWineURI *This = NSURI_THIS(iface);
2065 TRACE("(%p)->(%p)\n", This, aContainer);
2067 if(This->container) {
2068 if(This->container == aContainer)
2070 TRACE("Changing %p -> %p\n", This->container, aContainer);
2071 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
2075 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
2076 This->container = aContainer;
2081 static nsresult NSAPI nsURI_GetWindow(nsIWineURI *iface, HTMLWindow **aHTMLWindow)
2083 nsWineURI *This = NSURI_THIS(iface);
2085 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2087 if(This->window_ref && This->window_ref->window) {
2088 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window_ref->window));
2089 *aHTMLWindow = This->window_ref->window;
2091 *aHTMLWindow = NULL;
2097 static nsresult NSAPI nsURI_SetWindow(nsIWineURI *iface, HTMLWindow *aHTMLWindow)
2099 nsWineURI *This = NSURI_THIS(iface);
2101 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2103 if(This->window_ref) {
2104 if(This->window_ref->window == aHTMLWindow)
2106 TRACE("Changing %p -> %p\n", This->window_ref->window, aHTMLWindow);
2107 windowref_release(This->window_ref);
2111 windowref_addref(aHTMLWindow->window_ref);
2112 This->window_ref = aHTMLWindow->window_ref;
2114 if(aHTMLWindow->doc_obj)
2115 nsIWineURI_SetNSContainer(NSWINEURI(This), aHTMLWindow->doc_obj->nscontainer);
2117 This->window_ref = NULL;
2123 static nsresult NSAPI nsURI_GetChannelBSC(nsIWineURI *iface, nsChannelBSC **aChannelBSC)
2125 nsWineURI *This = NSURI_THIS(iface);
2127 TRACE("(%p)->(%p)\n", This, aChannelBSC);
2129 if(This->channel_bsc)
2130 IUnknown_AddRef((IUnknown*)This->channel_bsc);
2131 *aChannelBSC = This->channel_bsc;
2135 static nsresult NSAPI nsURI_SetChannelBSC(nsIWineURI *iface, nsChannelBSC *aChannelBSC)
2137 nsWineURI *This = NSURI_THIS(iface);
2139 TRACE("(%p)->(%p)\n", This, aChannelBSC);
2141 if(This->channel_bsc)
2142 IUnknown_Release((IUnknown*)This->channel_bsc);
2144 IUnknown_AddRef((IUnknown*)aChannelBSC);
2145 This->channel_bsc = aChannelBSC;
2149 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
2151 nsWineURI *This = NSURI_THIS(iface);
2153 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
2155 *aIsDocumentURI = This->is_doc_uri;
2159 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
2161 nsWineURI *This = NSURI_THIS(iface);
2163 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
2165 This->is_doc_uri = aIsDocumentURI;
2169 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
2171 nsWineURI *This = NSURI_THIS(iface);
2173 TRACE("(%p)->(%p)\n", This, aURL);
2175 *aURL = This->wine_url;
2179 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
2181 nsWineURI *This = NSURI_THIS(iface);
2183 static const WCHAR wszFtp[] = {'f','t','p',':'};
2184 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
2185 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
2187 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
2189 heap_free(This->wine_url);
2192 int len = strlenW(aURL)+1;
2193 This->wine_url = heap_alloc(len*sizeof(WCHAR));
2194 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
2197 /* FIXME: Always use wine url */
2198 This->use_wine_url =
2199 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
2200 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
2201 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
2203 This->use_wine_url = TRUE;
2206 This->wine_url = NULL;
2207 This->use_wine_url = FALSE;
2215 static const nsIWineURIVtbl nsWineURIVtbl = {
2216 nsURI_QueryInterface,
2244 nsURI_GetOriginCharset,
2257 nsURL_GetFileBaseName,
2258 nsURL_SetFileBaseName,
2259 nsURL_GetFileExtension,
2260 nsURL_SetFileExtension,
2261 nsURL_GetCommonBaseSpec,
2262 nsURL_GetRelativeSpec,
2263 nsURI_GetNSContainer,
2264 nsURI_SetNSContainer,
2267 nsURI_GetChannelBSC,
2268 nsURI_SetChannelBSC,
2269 nsURI_GetIsDocumentURI,
2270 nsURI_SetIsDocumentURI,
2275 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2277 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2279 ret->lpWineURIVtbl = &nsWineURIVtbl;
2283 nsIWineURI_SetNSContainer(NSWINEURI(ret), container);
2284 nsIWineURI_SetWindow(NSWINEURI(ret), window);
2287 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2291 TRACE("retval=%p\n", ret);
2296 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2301 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2302 if(NS_FAILED(nsres))
2305 nsIWineURI_SetWineURL(NSWINEURI(uri), url);
2306 uri->is_doc_uri = TRUE;
2313 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2317 nsIProtocolHandler *nshandler;
2318 } nsProtocolHandler;
2320 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2322 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2324 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2327 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2331 if(IsEqualGUID(&IID_nsISupports, riid)) {
2332 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2333 *result = NSPROTHANDLER(This);
2334 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2335 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2336 *result = NSPROTHANDLER(This);
2337 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2338 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2339 return NS_NOINTERFACE;
2343 nsISupports_AddRef((nsISupports*)*result);
2347 WARN("(%s %p)\n", debugstr_guid(riid), result);
2348 return NS_NOINTERFACE;
2351 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2353 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2354 LONG ref = InterlockedIncrement(&This->ref);
2356 TRACE("(%p) ref=%d\n", This, ref);
2361 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2363 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2364 LONG ref = InterlockedDecrement(&This->ref);
2366 TRACE("(%p) ref=%d\n", This, ref);
2370 nsIProtocolHandler_Release(This->nshandler);
2377 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2379 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2381 TRACE("(%p)->(%p)\n", This, aScheme);
2384 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2385 return NS_ERROR_NOT_IMPLEMENTED;
2388 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2389 PRInt32 *aDefaultPort)
2391 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2393 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2396 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2397 return NS_ERROR_NOT_IMPLEMENTED;
2400 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2401 PRUint32 *aProtocolFlags)
2403 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2405 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2408 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2409 return NS_ERROR_NOT_IMPLEMENTED;
2412 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2413 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2415 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2417 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2420 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2421 return NS_ERROR_NOT_IMPLEMENTED;
2424 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2425 nsIURI *aURI, nsIChannel **_retval)
2427 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2429 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2432 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2433 return NS_ERROR_NOT_IMPLEMENTED;
2436 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2437 PRInt32 port, const char *scheme, PRBool *_retval)
2439 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2441 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2444 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2445 return NS_ERROR_NOT_IMPLEMENTED;
2448 #undef NSPROTHANDLER_THIS
2450 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2451 nsProtocolHandler_QueryInterface,
2452 nsProtocolHandler_AddRef,
2453 nsProtocolHandler_Release,
2454 nsProtocolHandler_GetScheme,
2455 nsProtocolHandler_GetDefaultPort,
2456 nsProtocolHandler_GetProtocolFlags,
2457 nsProtocolHandler_NewURI,
2458 nsProtocolHandler_NewChannel,
2459 nsProtocolHandler_AllowPort
2462 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2464 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2466 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2468 ret->nshandler = nshandler;
2470 return NSPROTHANDLER(ret);
2473 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2475 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2480 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2485 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2486 nsIProtocolHandler **_retval)
2488 nsIExternalProtocolHandler *nsexthandler;
2489 nsIProtocolHandler *nshandler;
2492 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2494 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2495 if(NS_FAILED(nsres)) {
2496 WARN("GetProtocolHandler failed: %08x\n", nsres);
2500 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2501 (void**)&nsexthandler);
2502 if(NS_FAILED(nsres)) {
2503 *_retval = nshandler;
2507 nsIExternalProtocolHandler_Release(nsexthandler);
2508 *_retval = create_protocol_handler(nshandler);
2509 TRACE("return %p\n", *_retval);
2513 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2516 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2517 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2520 static BOOL is_gecko_special_uri(const char *spec)
2522 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2525 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2526 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2533 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2534 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2536 const char *spec = NULL;
2537 HTMLWindow *window = NULL;
2539 LPCWSTR base_wine_url = NULL;
2540 nsIWineURI *base_wine_uri = NULL;
2541 nsWineURI *wine_uri;
2542 BOOL is_wine_uri = FALSE;
2545 nsACString_GetData(aSpec, &spec);
2547 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2550 if(is_gecko_special_uri(spec))
2551 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2553 if(!strncmp(spec, "wine:", 5)) {
2559 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2561 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2562 if(NS_SUCCEEDED(nsres)) {
2563 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2564 nsIWineURI_GetWindow(base_wine_uri, &window);
2565 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2566 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2567 TRACE("not wraping\n");
2568 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2570 WARN("Could not get base nsIWineURI: %08x\n", nsres);
2574 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2575 if(NS_FAILED(nsres))
2576 TRACE("NewURI failed: %08x\n", nsres);
2578 nsres = create_uri(uri, window, NULL, &wine_uri);
2579 *_retval = (nsIURI*)wine_uri;
2582 IHTMLWindow2_Release(HTMLWINDOW2(window));
2585 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2589 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2591 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2592 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2593 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2595 set_wine_url(wine_uri, url);
2597 WARN("CoCombineUrl failed: %08x\n", hres);
2598 }else if(is_wine_uri) {
2599 WCHAR url[INTERNET_MAX_URL_LENGTH];
2601 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2602 set_wine_url(wine_uri, url);
2606 nsIWineURI_Release(base_wine_uri);
2611 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2614 TRACE("(%p %p)\n", aFile, _retval);
2615 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2618 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2619 nsIChannel **_retval)
2621 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2623 nsWineURI *wine_uri;
2626 TRACE("(%p %p)\n", aURI, _retval);
2628 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2629 if(NS_FAILED(nsres)) {
2630 TRACE("Could not get nsIWineURI: %08x\n", nsres);
2631 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2634 ret = heap_alloc_zero(sizeof(nsChannel));
2636 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2637 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2638 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2640 ret->uri = wine_uri;
2642 nsIURI_AddRef(aURI);
2643 ret->original_uri = aURI;
2644 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2645 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2647 *_retval = NSCHANNEL(ret);
2651 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2652 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2654 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2655 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2658 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2660 TRACE("(%p)\n", aOffline);
2661 return nsIIOService_GetOffline(nsio, aOffline);
2664 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2666 TRACE("(%x)\n", aOffline);
2667 return nsIIOService_SetOffline(nsio, aOffline);
2670 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2671 const char *aScheme, PRBool *_retval)
2673 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2674 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2677 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2678 nsACString * _retval)
2680 TRACE("(%p %p)\n", urlString, _retval);
2681 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2684 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2685 nsIOService_QueryInterface,
2687 nsIOService_Release,
2688 nsIOService_GetProtocolHandler,
2689 nsIOService_GetProtocolFlags,
2691 nsIOService_NewFileURI,
2692 nsIOService_NewChannelFromURI,
2693 nsIOService_NewChannel,
2694 nsIOService_GetOffline,
2695 nsIOService_SetOffline,
2696 nsIOService_AllowPort,
2697 nsIOService_ExtractScheme
2700 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2702 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2705 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2708 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2713 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2718 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2719 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2721 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2723 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2726 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2730 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2733 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2735 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2737 if(aFlags == (1<<11)) {
2742 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2745 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2747 TRACE("(%p %p)\n", aURI, _retval);
2749 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2752 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2753 PRUint32 aEscapeType, nsACString *_retval)
2755 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2757 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2760 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2761 nsACString *_retval)
2763 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2765 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2768 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2769 PRUint32 aFlags, nsACString *_retval)
2771 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2773 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2776 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2777 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2779 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2781 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2784 static const nsINetUtilVtbl nsNetUtilVtbl = {
2785 nsNetUtil_QueryInterface,
2788 nsNetUtil_ParseContentType,
2789 nsNetUtil_ProtocolHasFlags,
2790 nsNetUtil_URIChainHasFlags,
2791 nsNetUtil_ToImmutableURI,
2792 nsNetUtil_EscapeString,
2793 nsNetUtil_EscapeURL,
2794 nsNetUtil_UnescapeString,
2795 nsNetUtil_ExtractCharsetFromContentType
2798 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2800 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2805 if(IsEqualGUID(&IID_nsISupports, riid))
2806 *result = &nsIOService;
2807 else if(IsEqualGUID(&IID_nsIIOService, riid))
2808 *result = &nsIOService;
2809 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2810 *result = &nsNetUtil;
2813 nsISupports_AddRef((nsISupports*)*result);
2817 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2818 return NS_NOINTERFACE;
2821 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2826 if(IsEqualGUID(&IID_nsISupports, riid)) {
2827 TRACE("(IID_nsISupports %p)\n", result);
2829 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2830 TRACE("(IID_nsIFactory %p)\n", result);
2835 nsIFactory_AddRef(iface);
2839 WARN("(%s %p)\n", debugstr_guid(riid), result);
2840 return NS_NOINTERFACE;
2843 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2848 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2853 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2854 nsISupports *aOuter, const nsIID *iid, void **result)
2856 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2859 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2861 WARN("(%x)\n", lock);
2865 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2866 nsIOServiceFactory_QueryInterface,
2867 nsIOServiceFactory_AddRef,
2868 nsIOServiceFactory_Release,
2869 nsIOServiceFactory_CreateInstance,
2870 nsIOServiceFactory_LockFactory
2873 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2875 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2877 nsIFactory *old_factory = NULL;
2880 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2881 &IID_nsIFactory, (void**)&old_factory);
2882 if(NS_FAILED(nsres)) {
2883 ERR("Could not get factory: %08x\n", nsres);
2887 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2888 if(NS_FAILED(nsres)) {
2889 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2890 nsIFactory_Release(old_factory);
2894 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2895 if(NS_FAILED(nsres)) {
2896 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2897 nsIIOService_Release(nsio);
2901 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2902 nsIFactory_Release(old_factory);
2903 if(NS_FAILED(nsres))
2904 ERR("UnregisterFactory failed: %08x\n", nsres);
2906 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2907 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2908 if(NS_FAILED(nsres))
2909 ERR("RegisterFactory failed: %08x\n", nsres);
2912 void release_nsio(void)
2915 nsINetUtil_Release(net_util);
2920 nsIIOService_Release(nsio);