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 LOAD_INITIAL_DOCUMENT_URI 0x80000
43 #define NS_IOSERVICE_CLASSNAME "nsIOService"
44 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
46 static const IID NS_IOSERVICE_CID =
47 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
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 nsIWineURIVtbl *lpWineURIVtbl;
61 NSContainer *container;
62 windowref_t *window_ref;
68 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
69 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
71 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsIWineURI**);
73 static const char *debugstr_nsacstr(const nsACString *nsstr)
77 nsACString_GetData(nsstr, &data);
78 return debugstr_a(data);
81 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
83 const WCHAR *ptr = nsuri;
85 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
87 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
88 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
90 if(*ptr || ret_empty) {
91 *ret = SysAllocString(ptr);
98 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
102 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
104 IOleCommandTarget *cmdtrg = NULL;
107 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
108 if(SUCCEEDED(hres)) {
109 VARIANT varUrl, varRes;
111 V_VT(&varUrl) = VT_BSTR;
112 V_BSTR(&varUrl) = SysAllocString(url);
113 V_VT(&varRes) = VT_BOOL;
115 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
117 IOleCommandTarget_Release(cmdtrg);
118 SysFreeString(V_BSTR(&varUrl));
120 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
121 TRACE("got VARIANT_FALSE, do not load\n");
129 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
131 HTMLDocumentObj *doc = container->doc;
136 nsIWineURI_GetWineURL(channel->uri, &uri);
138 ERR("GetWineURL returned NULL\n");
143 NSContainer *container_iter = container;
145 hlnf = HLNF_OPENINNEWWINDOW;
146 while(!container_iter->doc)
147 container_iter = container_iter->parent;
148 doc = container_iter->doc;
154 if(!hlnf && !exec_shldocvw_67(doc, uri))
157 hres = hlink_frame_navigate(&doc->basedoc, uri, channel->post_data_stream, hlnf);
161 static inline BOOL is_http_channel(nsChannel *This)
163 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTP;
166 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
168 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
170 nsChannel *This = NSCHANNEL_THIS(iface);
172 if(IsEqualGUID(&IID_nsISupports, riid)) {
173 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
174 *result = NSCHANNEL(This);
175 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
176 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
177 *result = NSCHANNEL(This);
178 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
179 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
180 *result = NSCHANNEL(This);
181 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
182 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
183 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
184 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
185 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
186 *result = NSUPCHANNEL(This);
187 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
188 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
189 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
191 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
196 nsIChannel_AddRef(NSCHANNEL(This));
200 return NS_NOINTERFACE;
203 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
205 nsChannel *This = NSCHANNEL_THIS(iface);
206 nsrefcnt ref = InterlockedIncrement(&This->ref);
208 TRACE("(%p) ref=%d\n", This, ref);
213 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
215 nsChannel *This = NSCHANNEL_THIS(iface);
216 LONG ref = InterlockedDecrement(&This->ref);
219 nsIWineURI_Release(This->uri);
221 nsISupports_Release(This->owner);
222 if(This->post_data_stream)
223 nsIInputStream_Release(This->post_data_stream);
225 nsILoadGroup_Release(This->load_group);
226 if(This->notif_callback)
227 nsIInterfaceRequestor_Release(This->notif_callback);
228 if(This->original_uri)
229 nsIURI_Release(This->original_uri);
230 heap_free(This->content_type);
231 heap_free(This->charset);
238 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
240 nsChannel *This = NSCHANNEL_THIS(iface);
242 FIXME("(%p)->(%p)\n", This, aName);
244 return NS_ERROR_NOT_IMPLEMENTED;
247 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
249 nsChannel *This = NSCHANNEL_THIS(iface);
251 FIXME("(%p)->(%p)\n", This, _retval);
253 return NS_ERROR_NOT_IMPLEMENTED;
256 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
258 nsChannel *This = NSCHANNEL_THIS(iface);
260 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
262 return *aStatus = NS_OK;
265 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
267 nsChannel *This = NSCHANNEL_THIS(iface);
269 FIXME("(%p)->(%08x)\n", This, aStatus);
271 return NS_ERROR_NOT_IMPLEMENTED;
274 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
276 nsChannel *This = NSCHANNEL_THIS(iface);
278 FIXME("(%p)\n", This);
280 return NS_ERROR_NOT_IMPLEMENTED;
283 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
285 nsChannel *This = NSCHANNEL_THIS(iface);
287 FIXME("(%p)\n", This);
289 return NS_ERROR_NOT_IMPLEMENTED;
292 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
294 nsChannel *This = NSCHANNEL_THIS(iface);
296 TRACE("(%p)->(%p)\n", This, aLoadGroup);
299 nsILoadGroup_AddRef(This->load_group);
301 *aLoadGroup = This->load_group;
305 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
307 nsChannel *This = NSCHANNEL_THIS(iface);
309 TRACE("(%p)->(%p)\n", This, aLoadGroup);
312 nsILoadGroup_Release(This->load_group);
314 nsILoadGroup_AddRef(aLoadGroup);
315 This->load_group = aLoadGroup;
320 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
322 nsChannel *This = NSCHANNEL_THIS(iface);
324 TRACE("(%p)->(%p)\n", This, aLoadFlags);
326 *aLoadFlags = This->load_flags;
330 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
332 nsChannel *This = NSCHANNEL_THIS(iface);
334 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
336 This->load_flags = aLoadFlags;
340 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
342 nsChannel *This = NSCHANNEL_THIS(iface);
344 TRACE("(%p)->(%p)\n", This, aOriginalURI);
346 if(This->original_uri)
347 nsIURI_AddRef(This->original_uri);
349 *aOriginalURI = This->original_uri;
353 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
355 nsChannel *This = NSCHANNEL_THIS(iface);
357 TRACE("(%p)->(%p)\n", This, aOriginalURI);
359 if(This->original_uri)
360 nsIURI_Release(This->original_uri);
362 nsIURI_AddRef(aOriginalURI);
363 This->original_uri = aOriginalURI;
367 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
369 nsChannel *This = NSCHANNEL_THIS(iface);
371 TRACE("(%p)->(%p)\n", This, aURI);
373 nsIWineURI_AddRef(This->uri);
374 *aURI = (nsIURI*)This->uri;
379 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
381 nsChannel *This = NSCHANNEL_THIS(iface);
383 TRACE("(%p)->(%p)\n", This, aOwner);
386 nsISupports_AddRef(This->owner);
387 *aOwner = This->owner;
392 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
394 nsChannel *This = NSCHANNEL_THIS(iface);
396 TRACE("(%p)->(%p)\n", This, aOwner);
399 nsISupports_AddRef(aOwner);
401 nsISupports_Release(This->owner);
402 This->owner = aOwner;
407 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
408 nsIInterfaceRequestor **aNotificationCallbacks)
410 nsChannel *This = NSCHANNEL_THIS(iface);
412 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
414 if(This->notif_callback)
415 nsIInterfaceRequestor_AddRef(This->notif_callback);
416 *aNotificationCallbacks = This->notif_callback;
421 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
422 nsIInterfaceRequestor *aNotificationCallbacks)
424 nsChannel *This = NSCHANNEL_THIS(iface);
426 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
428 if(This->notif_callback)
429 nsIInterfaceRequestor_Release(This->notif_callback);
430 if(aNotificationCallbacks)
431 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
433 This->notif_callback = aNotificationCallbacks;
438 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
440 nsChannel *This = NSCHANNEL_THIS(iface);
442 FIXME("(%p)->(%p)\n", This, aSecurityInfo);
444 return NS_ERROR_NOT_IMPLEMENTED;
447 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
449 nsChannel *This = NSCHANNEL_THIS(iface);
451 TRACE("(%p)->(%p)\n", This, aContentType);
453 if(This->content_type) {
454 nsACString_SetData(aContentType, This->content_type);
458 WARN("unknown type\n");
459 return NS_ERROR_FAILURE;
462 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
463 const nsACString *aContentType)
465 nsChannel *This = NSCHANNEL_THIS(iface);
466 const char *content_type;
468 TRACE("(%p)->(%p)\n", This, aContentType);
470 nsACString_GetData(aContentType, &content_type);
472 TRACE("content_type %s\n", content_type);
474 heap_free(This->content_type);
475 This->content_type = heap_strdupA(content_type);
480 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
481 nsACString *aContentCharset)
483 nsChannel *This = NSCHANNEL_THIS(iface);
485 TRACE("(%p)->(%p)\n", This, aContentCharset);
488 nsACString_SetData(aContentCharset, This->charset);
492 nsACString_SetData(aContentCharset, "");
496 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
497 const nsACString *aContentCharset)
499 nsChannel *This = NSCHANNEL_THIS(iface);
501 FIXME("(%p)->(%p)\n", This, aContentCharset);
503 return NS_ERROR_NOT_IMPLEMENTED;
506 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
508 nsChannel *This = NSCHANNEL_THIS(iface);
510 FIXME("(%p)->(%p)\n", This, aContentLength);
512 return NS_ERROR_NOT_IMPLEMENTED;
515 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
517 nsChannel *This = NSCHANNEL_THIS(iface);
519 FIXME("(%p)->(%d)\n", This, aContentLength);
521 return NS_ERROR_NOT_IMPLEMENTED;
524 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
526 nsChannel *This = NSCHANNEL_THIS(iface);
528 FIXME("(%p)->(%p)\n", This, _retval);
530 return NS_ERROR_NOT_IMPLEMENTED;
533 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
535 nsIWineURI *wine_uri;
540 if(!channel->original_uri) {
541 ERR("original_uri == NULL\n");
545 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
546 if(NS_FAILED(nsres)) {
547 ERR("Could not get nsIWineURI: %08x\n", nsres);
551 nsIWineURI_GetWineURL(wine_uri, &wine_url);
552 nsIWineURI_Release(wine_uri);
554 TRACE("wine_url == NULL\n");
558 hres = CreateURLMoniker(NULL, wine_url, mon);
560 WARN("CreateURLMoniker failed: %08x\n", hres);
565 static HTMLWindow *get_window_from_load_group(nsChannel *This)
570 nsIWineURI *wine_uri;
574 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
575 if(NS_FAILED(nsres)) {
576 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
583 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
584 nsIRequest_Release(req);
585 if(NS_FAILED(nsres)) {
586 WARN("Could not get nsIChannel interface: %08x\n", nsres);
590 nsres = nsIChannel_GetURI(channel, &uri);
591 nsIChannel_Release(channel);
592 if(NS_FAILED(nsres)) {
593 ERR("GetURI failed: %08x\n", nsres);
597 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
599 if(NS_FAILED(nsres)) {
600 TRACE("Could not get nsIWineURI: %08x\n", nsres);
604 nsIWineURI_GetWindow(wine_uri, &window);
605 nsIWineURI_Release(wine_uri);
610 static HTMLWindow *get_channel_window(nsChannel *This)
612 nsIRequestObserver *req_observer;
613 nsIWebProgress *web_progress;
614 nsIDOMWindow *nswindow;
618 if(!This->load_group) {
619 ERR("NULL load_group\n");
623 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
624 if(NS_FAILED(nsres) || !req_observer) {
625 ERR("GetGroupObserver failed: %08x\n", nsres);
629 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
630 nsIRequestObserver_Release(req_observer);
631 if(NS_FAILED(nsres)) {
632 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
636 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
637 nsIWebProgress_Release(web_progress);
638 if(NS_FAILED(nsres) || !nswindow) {
639 ERR("GetDOMWindow failed: %08x\n", nsres);
643 window = nswindow_to_window(nswindow);
644 nsIDOMWindow_Release(nswindow);
647 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
649 FIXME("NULL window for %p\n", nswindow);
655 HTMLDocumentNode *doc;
656 nsChannelBSC *bscallback;
657 } start_binding_task_t;
659 static void start_binding_proc(task_t *_task)
661 start_binding_task_t *task = (start_binding_task_t*)_task;
663 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
669 nsChannelBSC *bscallback;
670 } start_doc_binding_task_t;
672 static void start_doc_binding_proc(task_t *_task)
674 start_doc_binding_task_t *task = (start_doc_binding_task_t*)_task;
676 start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
677 IUnknown_Release((IUnknown*)task->bscallback);
680 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
681 nsISupports *context)
683 nsChannelBSC *bscallback;
684 IMoniker *mon = NULL;
687 hres = create_mon_for_nschannel(This, &mon);
689 return NS_ERROR_UNEXPECTED;
692 set_current_mon(window, mon);
694 bscallback = create_channelbsc(mon);
695 IMoniker_Release(mon);
697 channelbsc_set_channel(bscallback, This, listener, context);
700 start_doc_binding_task_t *task;
702 set_window_bscallback(window, bscallback);
704 task = heap_alloc(sizeof(start_doc_binding_task_t));
705 task->window = window;
706 task->bscallback = bscallback;
707 push_task(&task->header, start_doc_binding_proc, window->task_magic);
709 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
711 task->doc = window->doc;
712 task->bscallback = bscallback;
713 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
719 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
720 nsISupports *aContext)
722 nsChannel *This = NSCHANNEL_THIS(iface);
723 HTMLWindow *window = NULL;
726 nsresult nsres = NS_OK;
728 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
730 if(TRACE_ON(mshtml)) {
733 nsIWineURI_GetWineURL(This->uri, &url);
734 TRACE("opening %s\n", debugstr_w(url));
737 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
739 window = get_channel_window(This);
741 nsIWineURI_SetWindow(This->uri, window);
743 NSContainer *nscontainer;
745 nsIWineURI_GetNSContainer(This->uri, &nscontainer);
749 /* nscontainer->doc should be NULL which means navigation to a new window */
751 FIXME("nscontainer->doc = %p\n", nscontainer->doc);
753 b = before_async_open(This, nscontainer);
754 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
756 FIXME("Navigation not cancelled\n");
757 return NS_ERROR_UNEXPECTED;
763 nsIWineURI_GetWindow(This->uri, &window);
765 if(!window && This->load_group) {
766 window = get_window_from_load_group(This);
768 nsIWineURI_SetWindow(This->uri, window);
773 ERR("window = NULL\n");
774 return NS_ERROR_UNEXPECTED;
777 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI) && window == window->doc_obj->basedoc.window) {
778 if(window->doc_obj->nscontainer->bscallback) {
779 NSContainer *nscontainer = window->doc_obj->nscontainer;
781 channelbsc_set_channel(nscontainer->bscallback, This, aListener, aContext);
783 if(nscontainer->doc->mime) {
784 heap_free(This->content_type);
785 This->content_type = heap_strdupWtoA(nscontainer->doc->mime);
790 open = before_async_open(This, window->doc_obj->nscontainer);
793 nsres = NS_ERROR_UNEXPECTED;
799 nsres = async_open(This, window, is_doc_uri, aListener, aContext);
802 IHTMLWindow2_Release(HTMLWINDOW2(window));
806 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
808 nsChannel *This = NSCHANNEL_THIS(iface);
810 FIXME("(%p)->(%p)\n", This, aRequestMethod);
812 return NS_ERROR_NOT_IMPLEMENTED;
815 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
816 const nsACString *aRequestMethod)
818 nsChannel *This = NSCHANNEL_THIS(iface);
820 FIXME("(%p)->(%p)\n", This, aRequestMethod);
822 return NS_ERROR_NOT_IMPLEMENTED;
825 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
827 nsChannel *This = NSCHANNEL_THIS(iface);
829 FIXME("(%p)->(%p)\n", This, aReferrer);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
836 nsChannel *This = NSCHANNEL_THIS(iface);
838 FIXME("(%p)->(%p)\n", This, aReferrer);
843 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
844 const nsACString *aHeader, nsACString *_retval)
846 nsChannel *This = NSCHANNEL_THIS(iface);
848 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
854 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
856 nsChannel *This = NSCHANNEL_THIS(iface);
858 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
863 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
864 nsIHttpHeaderVisitor *aVisitor)
866 nsChannel *This = NSCHANNEL_THIS(iface);
868 FIXME("(%p)->(%p)\n", This, aVisitor);
870 return NS_ERROR_NOT_IMPLEMENTED;
873 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
875 nsChannel *This = NSCHANNEL_THIS(iface);
877 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
879 return NS_ERROR_NOT_IMPLEMENTED;
882 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
884 nsChannel *This = NSCHANNEL_THIS(iface);
886 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
888 return NS_ERROR_NOT_IMPLEMENTED;
891 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
893 nsChannel *This = NSCHANNEL_THIS(iface);
895 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
897 return NS_ERROR_NOT_IMPLEMENTED;
900 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
902 nsChannel *This = NSCHANNEL_THIS(iface);
904 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
906 return NS_ERROR_NOT_IMPLEMENTED;
909 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
911 nsChannel *This = NSCHANNEL_THIS(iface);
913 TRACE("(%p)->(%p)\n", This, aResponseStatus);
915 if(This->response_status) {
916 *aResponseStatus = This->response_status;
920 WARN("No response status\n");
921 return NS_ERROR_UNEXPECTED;
924 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
925 nsACString *aResponseStatusText)
927 nsChannel *This = NSCHANNEL_THIS(iface);
929 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
931 return NS_ERROR_NOT_IMPLEMENTED;
934 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
935 PRBool *aRequestSucceeded)
937 nsChannel *This = NSCHANNEL_THIS(iface);
939 FIXME("(%p)->(%p)\n", This, aRequestSucceeded);
941 return NS_ERROR_NOT_IMPLEMENTED;
944 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
945 const nsACString *header, nsACString *_retval)
947 nsChannel *This = NSCHANNEL_THIS(iface);
949 FIXME("(%p)->(%p %p)\n", This, header, _retval);
951 return NS_ERROR_NOT_IMPLEMENTED;
954 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
955 const nsACString *header, const nsACString *value, PRBool merge)
957 nsChannel *This = NSCHANNEL_THIS(iface);
959 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
961 return NS_ERROR_NOT_IMPLEMENTED;
964 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
965 nsIHttpHeaderVisitor *aVisitor)
967 nsChannel *This = NSCHANNEL_THIS(iface);
969 FIXME("(%p)->(%p)\n", This, aVisitor);
971 return NS_ERROR_NOT_IMPLEMENTED;
974 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
976 nsChannel *This = NSCHANNEL_THIS(iface);
978 FIXME("(%p)->(%p)\n", This, _retval);
980 return NS_ERROR_NOT_IMPLEMENTED;
983 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
985 nsChannel *This = NSCHANNEL_THIS(iface);
987 FIXME("(%p)->(%p)\n", This, _retval);
989 return NS_ERROR_NOT_IMPLEMENTED;
992 #undef NSCHANNEL_THIS
994 static const nsIHttpChannelVtbl nsChannelVtbl = {
995 nsChannel_QueryInterface,
1000 nsChannel_GetStatus,
1004 nsChannel_GetLoadGroup,
1005 nsChannel_SetLoadGroup,
1006 nsChannel_GetLoadFlags,
1007 nsChannel_SetLoadFlags,
1008 nsChannel_GetOriginalURI,
1009 nsChannel_SetOriginalURI,
1013 nsChannel_GetNotificationCallbacks,
1014 nsChannel_SetNotificationCallbacks,
1015 nsChannel_GetSecurityInfo,
1016 nsChannel_GetContentType,
1017 nsChannel_SetContentType,
1018 nsChannel_GetContentCharset,
1019 nsChannel_SetContentCharset,
1020 nsChannel_GetContentLength,
1021 nsChannel_SetContentLength,
1023 nsChannel_AsyncOpen,
1024 nsChannel_GetRequestMethod,
1025 nsChannel_SetRequestMethod,
1026 nsChannel_GetReferrer,
1027 nsChannel_SetReferrer,
1028 nsChannel_GetRequestHeader,
1029 nsChannel_SetRequestHeader,
1030 nsChannel_VisitRequestHeaders,
1031 nsChannel_GetAllowPipelining,
1032 nsChannel_SetAllowPipelining,
1033 nsChannel_GetRedirectionLimit,
1034 nsChannel_SetRedirectionLimit,
1035 nsChannel_GetResponseStatus,
1036 nsChannel_GetResponseStatusText,
1037 nsChannel_GetRequestSucceeded,
1038 nsChannel_GetResponseHeader,
1039 nsChannel_SetResponseHeader,
1040 nsChannel_VisitResponseHeaders,
1041 nsChannel_IsNoStoreResponse,
1042 nsChannel_IsNoCacheResponse
1045 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1047 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1050 nsChannel *This = NSUPCHANNEL_THIS(iface);
1051 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1054 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1056 nsChannel *This = NSUPCHANNEL_THIS(iface);
1057 return nsIChannel_AddRef(NSCHANNEL(This));
1060 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1062 nsChannel *This = NSUPCHANNEL_THIS(iface);
1063 return nsIChannel_Release(NSCHANNEL(This));
1066 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1067 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1069 nsChannel *This = NSUPCHANNEL_THIS(iface);
1070 const char *content_type;
1072 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1074 if(This->post_data_stream)
1075 nsIInputStream_Release(This->post_data_stream);
1078 nsACString_GetData(aContentType, &content_type);
1080 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1083 if(aContentLength != -1)
1084 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1086 if(This->post_data_stream)
1087 nsIInputStream_Release(This->post_data_stream);
1088 This->post_data_stream = aStream;
1090 nsIInputStream_AddRef(aStream);
1095 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1096 nsIInputStream **aUploadStream)
1098 nsChannel *This = NSUPCHANNEL_THIS(iface);
1100 TRACE("(%p)->(%p)\n", This, aUploadStream);
1102 if(This->post_data_stream)
1103 nsIInputStream_AddRef(This->post_data_stream);
1105 *aUploadStream = This->post_data_stream;
1109 #undef NSUPCHANNEL_THIS
1111 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1112 nsUploadChannel_QueryInterface,
1113 nsUploadChannel_AddRef,
1114 nsUploadChannel_Release,
1115 nsUploadChannel_SetUploadStream,
1116 nsUploadChannel_GetUploadStream
1119 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1121 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1124 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1125 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1128 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1130 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1131 return nsIChannel_AddRef(NSCHANNEL(This));
1134 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1136 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1137 return nsIChannel_Release(NSCHANNEL(This));
1140 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1142 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1144 FIXME("(%p)->()\n", This);
1146 return NS_ERROR_NOT_IMPLEMENTED;
1149 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1151 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1153 FIXME("(%p)->()\n", This);
1155 return NS_ERROR_NOT_IMPLEMENTED;
1158 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1160 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1162 FIXME("(%p)->()\n", This);
1164 return NS_ERROR_NOT_IMPLEMENTED;
1167 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1169 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1171 FIXME("(%p)->()\n", This);
1173 return NS_ERROR_NOT_IMPLEMENTED;
1176 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1178 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1180 FIXME("(%p)->()\n", This);
1182 return NS_ERROR_NOT_IMPLEMENTED;
1185 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1187 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1189 FIXME("(%p)->()\n", This);
1191 return NS_ERROR_NOT_IMPLEMENTED;
1194 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1196 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1198 FIXME("(%p)->()\n", This);
1200 return NS_ERROR_NOT_IMPLEMENTED;
1203 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1205 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1207 FIXME("(%p)->()\n", This);
1209 return NS_ERROR_NOT_IMPLEMENTED;
1212 #undef NSHTTPINTERNAL_THIS
1214 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1215 nsHttpChannelInternal_QueryInterface,
1216 nsHttpChannelInternal_AddRef,
1217 nsHttpChannelInternal_Release,
1218 nsHttpChannelInternal_GetDocumentURI,
1219 nsHttpChannelInternal_SetDocumentURI,
1220 nsHttpChannelInternal_GetRequestVersion,
1221 nsHttpChannelInternal_GetResponseVersion,
1222 nsHttpChannelInternal_SetCookie,
1223 nsHttpChannelInternal_SetupFallbackChannel,
1224 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1225 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1228 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1230 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1232 nsURI *This = NSURI_THIS(iface);
1236 if(IsEqualGUID(&IID_nsISupports, riid)) {
1237 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1238 *result = NSURI(This);
1239 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1240 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1241 *result = NSURI(This);
1242 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1243 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1244 *result = NSURI(This);
1245 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1246 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1247 *result = NSURI(This);
1251 nsIURI_AddRef(NSURI(This));
1255 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1256 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1259 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1261 nsURI *This = NSURI_THIS(iface);
1262 LONG ref = InterlockedIncrement(&This->ref);
1264 TRACE("(%p) ref=%d\n", This, ref);
1269 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1271 nsURI *This = NSURI_THIS(iface);
1272 LONG ref = InterlockedDecrement(&This->ref);
1274 TRACE("(%p) ref=%d\n", This, ref);
1277 if(This->window_ref)
1278 windowref_release(This->window_ref);
1280 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1282 nsIURL_Release(This->nsurl);
1284 nsIURI_Release(This->uri);
1285 heap_free(This->wine_url);
1292 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1294 nsURI *This = NSURI_THIS(iface);
1296 TRACE("(%p)->(%p)\n", This, aSpec);
1298 if(This->use_wine_url) {
1299 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1300 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1301 nsACString_SetData(aSpec, speca);
1307 return nsIURI_GetSpec(This->uri, aSpec);
1309 TRACE("returning error\n");
1310 return NS_ERROR_NOT_IMPLEMENTED;
1314 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1316 nsURI *This = NSURI_THIS(iface);
1318 TRACE("(%p)->(%p)\n", This, aSpec);
1321 return nsIURI_SetSpec(This->uri, aSpec);
1323 FIXME("default action not implemented\n");
1324 return NS_ERROR_NOT_IMPLEMENTED;
1327 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1329 nsURI *This = NSURI_THIS(iface);
1331 TRACE("(%p)->(%p)\n", This, aPrePath);
1334 return nsIURI_GetPrePath(This->uri, aPrePath);
1336 FIXME("default action not implemented\n");
1337 return NS_ERROR_NOT_IMPLEMENTED;
1340 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1342 nsURI *This = NSURI_THIS(iface);
1344 TRACE("(%p)->(%p)\n", This, aScheme);
1346 if(This->use_wine_url) {
1348 * For Gecko we set scheme to unknown so it won't be handled
1349 * as any special case.
1351 nsACString_SetData(aScheme, "wine");
1356 return nsIURI_GetScheme(This->uri, aScheme);
1358 TRACE("returning error\n");
1359 return NS_ERROR_NOT_IMPLEMENTED;
1362 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1364 nsURI *This = NSURI_THIS(iface);
1366 TRACE("(%p)->(%p)\n", This, aScheme);
1369 return nsIURI_SetScheme(This->uri, aScheme);
1371 FIXME("default action not implemented\n");
1372 return NS_ERROR_NOT_IMPLEMENTED;
1375 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1377 nsURI *This = NSURI_THIS(iface);
1379 TRACE("(%p)->(%p)\n", This, aUserPass);
1382 return nsIURI_GetUserPass(This->uri, aUserPass);
1384 FIXME("default action not implemented\n");
1385 return NS_ERROR_NOT_IMPLEMENTED;
1388 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1390 nsURI *This = NSURI_THIS(iface);
1392 TRACE("(%p)->(%p)\n", This, aUserPass);
1395 return nsIURI_SetUserPass(This->uri, aUserPass);
1397 FIXME("default action not implemented\n");
1398 return NS_ERROR_NOT_IMPLEMENTED;
1401 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1403 nsURI *This = NSURI_THIS(iface);
1405 TRACE("(%p)->(%p)\n", This, aUsername);
1408 return nsIURI_GetUsername(This->uri, aUsername);
1410 FIXME("default action not implemented\n");
1411 return NS_ERROR_NOT_IMPLEMENTED;
1414 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1416 nsURI *This = NSURI_THIS(iface);
1418 TRACE("(%p)->(%p)\n", This, aUsername);
1421 return nsIURI_SetUsername(This->uri, aUsername);
1423 FIXME("default action not implemented\n");
1424 return NS_ERROR_NOT_IMPLEMENTED;
1427 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1429 nsURI *This = NSURI_THIS(iface);
1431 TRACE("(%p)->(%p)\n", This, aPassword);
1434 return nsIURI_GetPassword(This->uri, aPassword);
1436 FIXME("default action not implemented\n");
1437 return NS_ERROR_NOT_IMPLEMENTED;
1440 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1442 nsURI *This = NSURI_THIS(iface);
1444 TRACE("(%p)->(%p)\n", This, aPassword);
1447 return nsIURI_SetPassword(This->uri, aPassword);
1449 FIXME("default action not implemented\n");
1450 return NS_ERROR_NOT_IMPLEMENTED;
1453 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1455 nsURI *This = NSURI_THIS(iface);
1457 TRACE("(%p)->(%p)\n", This, aHostPort);
1460 return nsIURI_GetHostPort(This->uri, aHostPort);
1462 FIXME("default action not implemented\n");
1463 return NS_ERROR_NOT_IMPLEMENTED;
1466 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1468 nsURI *This = NSURI_THIS(iface);
1470 TRACE("(%p)->(%p)\n", This, aHostPort);
1473 return nsIURI_SetHostPort(This->uri, aHostPort);
1475 FIXME("default action not implemented\n");
1476 return NS_ERROR_NOT_IMPLEMENTED;
1479 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1481 nsURI *This = NSURI_THIS(iface);
1483 TRACE("(%p)->(%p)\n", This, aHost);
1486 return nsIURI_GetHost(This->uri, aHost);
1488 FIXME("default action not implemented\n");
1489 return NS_ERROR_NOT_IMPLEMENTED;
1492 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1494 nsURI *This = NSURI_THIS(iface);
1496 TRACE("(%p)->(%p)\n", This, aHost);
1499 return nsIURI_SetHost(This->uri, aHost);
1501 FIXME("default action not implemented\n");
1502 return NS_ERROR_NOT_IMPLEMENTED;
1505 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1507 nsURI *This = NSURI_THIS(iface);
1509 TRACE("(%p)->(%p)\n", This, aPort);
1512 return nsIURI_GetPort(This->uri, aPort);
1514 FIXME("default action not implemented\n");
1515 return NS_ERROR_NOT_IMPLEMENTED;
1518 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1520 nsURI *This = NSURI_THIS(iface);
1522 TRACE("(%p)->(%d)\n", This, aPort);
1525 return nsIURI_SetPort(This->uri, aPort);
1527 FIXME("default action not implemented\n");
1528 return NS_ERROR_NOT_IMPLEMENTED;
1531 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1533 nsURI *This = NSURI_THIS(iface);
1535 TRACE("(%p)->(%p)\n", This, aPath);
1538 return nsIURI_GetPath(This->uri, aPath);
1540 FIXME("default action not implemented\n");
1541 return NS_ERROR_NOT_IMPLEMENTED;
1544 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1546 nsURI *This = NSURI_THIS(iface);
1549 nsACString_GetData(aPath, &path);
1550 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1553 if(This->wine_url) {
1554 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1555 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1559 pathw = heap_strdupAtoW(path);
1560 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1563 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1565 WARN("UrlCombine failed: %08x\n", hres);
1571 return nsIURI_SetPath(This->uri, aPath);
1574 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1576 nsURI *This = NSURI_THIS(iface);
1577 nsIWineURI *wine_uri;
1578 LPCWSTR other_url = NULL;
1581 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1584 return nsIURI_Equals(This->uri, other, _retval);
1586 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1587 if(NS_FAILED(nsres)) {
1588 TRACE("Could not get nsIWineURI interface\n");
1593 nsIWineURI_GetWineURL(wine_uri, &other_url);
1594 *_retval = other_url && !UrlCompareW(This->wine_url, other_url, TRUE);
1595 nsIWineURI_Release(wine_uri);
1600 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1602 nsURI *This = NSURI_THIS(iface);
1604 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1606 if(This->use_wine_url) {
1607 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1608 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1610 *_retval = lstrlenW(This->wine_url) > len
1611 && This->wine_url[len] == ':'
1612 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1617 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1619 TRACE("returning error\n");
1620 return NS_ERROR_NOT_IMPLEMENTED;
1623 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1625 nsURI *This = NSURI_THIS(iface);
1626 nsIURI *nsuri = NULL;
1627 nsIWineURI *wine_uri;
1630 TRACE("(%p)->(%p)\n", This, _retval);
1633 nsres = nsIURI_Clone(This->uri, &nsuri);
1634 if(NS_FAILED(nsres)) {
1635 WARN("Clone failed: %08x\n", nsres);
1640 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1641 if(NS_FAILED(nsres)) {
1642 WARN("create_uri failed: %08x\n", nsres);
1646 *_retval = (nsIURI*)wine_uri;
1647 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1650 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1651 nsACString *_retval)
1653 nsURI *This = NSURI_THIS(iface);
1655 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1658 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1660 FIXME("default action not implemented\n");
1661 return NS_ERROR_NOT_IMPLEMENTED;
1664 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1666 nsURI *This = NSURI_THIS(iface);
1668 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1670 if(This->use_wine_url)
1671 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1674 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1676 TRACE("returning error\n");
1677 return NS_ERROR_NOT_IMPLEMENTED;
1680 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1682 nsURI *This = NSURI_THIS(iface);
1684 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1687 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1689 FIXME("default action not implemented\n");
1690 return NS_ERROR_NOT_IMPLEMENTED;
1693 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1695 nsURI *This = NSURI_THIS(iface);
1697 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1700 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1702 FIXME("default action not implemented\n");
1703 return NS_ERROR_NOT_IMPLEMENTED;
1706 static nsresult NSAPI nsURL_GetFilePath(nsIWineURI *iface, nsACString *aFilePath)
1708 nsURI *This = NSURI_THIS(iface);
1710 TRACE("(%p)->(%p)\n", This, aFilePath);
1713 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1715 FIXME("default action not implemented\n");
1716 return NS_ERROR_NOT_IMPLEMENTED;
1719 static nsresult NSAPI nsURL_SetFilePath(nsIWineURI *iface, const nsACString *aFilePath)
1721 nsURI *This = NSURI_THIS(iface);
1723 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1726 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1728 FIXME("default action not implemented\n");
1729 return NS_ERROR_NOT_IMPLEMENTED;
1732 static nsresult NSAPI nsURL_GetParam(nsIWineURI *iface, nsACString *aParam)
1734 nsURI *This = NSURI_THIS(iface);
1736 TRACE("(%p)->(%p)\n", This, aParam);
1739 return nsIURL_GetParam(This->nsurl, aParam);
1741 FIXME("default action not implemented\n");
1742 return NS_ERROR_NOT_IMPLEMENTED;
1745 static nsresult NSAPI nsURL_SetParam(nsIWineURI *iface, const nsACString *aParam)
1747 nsURI *This = NSURI_THIS(iface);
1749 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1752 return nsIURL_SetParam(This->nsurl, aParam);
1754 FIXME("default action not implemented\n");
1755 return NS_ERROR_NOT_IMPLEMENTED;
1758 static nsresult NSAPI nsURL_GetQuery(nsIWineURI *iface, nsACString *aQuery)
1760 nsURI *This = NSURI_THIS(iface);
1762 TRACE("(%p)->(%p)\n", This, aQuery);
1765 return nsIURL_GetQuery(This->nsurl, aQuery);
1767 FIXME("default action not implemented\n");
1768 return NS_ERROR_NOT_IMPLEMENTED;
1771 static nsresult NSAPI nsURL_SetQuery(nsIWineURI *iface, const nsACString *aQuery)
1773 nsURI *This = NSURI_THIS(iface);
1774 const WCHAR *ptr1, *ptr2;
1776 WCHAR *new_url, *ptr;
1779 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1782 nsIURL_SetQuery(This->nsurl, aQuery);
1787 nsACString_GetData(aQuery, &query);
1788 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1789 ptr1 = strchrW(This->wine_url, '?');
1791 size += ptr1-This->wine_url;
1792 ptr2 = strchrW(ptr1, '#');
1794 size += strlenW(ptr2);
1796 ptr1 = This->wine_url + strlenW(This->wine_url);
1798 size += strlenW(This->wine_url);
1804 new_url = heap_alloc(size*sizeof(WCHAR));
1805 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1806 ptr = new_url + (ptr1-This->wine_url);
1809 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1817 TRACE("setting %s\n", debugstr_w(new_url));
1819 heap_free(This->wine_url);
1820 This->wine_url = new_url;
1824 static nsresult NSAPI nsURL_GetRef(nsIWineURI *iface, nsACString *aRef)
1826 nsURI *This = NSURI_THIS(iface);
1828 TRACE("(%p)->(%p)\n", This, aRef);
1831 return nsIURL_GetRef(This->nsurl, aRef);
1833 FIXME("default action not implemented\n");
1834 return NS_ERROR_NOT_IMPLEMENTED;
1837 static nsresult NSAPI nsURL_SetRef(nsIWineURI *iface, const nsACString *aRef)
1839 nsURI *This = NSURI_THIS(iface);
1842 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1845 return nsIURL_SetRef(This->nsurl, aRef);
1847 nsACString_GetData(aRef, &refa);
1851 FIXME("default action not implemented\n");
1852 return NS_ERROR_NOT_IMPLEMENTED;
1855 static nsresult NSAPI nsURL_GetDirectory(nsIWineURI *iface, nsACString *aDirectory)
1857 nsURI *This = NSURI_THIS(iface);
1859 TRACE("(%p)->(%p)\n", This, aDirectory);
1862 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1864 FIXME("default action not implemented\n");
1865 return NS_ERROR_NOT_IMPLEMENTED;
1868 static nsresult NSAPI nsURL_SetDirectory(nsIWineURI *iface, const nsACString *aDirectory)
1870 nsURI *This = NSURI_THIS(iface);
1872 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
1875 return nsIURL_SetDirectory(This->nsurl, aDirectory);
1877 FIXME("default action not implemented\n");
1878 return NS_ERROR_NOT_IMPLEMENTED;
1881 static nsresult NSAPI nsURL_GetFileName(nsIWineURI *iface, nsACString *aFileName)
1883 nsURI *This = NSURI_THIS(iface);
1885 TRACE("(%p)->(%p)\n", This, aFileName);
1888 return nsIURL_GetFileName(This->nsurl, aFileName);
1890 FIXME("default action not implemented\n");
1891 return NS_ERROR_NOT_IMPLEMENTED;
1894 static nsresult NSAPI nsURL_SetFileName(nsIWineURI *iface, const nsACString *aFileName)
1896 nsURI *This = NSURI_THIS(iface);
1898 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
1901 return nsIURL_SetFileName(This->nsurl, aFileName);
1903 FIXME("default action not implemented\n");
1904 return NS_ERROR_NOT_IMPLEMENTED;
1907 static nsresult NSAPI nsURL_GetFileBaseName(nsIWineURI *iface, nsACString *aFileBaseName)
1909 nsURI *This = NSURI_THIS(iface);
1911 TRACE("(%p)->(%p)\n", This, aFileBaseName);
1914 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
1916 FIXME("default action not implemented\n");
1917 return NS_ERROR_NOT_IMPLEMENTED;
1920 static nsresult NSAPI nsURL_SetFileBaseName(nsIWineURI *iface, const nsACString *aFileBaseName)
1922 nsURI *This = NSURI_THIS(iface);
1924 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
1927 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
1929 FIXME("default action not implemented\n");
1930 return NS_ERROR_NOT_IMPLEMENTED;
1933 static nsresult NSAPI nsURL_GetFileExtension(nsIWineURI *iface, nsACString *aFileExtension)
1935 nsURI *This = NSURI_THIS(iface);
1937 TRACE("(%p)->(%p)\n", This, aFileExtension);
1940 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
1942 FIXME("default action not implemented\n");
1943 return NS_ERROR_NOT_IMPLEMENTED;
1946 static nsresult NSAPI nsURL_SetFileExtension(nsIWineURI *iface, const nsACString *aFileExtension)
1948 nsURI *This = NSURI_THIS(iface);
1950 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
1953 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
1955 FIXME("default action not implemented\n");
1956 return NS_ERROR_NOT_IMPLEMENTED;
1959 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
1961 nsURI *This = NSURI_THIS(iface);
1963 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
1966 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
1968 FIXME("default action not implemented\n");
1969 return NS_ERROR_NOT_IMPLEMENTED;
1972 static nsresult NSAPI nsURL_GetRelativeSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
1974 nsURI *This = NSURI_THIS(iface);
1976 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
1979 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
1981 FIXME("default action not implemented\n");
1982 return NS_ERROR_NOT_IMPLEMENTED;
1985 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1987 nsURI *This = NSURI_THIS(iface);
1989 TRACE("(%p)->(%p)\n", This, aContainer);
1992 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1993 *aContainer = This->container;
1998 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
2000 nsURI *This = NSURI_THIS(iface);
2002 TRACE("(%p)->(%p)\n", This, aContainer);
2004 if(This->container) {
2005 if(This->container == aContainer)
2007 TRACE("Changing %p -> %p\n", This->container, aContainer);
2008 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
2012 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
2013 This->container = aContainer;
2018 static nsresult NSAPI nsURI_GetWindow(nsIWineURI *iface, HTMLWindow **aHTMLWindow)
2020 nsURI *This = NSURI_THIS(iface);
2022 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2024 if(This->window_ref && This->window_ref->window) {
2025 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window_ref->window));
2026 *aHTMLWindow = This->window_ref->window;
2028 *aHTMLWindow = NULL;
2034 static nsresult NSAPI nsURI_SetWindow(nsIWineURI *iface, HTMLWindow *aHTMLWindow)
2036 nsURI *This = NSURI_THIS(iface);
2038 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2040 if(This->window_ref) {
2041 if(This->window_ref->window == aHTMLWindow)
2043 TRACE("Changing %p -> %p\n", This->window_ref->window, aHTMLWindow);
2044 windowref_release(This->window_ref);
2048 windowref_addref(aHTMLWindow->window_ref);
2049 This->window_ref = aHTMLWindow->window_ref;
2051 if(aHTMLWindow->doc_obj)
2052 nsIWineURI_SetNSContainer(NSWINEURI(This), aHTMLWindow->doc_obj->nscontainer);
2054 This->window_ref = NULL;
2060 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
2062 nsURI *This = NSURI_THIS(iface);
2064 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
2066 *aIsDocumentURI = This->is_doc_uri;
2070 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
2072 nsURI *This = NSURI_THIS(iface);
2074 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
2076 This->is_doc_uri = aIsDocumentURI;
2080 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
2082 nsURI *This = NSURI_THIS(iface);
2084 TRACE("(%p)->(%p)\n", This, aURL);
2086 *aURL = This->wine_url;
2090 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
2092 nsURI *This = NSURI_THIS(iface);
2094 static const WCHAR wszFtp[] = {'f','t','p',':'};
2095 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
2096 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
2098 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
2100 heap_free(This->wine_url);
2103 int len = strlenW(aURL)+1;
2104 This->wine_url = heap_alloc(len*sizeof(WCHAR));
2105 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
2108 /* FIXME: Always use wine url */
2109 This->use_wine_url =
2110 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
2111 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
2112 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
2114 This->use_wine_url = TRUE;
2117 This->wine_url = NULL;
2118 This->use_wine_url = FALSE;
2126 static const nsIWineURIVtbl nsWineURIVtbl = {
2127 nsURI_QueryInterface,
2155 nsURI_GetOriginCharset,
2168 nsURL_GetFileBaseName,
2169 nsURL_SetFileBaseName,
2170 nsURL_GetFileExtension,
2171 nsURL_SetFileExtension,
2172 nsURL_GetCommonBaseSpec,
2173 nsURL_GetRelativeSpec,
2174 nsURI_GetNSContainer,
2175 nsURI_SetNSContainer,
2178 nsURI_GetIsDocumentURI,
2179 nsURI_SetIsDocumentURI,
2184 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsIWineURI **_retval)
2186 nsURI *ret = heap_alloc_zero(sizeof(nsURI));
2188 ret->lpWineURIVtbl = &nsWineURIVtbl;
2192 nsIWineURI_SetNSContainer(NSWINEURI(ret), container);
2193 nsIWineURI_SetWindow(NSWINEURI(ret), window);
2196 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2200 TRACE("retval=%p\n", ret);
2201 *_retval = NSWINEURI(ret);
2205 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsIWineURI **ret)
2210 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2211 if(NS_FAILED(nsres))
2214 nsIWineURI_SetWineURL(uri, url);
2215 nsIWineURI_SetIsDocumentURI(uri, TRUE);
2222 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2226 nsIProtocolHandler *nshandler;
2227 } nsProtocolHandler;
2229 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2231 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2233 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2236 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2240 if(IsEqualGUID(&IID_nsISupports, riid)) {
2241 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2242 *result = NSPROTHANDLER(This);
2243 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2244 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2245 *result = NSPROTHANDLER(This);
2246 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2247 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2248 return NS_NOINTERFACE;
2252 nsISupports_AddRef((nsISupports*)*result);
2256 WARN("(%s %p)\n", debugstr_guid(riid), result);
2257 return NS_NOINTERFACE;
2260 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2262 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2263 LONG ref = InterlockedIncrement(&This->ref);
2265 TRACE("(%p) ref=%d\n", This, ref);
2270 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2272 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2273 LONG ref = InterlockedDecrement(&This->ref);
2275 TRACE("(%p) ref=%d\n", This, ref);
2279 nsIProtocolHandler_Release(This->nshandler);
2286 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2288 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2290 TRACE("(%p)->(%p)\n", This, aScheme);
2293 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2294 return NS_ERROR_NOT_IMPLEMENTED;
2297 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2298 PRInt32 *aDefaultPort)
2300 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2302 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2305 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2306 return NS_ERROR_NOT_IMPLEMENTED;
2309 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2310 PRUint32 *aProtocolFlags)
2312 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2314 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2317 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2318 return NS_ERROR_NOT_IMPLEMENTED;
2321 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2322 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2324 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2326 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2329 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2330 return NS_ERROR_NOT_IMPLEMENTED;
2333 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2334 nsIURI *aURI, nsIChannel **_retval)
2336 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2338 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2341 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2342 return NS_ERROR_NOT_IMPLEMENTED;
2345 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2346 PRInt32 port, const char *scheme, PRBool *_retval)
2348 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2350 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2353 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2354 return NS_ERROR_NOT_IMPLEMENTED;
2357 #undef NSPROTHANDLER_THIS
2359 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2360 nsProtocolHandler_QueryInterface,
2361 nsProtocolHandler_AddRef,
2362 nsProtocolHandler_Release,
2363 nsProtocolHandler_GetScheme,
2364 nsProtocolHandler_GetDefaultPort,
2365 nsProtocolHandler_GetProtocolFlags,
2366 nsProtocolHandler_NewURI,
2367 nsProtocolHandler_NewChannel,
2368 nsProtocolHandler_AllowPort
2371 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2373 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2375 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2377 ret->nshandler = nshandler;
2379 return NSPROTHANDLER(ret);
2382 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2384 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2389 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2394 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2395 nsIProtocolHandler **_retval)
2397 nsIExternalProtocolHandler *nsexthandler;
2398 nsIProtocolHandler *nshandler;
2401 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2403 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2404 if(NS_FAILED(nsres)) {
2405 WARN("GetProtocolHandler failed: %08x\n", nsres);
2409 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2410 (void**)&nsexthandler);
2411 if(NS_FAILED(nsres)) {
2412 *_retval = nshandler;
2416 nsIExternalProtocolHandler_Release(nsexthandler);
2417 *_retval = create_protocol_handler(nshandler);
2418 TRACE("return %p\n", *_retval);
2422 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2425 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2426 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2429 static BOOL is_gecko_special_uri(const char *spec)
2431 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2434 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2435 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2442 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2443 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2445 const char *spec = NULL;
2446 HTMLWindow *window = NULL;
2448 LPCWSTR base_wine_url = NULL;
2449 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2450 BOOL is_wine_uri = FALSE;
2453 nsACString_GetData(aSpec, &spec);
2455 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2458 if(is_gecko_special_uri(spec))
2459 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2461 if(!strncmp(spec, "wine:", 5)) {
2467 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2469 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2470 if(NS_SUCCEEDED(nsres)) {
2471 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2472 nsIWineURI_GetWindow(base_wine_uri, &window);
2473 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2474 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2475 TRACE("not wraping\n");
2476 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2478 WARN("Could not get base nsIWineURI: %08x\n", nsres);
2482 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2483 if(NS_FAILED(nsres))
2484 TRACE("NewURI failed: %08x\n", nsres);
2486 nsres = create_uri(uri, window, NULL, &wine_uri);
2487 *_retval = (nsIURI*)wine_uri;
2490 IHTMLWindow2_Release(HTMLWINDOW2(window));
2493 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2497 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2499 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2500 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2501 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2503 nsIWineURI_SetWineURL(wine_uri, url);
2505 WARN("CoCombineUrl failed: %08x\n", hres);
2506 }else if(is_wine_uri) {
2507 WCHAR url[INTERNET_MAX_URL_LENGTH];
2509 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2510 nsIWineURI_SetWineURL(wine_uri, url);
2514 nsIWineURI_Release(base_wine_uri);
2519 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2522 TRACE("(%p %p)\n", aFile, _retval);
2523 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2526 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2527 nsIChannel **_retval)
2529 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2531 nsIWineURI *wine_uri;
2535 TRACE("(%p %p)\n", aURI, _retval);
2537 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2538 if(NS_FAILED(nsres)) {
2539 TRACE("Could not get nsIWineURI: %08x\n", nsres);
2540 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2543 ret = heap_alloc_zero(sizeof(nsChannel));
2545 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2546 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2547 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2549 ret->uri = wine_uri;
2551 nsIURI_AddRef(aURI);
2552 ret->original_uri = aURI;
2554 nsIWineURI_GetWineURL(wine_uri, &url);
2555 ret->url_scheme = url && SUCCEEDED(ParseURLW(url, &parsed_url)) ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2557 *_retval = NSCHANNEL(ret);
2561 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2562 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2564 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2565 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2568 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2570 TRACE("(%p)\n", aOffline);
2571 return nsIIOService_GetOffline(nsio, aOffline);
2574 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2576 TRACE("(%x)\n", aOffline);
2577 return nsIIOService_SetOffline(nsio, aOffline);
2580 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2581 const char *aScheme, PRBool *_retval)
2583 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2584 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2587 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2588 nsACString * _retval)
2590 TRACE("(%p %p)\n", urlString, _retval);
2591 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2594 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2595 nsIOService_QueryInterface,
2597 nsIOService_Release,
2598 nsIOService_GetProtocolHandler,
2599 nsIOService_GetProtocolFlags,
2601 nsIOService_NewFileURI,
2602 nsIOService_NewChannelFromURI,
2603 nsIOService_NewChannel,
2604 nsIOService_GetOffline,
2605 nsIOService_SetOffline,
2606 nsIOService_AllowPort,
2607 nsIOService_ExtractScheme
2610 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2612 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2615 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2618 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2623 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2628 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2629 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2631 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2633 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2636 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2640 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2643 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2645 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2647 if(aFlags == (1<<11)) {
2652 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2655 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2657 TRACE("(%p %p)\n", aURI, _retval);
2659 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2662 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2663 PRUint32 aEscapeType, nsACString *_retval)
2665 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2667 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2670 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2671 nsACString *_retval)
2673 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2675 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2678 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2679 PRUint32 aFlags, nsACString *_retval)
2681 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2683 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2686 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2687 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2689 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2691 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2694 static const nsINetUtilVtbl nsNetUtilVtbl = {
2695 nsNetUtil_QueryInterface,
2698 nsNetUtil_ParseContentType,
2699 nsNetUtil_ProtocolHasFlags,
2700 nsNetUtil_URIChainHasFlags,
2701 nsNetUtil_ToImmutableURI,
2702 nsNetUtil_EscapeString,
2703 nsNetUtil_EscapeURL,
2704 nsNetUtil_UnescapeString,
2705 nsNetUtil_ExtractCharsetFromContentType
2708 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2710 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2715 if(IsEqualGUID(&IID_nsISupports, riid))
2716 *result = &nsIOService;
2717 else if(IsEqualGUID(&IID_nsIIOService, riid))
2718 *result = &nsIOService;
2719 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2720 *result = &nsNetUtil;
2723 nsISupports_AddRef((nsISupports*)*result);
2727 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2728 return NS_NOINTERFACE;
2731 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2736 if(IsEqualGUID(&IID_nsISupports, riid)) {
2737 TRACE("(IID_nsISupports %p)\n", result);
2739 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2740 TRACE("(IID_nsIFactory %p)\n", result);
2745 nsIFactory_AddRef(iface);
2749 WARN("(%s %p)\n", debugstr_guid(riid), result);
2750 return NS_NOINTERFACE;
2753 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2758 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2763 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2764 nsISupports *aOuter, const nsIID *iid, void **result)
2766 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2769 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2771 WARN("(%x)\n", lock);
2775 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2776 nsIOServiceFactory_QueryInterface,
2777 nsIOServiceFactory_AddRef,
2778 nsIOServiceFactory_Release,
2779 nsIOServiceFactory_CreateInstance,
2780 nsIOServiceFactory_LockFactory
2783 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2785 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2787 nsIFactory *old_factory = NULL;
2790 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2791 &IID_nsIFactory, (void**)&old_factory);
2792 if(NS_FAILED(nsres)) {
2793 ERR("Could not get factory: %08x\n", nsres);
2797 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2798 if(NS_FAILED(nsres)) {
2799 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2800 nsIFactory_Release(old_factory);
2804 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2805 if(NS_FAILED(nsres)) {
2806 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2807 nsIIOService_Release(nsio);
2811 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2812 nsIFactory_Release(old_factory);
2813 if(NS_FAILED(nsres))
2814 ERR("UnregisterFactory failed: %08x\n", nsres);
2816 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2817 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2818 if(NS_FAILED(nsres))
2819 ERR("RegisterFactory failed: %08x\n", nsres);
2822 void release_nsio(void)
2825 nsINetUtil_Release(net_util);
2830 nsIIOService_Release(nsio);