2 * Copyright 2006-2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID =
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static const IID IID_nsWineURI =
47 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
49 static nsIIOService *nsio = NULL;
50 static nsINetUtil *net_util;
52 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
55 const nsIURLVtbl *lpIURLVtbl;
61 NSContainer *container;
62 windowref_t *window_ref;
63 nsChannelBSC *channel_bsc;
69 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
70 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
72 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsWineURI**);
74 static const char *debugstr_nsacstr(const nsACString *nsstr)
78 nsACString_GetData(nsstr, &data);
79 return debugstr_a(data);
82 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
84 const WCHAR *ptr = nsuri;
86 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
88 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
89 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
91 if(*ptr || ret_empty) {
92 *ret = SysAllocString(ptr);
99 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
103 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
105 IOleCommandTarget *cmdtrg = NULL;
108 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
109 if(SUCCEEDED(hres)) {
110 VARIANT varUrl, varRes;
112 V_VT(&varUrl) = VT_BSTR;
113 V_BSTR(&varUrl) = SysAllocString(url);
114 V_VT(&varRes) = VT_BOOL;
116 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
118 IOleCommandTarget_Release(cmdtrg);
119 SysFreeString(V_BSTR(&varUrl));
121 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
122 TRACE("got VARIANT_FALSE, do not load\n");
130 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
132 HTMLDocumentObj *doc = container->doc;
138 NSContainer *container_iter = container;
140 hlnf = HLNF_OPENINNEWWINDOW;
141 while(!container_iter->doc)
142 container_iter = container_iter->parent;
143 doc = container_iter->doc;
149 if(!hlnf && !exec_shldocvw_67(doc, channel->uri->wine_url))
152 hres = hlink_frame_navigate(&doc->basedoc, channel->uri->wine_url, channel->post_data_stream, hlnf, &cancel);
153 return FAILED(hres) || cancel;
156 HRESULT load_nsuri(HTMLWindow *window, nsWineURI *uri, nsChannelBSC *channelbsc, DWORD flags)
158 nsIWebNavigation *web_navigation;
159 nsIDocShell *doc_shell;
162 nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation);
163 if(NS_FAILED(nsres)) {
164 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
168 nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell);
169 nsIWebNavigation_Release(web_navigation);
170 if(NS_FAILED(nsres)) {
171 ERR("Could not get nsIDocShell: %08x\n", nsres);
176 uri->channel_bsc = channelbsc;
177 nsres = nsIDocShell_LoadURI(doc_shell, NSURI(uri), NULL, flags, FALSE);
178 uri->channel_bsc = NULL;
179 nsIDocShell_Release(doc_shell);
180 if(NS_FAILED(nsres)) {
181 WARN("LoadURI failed: %08x\n", nsres);
188 static BOOL translate_url(HTMLDocumentObj *doc, nsWineURI *uri)
190 OLECHAR *new_url = NULL, *url;
197 url = heap_strdupW(uri->wine_url);
198 hres = IDocHostUIHandler_TranslateUrl(doc->hostui, 0, url, &new_url);
200 if(hres != S_OK || !new_url)
203 if(strcmpW(url, new_url)) {
204 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url), debugstr_w(new_url));
208 CoTaskMemFree(new_url);
212 nsresult on_start_uri_open(NSContainer *nscontainer, nsIURI *uri, PRBool *_retval)
219 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
220 if(NS_FAILED(nsres)) {
221 WARN("Could not get nsWineURI: %08x\n", nsres);
222 return NS_ERROR_NOT_IMPLEMENTED;
225 if(!wine_uri->is_doc_uri) {
226 if(!wine_uri->container) {
227 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
228 wine_uri->container = nscontainer;
231 wine_uri->is_doc_uri = TRUE;
232 *_retval = translate_url(nscontainer->doc->basedoc.doc_obj, wine_uri);
235 nsIURI_Release(NSURI(wine_uri));
239 HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
241 static const WCHAR wszFtp[] = {'f','t','p',':'};
242 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
243 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
245 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
250 new_url = heap_strdupW(url);
252 return E_OUTOFMEMORY;
253 heap_free(This->wine_url);
254 This->wine_url = new_url;
257 /* FIXME: Always use wine url */
259 strncmpW(url, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
260 && strncmpW(url, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
261 && strncmpW(url, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
263 This->use_wine_url = TRUE;
266 heap_free(This->wine_url);
267 This->wine_url = NULL;
268 This->use_wine_url = FALSE;
274 static void set_uri_nscontainer(nsWineURI *This, NSContainer *nscontainer)
276 if(This->container) {
277 if(This->container == nscontainer)
279 TRACE("Changing %p -> %p\n", This->container, nscontainer);
280 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
284 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer));
285 This->container = nscontainer;
288 static void set_uri_window(nsWineURI *This, HTMLWindow *window)
290 if(This->window_ref) {
291 if(This->window_ref->window == window)
293 TRACE("Changing %p -> %p\n", This->window_ref->window, window);
294 windowref_release(This->window_ref);
298 windowref_addref(window->window_ref);
299 This->window_ref = window->window_ref;
302 set_uri_nscontainer(This, window->doc_obj->nscontainer);
304 This->window_ref = NULL;
308 static inline BOOL is_http_channel(nsChannel *This)
310 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTP;
313 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
315 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
317 nsChannel *This = NSCHANNEL_THIS(iface);
319 if(IsEqualGUID(&IID_nsISupports, riid)) {
320 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
321 *result = NSCHANNEL(This);
322 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
323 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
324 *result = NSCHANNEL(This);
325 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
326 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
327 *result = NSCHANNEL(This);
328 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
329 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
330 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
331 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
332 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
333 *result = NSUPCHANNEL(This);
334 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
335 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
336 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
338 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
343 nsIChannel_AddRef(NSCHANNEL(This));
347 return NS_NOINTERFACE;
350 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
352 nsChannel *This = NSCHANNEL_THIS(iface);
353 nsrefcnt ref = InterlockedIncrement(&This->ref);
355 TRACE("(%p) ref=%d\n", This, ref);
360 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
362 nsChannel *This = NSCHANNEL_THIS(iface);
363 LONG ref = InterlockedDecrement(&This->ref);
366 nsIURI_Release(NSURI(This->uri));
368 nsISupports_Release(This->owner);
369 if(This->post_data_stream)
370 nsIInputStream_Release(This->post_data_stream);
372 nsILoadGroup_Release(This->load_group);
373 if(This->notif_callback)
374 nsIInterfaceRequestor_Release(This->notif_callback);
375 if(This->original_uri)
376 nsIURI_Release(This->original_uri);
377 heap_free(This->content_type);
378 heap_free(This->charset);
385 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
387 nsChannel *This = NSCHANNEL_THIS(iface);
389 FIXME("(%p)->(%p)\n", This, aName);
391 return NS_ERROR_NOT_IMPLEMENTED;
394 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
396 nsChannel *This = NSCHANNEL_THIS(iface);
398 FIXME("(%p)->(%p)\n", This, _retval);
400 return NS_ERROR_NOT_IMPLEMENTED;
403 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
405 nsChannel *This = NSCHANNEL_THIS(iface);
407 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
409 return *aStatus = NS_OK;
412 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
414 nsChannel *This = NSCHANNEL_THIS(iface);
416 FIXME("(%p)->(%08x)\n", This, aStatus);
418 return NS_ERROR_NOT_IMPLEMENTED;
421 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
423 nsChannel *This = NSCHANNEL_THIS(iface);
425 FIXME("(%p)\n", This);
427 return NS_ERROR_NOT_IMPLEMENTED;
430 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
432 nsChannel *This = NSCHANNEL_THIS(iface);
434 FIXME("(%p)\n", This);
436 return NS_ERROR_NOT_IMPLEMENTED;
439 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
441 nsChannel *This = NSCHANNEL_THIS(iface);
443 TRACE("(%p)->(%p)\n", This, aLoadGroup);
446 nsILoadGroup_AddRef(This->load_group);
448 *aLoadGroup = This->load_group;
452 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
454 nsChannel *This = NSCHANNEL_THIS(iface);
456 TRACE("(%p)->(%p)\n", This, aLoadGroup);
459 nsILoadGroup_Release(This->load_group);
461 nsILoadGroup_AddRef(aLoadGroup);
462 This->load_group = aLoadGroup;
467 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
469 nsChannel *This = NSCHANNEL_THIS(iface);
471 TRACE("(%p)->(%p)\n", This, aLoadFlags);
473 *aLoadFlags = This->load_flags;
477 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
479 nsChannel *This = NSCHANNEL_THIS(iface);
481 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
483 This->load_flags = aLoadFlags;
487 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
489 nsChannel *This = NSCHANNEL_THIS(iface);
491 TRACE("(%p)->(%p)\n", This, aOriginalURI);
493 if(This->original_uri)
494 nsIURI_AddRef(This->original_uri);
496 *aOriginalURI = This->original_uri;
500 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
502 nsChannel *This = NSCHANNEL_THIS(iface);
504 TRACE("(%p)->(%p)\n", This, aOriginalURI);
506 if(This->original_uri)
507 nsIURI_Release(This->original_uri);
509 nsIURI_AddRef(aOriginalURI);
510 This->original_uri = aOriginalURI;
514 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
516 nsChannel *This = NSCHANNEL_THIS(iface);
518 TRACE("(%p)->(%p)\n", This, aURI);
520 nsIURI_AddRef(NSURI(This->uri));
521 *aURI = (nsIURI*)This->uri;
526 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
528 nsChannel *This = NSCHANNEL_THIS(iface);
530 TRACE("(%p)->(%p)\n", This, aOwner);
533 nsISupports_AddRef(This->owner);
534 *aOwner = This->owner;
539 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
541 nsChannel *This = NSCHANNEL_THIS(iface);
543 TRACE("(%p)->(%p)\n", This, aOwner);
546 nsISupports_AddRef(aOwner);
548 nsISupports_Release(This->owner);
549 This->owner = aOwner;
554 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
555 nsIInterfaceRequestor **aNotificationCallbacks)
557 nsChannel *This = NSCHANNEL_THIS(iface);
559 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
561 if(This->notif_callback)
562 nsIInterfaceRequestor_AddRef(This->notif_callback);
563 *aNotificationCallbacks = This->notif_callback;
568 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
569 nsIInterfaceRequestor *aNotificationCallbacks)
571 nsChannel *This = NSCHANNEL_THIS(iface);
573 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
575 if(This->notif_callback)
576 nsIInterfaceRequestor_Release(This->notif_callback);
577 if(aNotificationCallbacks)
578 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
580 This->notif_callback = aNotificationCallbacks;
585 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
587 nsChannel *This = NSCHANNEL_THIS(iface);
589 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
591 return NS_ERROR_NOT_IMPLEMENTED;
594 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
596 nsChannel *This = NSCHANNEL_THIS(iface);
598 TRACE("(%p)->(%p)\n", This, aContentType);
600 if(This->content_type) {
601 nsACString_SetData(aContentType, This->content_type);
605 WARN("unknown type\n");
606 return NS_ERROR_FAILURE;
609 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
610 const nsACString *aContentType)
612 nsChannel *This = NSCHANNEL_THIS(iface);
613 const char *content_type;
615 TRACE("(%p)->(%p)\n", This, aContentType);
617 nsACString_GetData(aContentType, &content_type);
619 TRACE("content_type %s\n", content_type);
621 heap_free(This->content_type);
622 This->content_type = heap_strdupA(content_type);
627 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
628 nsACString *aContentCharset)
630 nsChannel *This = NSCHANNEL_THIS(iface);
632 TRACE("(%p)->(%p)\n", This, aContentCharset);
635 nsACString_SetData(aContentCharset, This->charset);
639 nsACString_SetData(aContentCharset, "");
643 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
644 const nsACString *aContentCharset)
646 nsChannel *This = NSCHANNEL_THIS(iface);
648 FIXME("(%p)->(%p)\n", This, aContentCharset);
650 return NS_ERROR_NOT_IMPLEMENTED;
653 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
655 nsChannel *This = NSCHANNEL_THIS(iface);
657 FIXME("(%p)->(%p)\n", This, aContentLength);
659 return NS_ERROR_NOT_IMPLEMENTED;
662 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
664 nsChannel *This = NSCHANNEL_THIS(iface);
666 FIXME("(%p)->(%d)\n", This, aContentLength);
668 return NS_ERROR_NOT_IMPLEMENTED;
671 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
673 nsChannel *This = NSCHANNEL_THIS(iface);
675 FIXME("(%p)->(%p)\n", This, _retval);
677 return NS_ERROR_NOT_IMPLEMENTED;
680 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
686 if(!channel->original_uri) {
687 ERR("original_uri == NULL\n");
691 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsWineURI, (void**)&wine_uri);
692 if(NS_FAILED(nsres)) {
693 ERR("Could not get nsWineURI: %08x\n", nsres);
697 if(wine_uri->wine_url) {
698 hres = CreateURLMoniker(NULL, wine_uri->wine_url, mon);
700 WARN("CreateURLMoniker failed: %08x\n", hres);
702 TRACE("wine_url == NULL\n");
706 nsIURI_Release(NSURI(wine_uri));
711 static HTMLWindow *get_window_from_load_group(nsChannel *This)
720 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
721 if(NS_FAILED(nsres)) {
722 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
729 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
730 nsIRequest_Release(req);
731 if(NS_FAILED(nsres)) {
732 WARN("Could not get nsIChannel interface: %08x\n", nsres);
736 nsres = nsIChannel_GetURI(channel, &uri);
737 nsIChannel_Release(channel);
738 if(NS_FAILED(nsres)) {
739 ERR("GetURI failed: %08x\n", nsres);
743 nsres = nsIURI_QueryInterface(uri, &IID_nsWineURI, (void**)&wine_uri);
745 if(NS_FAILED(nsres)) {
746 TRACE("Could not get nsWineURI: %08x\n", nsres);
750 window = wine_uri->window_ref ? wine_uri->window_ref->window : NULL;
752 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
753 nsIURI_Release(NSURI(wine_uri));
758 static HTMLWindow *get_channel_window(nsChannel *This)
760 nsIRequestObserver *req_observer;
761 nsIWebProgress *web_progress;
762 nsIDOMWindow *nswindow;
766 if(!This->load_group) {
767 ERR("NULL load_group\n");
771 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
772 if(NS_FAILED(nsres) || !req_observer) {
773 ERR("GetGroupObserver failed: %08x\n", nsres);
777 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
778 nsIRequestObserver_Release(req_observer);
779 if(NS_FAILED(nsres)) {
780 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
784 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
785 nsIWebProgress_Release(web_progress);
786 if(NS_FAILED(nsres) || !nswindow) {
787 ERR("GetDOMWindow failed: %08x\n", nsres);
791 window = nswindow_to_window(nswindow);
792 nsIDOMWindow_Release(nswindow);
795 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
797 FIXME("NULL window for %p\n", nswindow);
803 HTMLDocumentNode *doc;
804 nsChannelBSC *bscallback;
805 } start_binding_task_t;
807 static void start_binding_proc(task_t *_task)
809 start_binding_task_t *task = (start_binding_task_t*)_task;
811 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
813 IUnknown_Release((IUnknown*)task->bscallback);
816 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
817 nsISupports *context)
819 nsChannelBSC *bscallback;
820 IMoniker *mon = NULL;
823 hres = create_mon_for_nschannel(This, &mon);
825 return NS_ERROR_UNEXPECTED;
828 set_current_mon(window, mon);
830 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
831 IMoniker_Release(mon);
833 return NS_ERROR_UNEXPECTED;
835 channelbsc_set_channel(bscallback, This, listener, context);
838 set_window_bscallback(window, bscallback);
839 async_start_doc_binding(window, bscallback);
840 IUnknown_Release((IUnknown*)bscallback);
842 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
844 task->doc = window->doc;
845 task->bscallback = bscallback;
846 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
852 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
853 nsISupports *aContext)
855 nsChannel *This = NSCHANNEL_THIS(iface);
856 HTMLWindow *window = NULL;
858 nsresult nsres = NS_OK;
860 TRACE("(%p)->(%p %p) opening %s\n", This, aListener, aContext, debugstr_w(This->uri->wine_url));
862 if(This->uri->is_doc_uri) {
863 window = get_channel_window(This);
865 set_uri_window(This->uri, window);
866 }else if(This->uri->container) {
869 /* nscontainer->doc should be NULL which means navigation to a new window */
870 if(This->uri->container->doc)
871 FIXME("nscontainer->doc = %p\n", This->uri->container->doc);
873 b = before_async_open(This, This->uri->container);
875 FIXME("Navigation not cancelled\n");
876 return NS_ERROR_UNEXPECTED;
881 if(This->uri->window_ref && This->uri->window_ref->window) {
882 window = This->uri->window_ref->window;
883 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
884 }else if(This->load_group) {
885 window = get_window_from_load_group(This);
887 set_uri_window(This->uri, window);
892 ERR("window = NULL\n");
893 return NS_ERROR_UNEXPECTED;
896 if(This->uri->is_doc_uri && window == window->doc_obj->basedoc.window) {
897 if(This->uri->channel_bsc) {
898 channelbsc_set_channel(This->uri->channel_bsc, This, aListener, aContext);
900 if(window->doc_obj->mime) {
901 heap_free(This->content_type);
902 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
907 open = !before_async_open(This, window->doc_obj->nscontainer);
910 nsres = NS_ERROR_UNEXPECTED;
916 nsres = async_open(This, window, This->uri->is_doc_uri, aListener, aContext);
918 IHTMLWindow2_Release(HTMLWINDOW2(window));
922 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
924 nsChannel *This = NSCHANNEL_THIS(iface);
926 FIXME("(%p)->(%p)\n", This, aRequestMethod);
928 return NS_ERROR_NOT_IMPLEMENTED;
931 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
932 const nsACString *aRequestMethod)
934 nsChannel *This = NSCHANNEL_THIS(iface);
936 FIXME("(%p)->(%p)\n", This, aRequestMethod);
938 return NS_ERROR_NOT_IMPLEMENTED;
941 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
943 nsChannel *This = NSCHANNEL_THIS(iface);
945 FIXME("(%p)->(%p)\n", This, aReferrer);
947 return NS_ERROR_NOT_IMPLEMENTED;
950 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
952 nsChannel *This = NSCHANNEL_THIS(iface);
954 FIXME("(%p)->(%p)\n", This, aReferrer);
959 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
960 const nsACString *aHeader, nsACString *_retval)
962 nsChannel *This = NSCHANNEL_THIS(iface);
964 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
966 return NS_ERROR_NOT_IMPLEMENTED;
969 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
970 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
972 nsChannel *This = NSCHANNEL_THIS(iface);
974 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
979 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
980 nsIHttpHeaderVisitor *aVisitor)
982 nsChannel *This = NSCHANNEL_THIS(iface);
984 FIXME("(%p)->(%p)\n", This, aVisitor);
986 return NS_ERROR_NOT_IMPLEMENTED;
989 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
991 nsChannel *This = NSCHANNEL_THIS(iface);
993 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
995 return NS_ERROR_NOT_IMPLEMENTED;
998 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
1000 nsChannel *This = NSCHANNEL_THIS(iface);
1002 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
1004 return NS_ERROR_NOT_IMPLEMENTED;
1007 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
1009 nsChannel *This = NSCHANNEL_THIS(iface);
1011 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
1013 return NS_ERROR_NOT_IMPLEMENTED;
1016 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
1018 nsChannel *This = NSCHANNEL_THIS(iface);
1020 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
1022 return NS_ERROR_NOT_IMPLEMENTED;
1025 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
1027 nsChannel *This = NSCHANNEL_THIS(iface);
1029 TRACE("(%p)->(%p)\n", This, aResponseStatus);
1031 if(This->response_status) {
1032 *aResponseStatus = This->response_status;
1036 WARN("No response status\n");
1037 return NS_ERROR_UNEXPECTED;
1040 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
1041 nsACString *aResponseStatusText)
1043 nsChannel *This = NSCHANNEL_THIS(iface);
1045 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
1047 return NS_ERROR_NOT_IMPLEMENTED;
1050 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1051 PRBool *aRequestSucceeded)
1053 nsChannel *This = NSCHANNEL_THIS(iface);
1055 FIXME("(%p)->(%p)\n", This, aRequestSucceeded);
1057 return NS_ERROR_NOT_IMPLEMENTED;
1060 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1061 const nsACString *header, nsACString *_retval)
1063 nsChannel *This = NSCHANNEL_THIS(iface);
1065 FIXME("(%p)->(%p %p)\n", This, header, _retval);
1067 return NS_ERROR_NOT_IMPLEMENTED;
1070 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1071 const nsACString *header, const nsACString *value, PRBool merge)
1073 nsChannel *This = NSCHANNEL_THIS(iface);
1075 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
1077 return NS_ERROR_NOT_IMPLEMENTED;
1080 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1081 nsIHttpHeaderVisitor *aVisitor)
1083 nsChannel *This = NSCHANNEL_THIS(iface);
1085 FIXME("(%p)->(%p)\n", This, aVisitor);
1087 return NS_ERROR_NOT_IMPLEMENTED;
1090 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1092 nsChannel *This = NSCHANNEL_THIS(iface);
1094 FIXME("(%p)->(%p)\n", This, _retval);
1096 return NS_ERROR_NOT_IMPLEMENTED;
1099 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1101 nsChannel *This = NSCHANNEL_THIS(iface);
1103 FIXME("(%p)->(%p)\n", This, _retval);
1105 return NS_ERROR_NOT_IMPLEMENTED;
1108 #undef NSCHANNEL_THIS
1110 static const nsIHttpChannelVtbl nsChannelVtbl = {
1111 nsChannel_QueryInterface,
1115 nsChannel_IsPending,
1116 nsChannel_GetStatus,
1120 nsChannel_GetLoadGroup,
1121 nsChannel_SetLoadGroup,
1122 nsChannel_GetLoadFlags,
1123 nsChannel_SetLoadFlags,
1124 nsChannel_GetOriginalURI,
1125 nsChannel_SetOriginalURI,
1129 nsChannel_GetNotificationCallbacks,
1130 nsChannel_SetNotificationCallbacks,
1131 nsChannel_GetSecurityInfo,
1132 nsChannel_GetContentType,
1133 nsChannel_SetContentType,
1134 nsChannel_GetContentCharset,
1135 nsChannel_SetContentCharset,
1136 nsChannel_GetContentLength,
1137 nsChannel_SetContentLength,
1139 nsChannel_AsyncOpen,
1140 nsChannel_GetRequestMethod,
1141 nsChannel_SetRequestMethod,
1142 nsChannel_GetReferrer,
1143 nsChannel_SetReferrer,
1144 nsChannel_GetRequestHeader,
1145 nsChannel_SetRequestHeader,
1146 nsChannel_VisitRequestHeaders,
1147 nsChannel_GetAllowPipelining,
1148 nsChannel_SetAllowPipelining,
1149 nsChannel_GetRedirectionLimit,
1150 nsChannel_SetRedirectionLimit,
1151 nsChannel_GetResponseStatus,
1152 nsChannel_GetResponseStatusText,
1153 nsChannel_GetRequestSucceeded,
1154 nsChannel_GetResponseHeader,
1155 nsChannel_SetResponseHeader,
1156 nsChannel_VisitResponseHeaders,
1157 nsChannel_IsNoStoreResponse,
1158 nsChannel_IsNoCacheResponse
1161 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1163 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1166 nsChannel *This = NSUPCHANNEL_THIS(iface);
1167 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1170 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1172 nsChannel *This = NSUPCHANNEL_THIS(iface);
1173 return nsIChannel_AddRef(NSCHANNEL(This));
1176 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1178 nsChannel *This = NSUPCHANNEL_THIS(iface);
1179 return nsIChannel_Release(NSCHANNEL(This));
1182 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1183 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1185 nsChannel *This = NSUPCHANNEL_THIS(iface);
1186 const char *content_type;
1188 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1190 if(This->post_data_stream)
1191 nsIInputStream_Release(This->post_data_stream);
1194 nsACString_GetData(aContentType, &content_type);
1196 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1199 if(aContentLength != -1)
1200 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1202 if(This->post_data_stream)
1203 nsIInputStream_Release(This->post_data_stream);
1204 This->post_data_stream = aStream;
1206 nsIInputStream_AddRef(aStream);
1211 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1212 nsIInputStream **aUploadStream)
1214 nsChannel *This = NSUPCHANNEL_THIS(iface);
1216 TRACE("(%p)->(%p)\n", This, aUploadStream);
1218 if(This->post_data_stream)
1219 nsIInputStream_AddRef(This->post_data_stream);
1221 *aUploadStream = This->post_data_stream;
1225 #undef NSUPCHANNEL_THIS
1227 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1228 nsUploadChannel_QueryInterface,
1229 nsUploadChannel_AddRef,
1230 nsUploadChannel_Release,
1231 nsUploadChannel_SetUploadStream,
1232 nsUploadChannel_GetUploadStream
1235 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1237 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1240 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1241 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1244 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1246 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1247 return nsIChannel_AddRef(NSCHANNEL(This));
1250 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1252 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1253 return nsIChannel_Release(NSCHANNEL(This));
1256 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1258 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1260 FIXME("(%p)->()\n", This);
1262 return NS_ERROR_NOT_IMPLEMENTED;
1265 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1267 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1269 FIXME("(%p)->()\n", This);
1271 return NS_ERROR_NOT_IMPLEMENTED;
1274 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1276 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1278 FIXME("(%p)->()\n", This);
1280 return NS_ERROR_NOT_IMPLEMENTED;
1283 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1285 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1287 FIXME("(%p)->()\n", This);
1289 return NS_ERROR_NOT_IMPLEMENTED;
1292 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1294 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1296 FIXME("(%p)->()\n", This);
1298 return NS_ERROR_NOT_IMPLEMENTED;
1301 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1303 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1305 FIXME("(%p)->()\n", This);
1307 return NS_ERROR_NOT_IMPLEMENTED;
1310 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1312 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1314 FIXME("(%p)->()\n", This);
1316 return NS_ERROR_NOT_IMPLEMENTED;
1319 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1321 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1323 FIXME("(%p)->()\n", This);
1325 return NS_ERROR_NOT_IMPLEMENTED;
1328 #undef NSHTTPINTERNAL_THIS
1330 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1331 nsHttpChannelInternal_QueryInterface,
1332 nsHttpChannelInternal_AddRef,
1333 nsHttpChannelInternal_Release,
1334 nsHttpChannelInternal_GetDocumentURI,
1335 nsHttpChannelInternal_SetDocumentURI,
1336 nsHttpChannelInternal_GetRequestVersion,
1337 nsHttpChannelInternal_GetResponseVersion,
1338 nsHttpChannelInternal_SetCookie,
1339 nsHttpChannelInternal_SetupFallbackChannel,
1340 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1341 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1344 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1346 static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, nsQIResult result)
1348 nsWineURI *This = NSURI_THIS(iface);
1352 if(IsEqualGUID(&IID_nsISupports, riid)) {
1353 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1354 *result = NSURI(This);
1355 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1356 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1357 *result = NSURI(This);
1358 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1359 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1360 *result = NSURL(This);
1361 }else if(IsEqualGUID(&IID_nsWineURI, riid)) {
1362 TRACE("(%p)->(IID_nsWineURI %p)\n", This, result);
1367 nsIURI_AddRef(NSURI(This));
1371 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1372 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1375 static nsrefcnt NSAPI nsURI_AddRef(nsIURL *iface)
1377 nsWineURI *This = NSURI_THIS(iface);
1378 LONG ref = InterlockedIncrement(&This->ref);
1380 TRACE("(%p) ref=%d\n", This, ref);
1385 static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
1387 nsWineURI *This = NSURI_THIS(iface);
1388 LONG ref = InterlockedDecrement(&This->ref);
1390 TRACE("(%p) ref=%d\n", This, ref);
1393 if(This->window_ref)
1394 windowref_release(This->window_ref);
1396 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1398 nsIURL_Release(This->nsurl);
1400 nsIURI_Release(This->uri);
1401 heap_free(This->wine_url);
1408 static nsresult NSAPI nsURI_GetSpec(nsIURL *iface, nsACString *aSpec)
1410 nsWineURI *This = NSURI_THIS(iface);
1412 TRACE("(%p)->(%p)\n", This, aSpec);
1414 if(This->use_wine_url) {
1415 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1416 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1417 nsACString_SetData(aSpec, speca);
1423 return nsIURI_GetSpec(This->uri, aSpec);
1425 TRACE("returning error\n");
1426 return NS_ERROR_NOT_IMPLEMENTED;
1430 static nsresult NSAPI nsURI_SetSpec(nsIURL *iface, const nsACString *aSpec)
1432 nsWineURI *This = NSURI_THIS(iface);
1434 TRACE("(%p)->(%p)\n", This, aSpec);
1437 return nsIURI_SetSpec(This->uri, aSpec);
1439 FIXME("default action not implemented\n");
1440 return NS_ERROR_NOT_IMPLEMENTED;
1443 static nsresult NSAPI nsURI_GetPrePath(nsIURL *iface, nsACString *aPrePath)
1445 nsWineURI *This = NSURI_THIS(iface);
1447 TRACE("(%p)->(%p)\n", This, aPrePath);
1450 return nsIURI_GetPrePath(This->uri, aPrePath);
1452 FIXME("default action not implemented\n");
1453 return NS_ERROR_NOT_IMPLEMENTED;
1456 static nsresult NSAPI nsURI_GetScheme(nsIURL *iface, nsACString *aScheme)
1458 nsWineURI *This = NSURI_THIS(iface);
1460 TRACE("(%p)->(%p)\n", This, aScheme);
1462 if(This->use_wine_url) {
1464 * For Gecko we set scheme to unknown so it won't be handled
1465 * as any special case.
1467 nsACString_SetData(aScheme, "wine");
1472 return nsIURI_GetScheme(This->uri, aScheme);
1474 TRACE("returning error\n");
1475 return NS_ERROR_NOT_IMPLEMENTED;
1478 static nsresult NSAPI nsURI_SetScheme(nsIURL *iface, const nsACString *aScheme)
1480 nsWineURI *This = NSURI_THIS(iface);
1482 TRACE("(%p)->(%p)\n", This, aScheme);
1485 return nsIURI_SetScheme(This->uri, aScheme);
1487 FIXME("default action not implemented\n");
1488 return NS_ERROR_NOT_IMPLEMENTED;
1491 static nsresult NSAPI nsURI_GetUserPass(nsIURL *iface, nsACString *aUserPass)
1493 nsWineURI *This = NSURI_THIS(iface);
1495 TRACE("(%p)->(%p)\n", This, aUserPass);
1498 return nsIURI_GetUserPass(This->uri, aUserPass);
1500 FIXME("default action not implemented\n");
1501 return NS_ERROR_NOT_IMPLEMENTED;
1504 static nsresult NSAPI nsURI_SetUserPass(nsIURL *iface, const nsACString *aUserPass)
1506 nsWineURI *This = NSURI_THIS(iface);
1508 TRACE("(%p)->(%p)\n", This, aUserPass);
1511 return nsIURI_SetUserPass(This->uri, aUserPass);
1513 FIXME("default action not implemented\n");
1514 return NS_ERROR_NOT_IMPLEMENTED;
1517 static nsresult NSAPI nsURI_GetUsername(nsIURL *iface, nsACString *aUsername)
1519 nsWineURI *This = NSURI_THIS(iface);
1521 TRACE("(%p)->(%p)\n", This, aUsername);
1524 return nsIURI_GetUsername(This->uri, aUsername);
1526 FIXME("default action not implemented\n");
1527 return NS_ERROR_NOT_IMPLEMENTED;
1530 static nsresult NSAPI nsURI_SetUsername(nsIURL *iface, const nsACString *aUsername)
1532 nsWineURI *This = NSURI_THIS(iface);
1534 TRACE("(%p)->(%p)\n", This, aUsername);
1537 return nsIURI_SetUsername(This->uri, aUsername);
1539 FIXME("default action not implemented\n");
1540 return NS_ERROR_NOT_IMPLEMENTED;
1543 static nsresult NSAPI nsURI_GetPassword(nsIURL *iface, nsACString *aPassword)
1545 nsWineURI *This = NSURI_THIS(iface);
1547 TRACE("(%p)->(%p)\n", This, aPassword);
1550 return nsIURI_GetPassword(This->uri, aPassword);
1552 FIXME("default action not implemented\n");
1553 return NS_ERROR_NOT_IMPLEMENTED;
1556 static nsresult NSAPI nsURI_SetPassword(nsIURL *iface, const nsACString *aPassword)
1558 nsWineURI *This = NSURI_THIS(iface);
1560 TRACE("(%p)->(%p)\n", This, aPassword);
1563 return nsIURI_SetPassword(This->uri, aPassword);
1565 FIXME("default action not implemented\n");
1566 return NS_ERROR_NOT_IMPLEMENTED;
1569 static nsresult NSAPI nsURI_GetHostPort(nsIURL *iface, nsACString *aHostPort)
1571 nsWineURI *This = NSURI_THIS(iface);
1573 TRACE("(%p)->(%p)\n", This, aHostPort);
1576 return nsIURI_GetHostPort(This->uri, aHostPort);
1578 FIXME("default action not implemented\n");
1579 return NS_ERROR_NOT_IMPLEMENTED;
1582 static nsresult NSAPI nsURI_SetHostPort(nsIURL *iface, const nsACString *aHostPort)
1584 nsWineURI *This = NSURI_THIS(iface);
1586 TRACE("(%p)->(%p)\n", This, aHostPort);
1589 return nsIURI_SetHostPort(This->uri, aHostPort);
1591 FIXME("default action not implemented\n");
1592 return NS_ERROR_NOT_IMPLEMENTED;
1595 static nsresult NSAPI nsURI_GetHost(nsIURL *iface, nsACString *aHost)
1597 nsWineURI *This = NSURI_THIS(iface);
1599 TRACE("(%p)->(%p)\n", This, aHost);
1602 return nsIURI_GetHost(This->uri, aHost);
1604 FIXME("default action not implemented\n");
1605 return NS_ERROR_NOT_IMPLEMENTED;
1608 static nsresult NSAPI nsURI_SetHost(nsIURL *iface, const nsACString *aHost)
1610 nsWineURI *This = NSURI_THIS(iface);
1612 TRACE("(%p)->(%p)\n", This, aHost);
1615 return nsIURI_SetHost(This->uri, aHost);
1617 FIXME("default action not implemented\n");
1618 return NS_ERROR_NOT_IMPLEMENTED;
1621 static nsresult NSAPI nsURI_GetPort(nsIURL *iface, PRInt32 *aPort)
1623 nsWineURI *This = NSURI_THIS(iface);
1625 TRACE("(%p)->(%p)\n", This, aPort);
1628 return nsIURI_GetPort(This->uri, aPort);
1630 FIXME("default action not implemented\n");
1631 return NS_ERROR_NOT_IMPLEMENTED;
1634 static nsresult NSAPI nsURI_SetPort(nsIURL *iface, PRInt32 aPort)
1636 nsWineURI *This = NSURI_THIS(iface);
1638 TRACE("(%p)->(%d)\n", This, aPort);
1641 return nsIURI_SetPort(This->uri, aPort);
1643 FIXME("default action not implemented\n");
1644 return NS_ERROR_NOT_IMPLEMENTED;
1647 static nsresult NSAPI nsURI_GetPath(nsIURL *iface, nsACString *aPath)
1649 nsWineURI *This = NSURI_THIS(iface);
1651 TRACE("(%p)->(%p)\n", This, aPath);
1654 return nsIURI_GetPath(This->uri, aPath);
1656 FIXME("default action not implemented\n");
1657 return NS_ERROR_NOT_IMPLEMENTED;
1660 static nsresult NSAPI nsURI_SetPath(nsIURL *iface, const nsACString *aPath)
1662 nsWineURI *This = NSURI_THIS(iface);
1665 nsACString_GetData(aPath, &path);
1666 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1669 if(This->wine_url) {
1670 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1671 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1675 pathw = heap_strdupAtoW(path);
1676 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1679 set_wine_url(This, new_url);
1681 WARN("UrlCombine failed: %08x\n", hres);
1687 return nsIURI_SetPath(This->uri, aPath);
1690 static nsresult NSAPI nsURI_Equals(nsIURL *iface, nsIURI *other, PRBool *_retval)
1692 nsWineURI *This = NSURI_THIS(iface);
1693 nsWineURI *wine_uri;
1696 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1699 return nsIURI_Equals(This->uri, other, _retval);
1701 nsres = nsIURI_QueryInterface(other, &IID_nsWineURI, (void**)&wine_uri);
1702 if(NS_FAILED(nsres)) {
1703 TRACE("Could not get nsWineURI interface\n");
1708 *_retval = wine_uri->wine_url && !UrlCompareW(This->wine_url, wine_uri->wine_url, TRUE);
1709 nsIURI_Release(NSURI(wine_uri));
1714 static nsresult NSAPI nsURI_SchemeIs(nsIURL *iface, const char *scheme, PRBool *_retval)
1716 nsWineURI *This = NSURI_THIS(iface);
1718 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1720 if(This->use_wine_url) {
1721 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1722 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1724 *_retval = lstrlenW(This->wine_url) > len
1725 && This->wine_url[len] == ':'
1726 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1731 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1733 TRACE("returning error\n");
1734 return NS_ERROR_NOT_IMPLEMENTED;
1737 static nsresult NSAPI nsURI_Clone(nsIURL *iface, nsIURI **_retval)
1739 nsWineURI *This = NSURI_THIS(iface);
1740 nsIURI *nsuri = NULL;
1741 nsWineURI *wine_uri;
1744 TRACE("(%p)->(%p)\n", This, _retval);
1747 nsres = nsIURI_Clone(This->uri, &nsuri);
1748 if(NS_FAILED(nsres)) {
1749 WARN("Clone failed: %08x\n", nsres);
1754 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1755 if(NS_FAILED(nsres)) {
1756 WARN("create_uri failed: %08x\n", nsres);
1760 set_wine_url(wine_uri, This->wine_url);
1762 *_retval = NSURI(wine_uri);
1766 static nsresult NSAPI nsURI_Resolve(nsIURL *iface, const nsACString *arelativePath,
1767 nsACString *_retval)
1769 nsWineURI *This = NSURI_THIS(iface);
1771 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1774 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1776 FIXME("default action not implemented\n");
1777 return NS_ERROR_NOT_IMPLEMENTED;
1780 static nsresult NSAPI nsURI_GetAsciiSpec(nsIURL *iface, nsACString *aAsciiSpec)
1782 nsWineURI *This = NSURI_THIS(iface);
1784 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1786 if(This->use_wine_url)
1787 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1790 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1792 TRACE("returning error\n");
1793 return NS_ERROR_NOT_IMPLEMENTED;
1796 static nsresult NSAPI nsURI_GetAsciiHost(nsIURL *iface, nsACString *aAsciiHost)
1798 nsWineURI *This = NSURI_THIS(iface);
1800 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1803 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1805 FIXME("default action not implemented\n");
1806 return NS_ERROR_NOT_IMPLEMENTED;
1809 static nsresult NSAPI nsURI_GetOriginCharset(nsIURL *iface, nsACString *aOriginCharset)
1811 nsWineURI *This = NSURI_THIS(iface);
1813 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1816 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1818 FIXME("default action not implemented\n");
1819 return NS_ERROR_NOT_IMPLEMENTED;
1822 static nsresult NSAPI nsURL_GetFilePath(nsIURL *iface, nsACString *aFilePath)
1824 nsWineURI *This = NSURI_THIS(iface);
1826 TRACE("(%p)->(%p)\n", This, aFilePath);
1829 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1831 FIXME("default action not implemented\n");
1832 return NS_ERROR_NOT_IMPLEMENTED;
1835 static nsresult NSAPI nsURL_SetFilePath(nsIURL *iface, const nsACString *aFilePath)
1837 nsWineURI *This = NSURI_THIS(iface);
1839 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1842 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1844 FIXME("default action not implemented\n");
1845 return NS_ERROR_NOT_IMPLEMENTED;
1848 static nsresult NSAPI nsURL_GetParam(nsIURL *iface, nsACString *aParam)
1850 nsWineURI *This = NSURI_THIS(iface);
1852 TRACE("(%p)->(%p)\n", This, aParam);
1855 return nsIURL_GetParam(This->nsurl, aParam);
1857 FIXME("default action not implemented\n");
1858 return NS_ERROR_NOT_IMPLEMENTED;
1861 static nsresult NSAPI nsURL_SetParam(nsIURL *iface, const nsACString *aParam)
1863 nsWineURI *This = NSURI_THIS(iface);
1865 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1868 return nsIURL_SetParam(This->nsurl, aParam);
1870 FIXME("default action not implemented\n");
1871 return NS_ERROR_NOT_IMPLEMENTED;
1874 static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
1876 nsWineURI *This = NSURI_THIS(iface);
1878 TRACE("(%p)->(%p)\n", This, aQuery);
1881 return nsIURL_GetQuery(This->nsurl, aQuery);
1883 FIXME("default action not implemented\n");
1884 return NS_ERROR_NOT_IMPLEMENTED;
1887 static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
1889 nsWineURI *This = NSURI_THIS(iface);
1890 const WCHAR *ptr1, *ptr2;
1892 WCHAR *new_url, *ptr;
1895 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1898 nsIURL_SetQuery(This->nsurl, aQuery);
1903 nsACString_GetData(aQuery, &query);
1904 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1905 ptr1 = strchrW(This->wine_url, '?');
1907 size += ptr1-This->wine_url;
1908 ptr2 = strchrW(ptr1, '#');
1910 size += strlenW(ptr2);
1912 ptr1 = This->wine_url + strlenW(This->wine_url);
1914 size += strlenW(This->wine_url);
1920 new_url = heap_alloc(size*sizeof(WCHAR));
1921 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1922 ptr = new_url + (ptr1-This->wine_url);
1925 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1933 TRACE("setting %s\n", debugstr_w(new_url));
1935 heap_free(This->wine_url);
1936 This->wine_url = new_url;
1940 static nsresult NSAPI nsURL_GetRef(nsIURL *iface, nsACString *aRef)
1942 nsWineURI *This = NSURI_THIS(iface);
1944 TRACE("(%p)->(%p)\n", This, aRef);
1947 return nsIURL_GetRef(This->nsurl, aRef);
1949 FIXME("default action not implemented\n");
1950 return NS_ERROR_NOT_IMPLEMENTED;
1953 static nsresult NSAPI nsURL_SetRef(nsIURL *iface, const nsACString *aRef)
1955 nsWineURI *This = NSURI_THIS(iface);
1958 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1961 return nsIURL_SetRef(This->nsurl, aRef);
1963 nsACString_GetData(aRef, &refa);
1967 FIXME("default action not implemented\n");
1968 return NS_ERROR_NOT_IMPLEMENTED;
1971 static nsresult NSAPI nsURL_GetDirectory(nsIURL *iface, nsACString *aDirectory)
1973 nsWineURI *This = NSURI_THIS(iface);
1975 TRACE("(%p)->(%p)\n", This, aDirectory);
1978 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1980 FIXME("default action not implemented\n");
1981 return NS_ERROR_NOT_IMPLEMENTED;
1984 static nsresult NSAPI nsURL_SetDirectory(nsIURL *iface, const nsACString *aDirectory)
1986 nsWineURI *This = NSURI_THIS(iface);
1988 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
1991 return nsIURL_SetDirectory(This->nsurl, aDirectory);
1993 FIXME("default action not implemented\n");
1994 return NS_ERROR_NOT_IMPLEMENTED;
1997 static nsresult NSAPI nsURL_GetFileName(nsIURL *iface, nsACString *aFileName)
1999 nsWineURI *This = NSURI_THIS(iface);
2001 TRACE("(%p)->(%p)\n", This, aFileName);
2004 return nsIURL_GetFileName(This->nsurl, aFileName);
2006 FIXME("default action not implemented\n");
2007 return NS_ERROR_NOT_IMPLEMENTED;
2010 static nsresult NSAPI nsURL_SetFileName(nsIURL *iface, const nsACString *aFileName)
2012 nsWineURI *This = NSURI_THIS(iface);
2014 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
2017 return nsIURL_SetFileName(This->nsurl, aFileName);
2019 FIXME("default action not implemented\n");
2020 return NS_ERROR_NOT_IMPLEMENTED;
2023 static nsresult NSAPI nsURL_GetFileBaseName(nsIURL *iface, nsACString *aFileBaseName)
2025 nsWineURI *This = NSURI_THIS(iface);
2027 TRACE("(%p)->(%p)\n", This, aFileBaseName);
2030 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
2032 FIXME("default action not implemented\n");
2033 return NS_ERROR_NOT_IMPLEMENTED;
2036 static nsresult NSAPI nsURL_SetFileBaseName(nsIURL *iface, const nsACString *aFileBaseName)
2038 nsWineURI *This = NSURI_THIS(iface);
2040 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2043 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2045 FIXME("default action not implemented\n");
2046 return NS_ERROR_NOT_IMPLEMENTED;
2049 static nsresult NSAPI nsURL_GetFileExtension(nsIURL *iface, nsACString *aFileExtension)
2051 nsWineURI *This = NSURI_THIS(iface);
2053 TRACE("(%p)->(%p)\n", This, aFileExtension);
2056 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2058 FIXME("default action not implemented\n");
2059 return NS_ERROR_NOT_IMPLEMENTED;
2062 static nsresult NSAPI nsURL_SetFileExtension(nsIURL *iface, const nsACString *aFileExtension)
2064 nsWineURI *This = NSURI_THIS(iface);
2066 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2069 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2071 FIXME("default action not implemented\n");
2072 return NS_ERROR_NOT_IMPLEMENTED;
2075 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2077 nsWineURI *This = NSURI_THIS(iface);
2079 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2082 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2084 FIXME("default action not implemented\n");
2085 return NS_ERROR_NOT_IMPLEMENTED;
2088 static nsresult NSAPI nsURL_GetRelativeSpec(nsIURL *iface, nsIURI *aURIToCompare, nsACString *_retval)
2090 nsWineURI *This = NSURI_THIS(iface);
2092 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2095 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2097 FIXME("default action not implemented\n");
2098 return NS_ERROR_NOT_IMPLEMENTED;
2103 static const nsIURLVtbl nsURLVtbl = {
2104 nsURI_QueryInterface,
2132 nsURI_GetOriginCharset,
2145 nsURL_GetFileBaseName,
2146 nsURL_SetFileBaseName,
2147 nsURL_GetFileExtension,
2148 nsURL_SetFileExtension,
2149 nsURL_GetCommonBaseSpec,
2150 nsURL_GetRelativeSpec
2153 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsWineURI **_retval)
2155 nsWineURI *ret = heap_alloc_zero(sizeof(nsWineURI));
2157 ret->lpIURLVtbl = &nsURLVtbl;
2161 set_uri_nscontainer(ret, container);
2162 set_uri_window(ret, window);
2165 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2167 TRACE("retval=%p\n", ret);
2172 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsWineURI **ret)
2177 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2178 if(NS_FAILED(nsres))
2181 set_wine_url(uri, url);
2182 uri->is_doc_uri = TRUE;
2189 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2193 nsIProtocolHandler *nshandler;
2194 } nsProtocolHandler;
2196 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2198 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2200 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2203 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2207 if(IsEqualGUID(&IID_nsISupports, riid)) {
2208 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2209 *result = NSPROTHANDLER(This);
2210 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2211 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2212 *result = NSPROTHANDLER(This);
2213 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2214 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2215 return NS_NOINTERFACE;
2219 nsISupports_AddRef((nsISupports*)*result);
2223 WARN("(%s %p)\n", debugstr_guid(riid), result);
2224 return NS_NOINTERFACE;
2227 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2229 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2230 LONG ref = InterlockedIncrement(&This->ref);
2232 TRACE("(%p) ref=%d\n", This, ref);
2237 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2239 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2240 LONG ref = InterlockedDecrement(&This->ref);
2242 TRACE("(%p) ref=%d\n", This, ref);
2246 nsIProtocolHandler_Release(This->nshandler);
2253 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2255 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2257 TRACE("(%p)->(%p)\n", This, aScheme);
2260 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2261 return NS_ERROR_NOT_IMPLEMENTED;
2264 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2265 PRInt32 *aDefaultPort)
2267 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2269 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2272 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2273 return NS_ERROR_NOT_IMPLEMENTED;
2276 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2277 PRUint32 *aProtocolFlags)
2279 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2281 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2284 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2285 return NS_ERROR_NOT_IMPLEMENTED;
2288 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2289 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2291 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2293 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2296 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2297 return NS_ERROR_NOT_IMPLEMENTED;
2300 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2301 nsIURI *aURI, nsIChannel **_retval)
2303 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2305 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2308 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2309 return NS_ERROR_NOT_IMPLEMENTED;
2312 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2313 PRInt32 port, const char *scheme, PRBool *_retval)
2315 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2317 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2320 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2321 return NS_ERROR_NOT_IMPLEMENTED;
2324 #undef NSPROTHANDLER_THIS
2326 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2327 nsProtocolHandler_QueryInterface,
2328 nsProtocolHandler_AddRef,
2329 nsProtocolHandler_Release,
2330 nsProtocolHandler_GetScheme,
2331 nsProtocolHandler_GetDefaultPort,
2332 nsProtocolHandler_GetProtocolFlags,
2333 nsProtocolHandler_NewURI,
2334 nsProtocolHandler_NewChannel,
2335 nsProtocolHandler_AllowPort
2338 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2340 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2342 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2344 ret->nshandler = nshandler;
2346 return NSPROTHANDLER(ret);
2349 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2351 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2356 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2361 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2362 nsIProtocolHandler **_retval)
2364 nsIExternalProtocolHandler *nsexthandler;
2365 nsIProtocolHandler *nshandler;
2368 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2370 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2371 if(NS_FAILED(nsres)) {
2372 WARN("GetProtocolHandler failed: %08x\n", nsres);
2376 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2377 (void**)&nsexthandler);
2378 if(NS_FAILED(nsres)) {
2379 *_retval = nshandler;
2383 nsIExternalProtocolHandler_Release(nsexthandler);
2384 *_retval = create_protocol_handler(nshandler);
2385 TRACE("return %p\n", *_retval);
2389 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2392 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2393 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2396 static BOOL is_gecko_special_uri(const char *spec)
2398 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2401 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2402 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2409 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2410 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2412 nsWineURI *wine_uri, *base_wine_uri = NULL;
2413 const char *spec = NULL;
2414 HTMLWindow *window = NULL;
2416 LPCWSTR base_wine_url = NULL;
2417 BOOL is_wine_uri = FALSE;
2420 nsACString_GetData(aSpec, &spec);
2422 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2425 if(is_gecko_special_uri(spec))
2426 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2428 if(!strncmp(spec, "wine:", 5)) {
2434 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2436 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsWineURI, (void**)&base_wine_uri);
2437 if(NS_SUCCEEDED(nsres)) {
2438 base_wine_url = base_wine_uri->wine_url;
2439 if(base_wine_uri->window_ref && base_wine_uri->window_ref->window) {
2440 window = base_wine_uri->window_ref->window;
2441 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2443 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2444 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2445 TRACE("not wraping\n");
2446 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2448 WARN("Could not get base nsWineURI: %08x\n", nsres);
2452 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2453 if(NS_FAILED(nsres))
2454 TRACE("NewURI failed: %08x\n", nsres);
2456 nsres = create_uri(uri, window, NULL, &wine_uri);
2457 *_retval = (nsIURI*)wine_uri;
2460 IHTMLWindow2_Release(HTMLWINDOW2(window));
2463 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2467 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2469 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2470 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2471 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2473 set_wine_url(wine_uri, url);
2475 WARN("CoCombineUrl failed: %08x\n", hres);
2476 }else if(is_wine_uri) {
2477 WCHAR url[INTERNET_MAX_URL_LENGTH];
2479 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2480 set_wine_url(wine_uri, url);
2484 nsIURI_Release(NSURI(base_wine_uri));
2489 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2492 TRACE("(%p %p)\n", aFile, _retval);
2493 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2496 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2497 nsIChannel **_retval)
2499 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2501 nsWineURI *wine_uri;
2504 TRACE("(%p %p)\n", aURI, _retval);
2506 nsres = nsIURI_QueryInterface(aURI, &IID_nsWineURI, (void**)&wine_uri);
2507 if(NS_FAILED(nsres)) {
2508 TRACE("Could not get nsWineURI: %08x\n", nsres);
2509 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2512 ret = heap_alloc_zero(sizeof(nsChannel));
2514 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2515 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2516 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2518 ret->uri = wine_uri;
2520 nsIURI_AddRef(aURI);
2521 ret->original_uri = aURI;
2522 ret->url_scheme = wine_uri->wine_url && SUCCEEDED(ParseURLW(wine_uri->wine_url, &parsed_url))
2523 ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2525 *_retval = NSCHANNEL(ret);
2529 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2530 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2532 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2533 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2536 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2538 TRACE("(%p)\n", aOffline);
2539 return nsIIOService_GetOffline(nsio, aOffline);
2542 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2544 TRACE("(%x)\n", aOffline);
2545 return nsIIOService_SetOffline(nsio, aOffline);
2548 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2549 const char *aScheme, PRBool *_retval)
2551 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2552 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2555 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2556 nsACString * _retval)
2558 TRACE("(%p %p)\n", urlString, _retval);
2559 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2562 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2563 nsIOService_QueryInterface,
2565 nsIOService_Release,
2566 nsIOService_GetProtocolHandler,
2567 nsIOService_GetProtocolFlags,
2569 nsIOService_NewFileURI,
2570 nsIOService_NewChannelFromURI,
2571 nsIOService_NewChannel,
2572 nsIOService_GetOffline,
2573 nsIOService_SetOffline,
2574 nsIOService_AllowPort,
2575 nsIOService_ExtractScheme
2578 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2580 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2583 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2586 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2591 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2596 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2597 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2599 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2601 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2604 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2608 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2611 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2613 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2615 if(aFlags == (1<<11)) {
2620 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2623 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2625 TRACE("(%p %p)\n", aURI, _retval);
2627 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2630 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2631 PRUint32 aEscapeType, nsACString *_retval)
2633 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2635 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2638 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2639 nsACString *_retval)
2641 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2643 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2646 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2647 PRUint32 aFlags, nsACString *_retval)
2649 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2651 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2654 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2655 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2657 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2659 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2662 static const nsINetUtilVtbl nsNetUtilVtbl = {
2663 nsNetUtil_QueryInterface,
2666 nsNetUtil_ParseContentType,
2667 nsNetUtil_ProtocolHasFlags,
2668 nsNetUtil_URIChainHasFlags,
2669 nsNetUtil_ToImmutableURI,
2670 nsNetUtil_EscapeString,
2671 nsNetUtil_EscapeURL,
2672 nsNetUtil_UnescapeString,
2673 nsNetUtil_ExtractCharsetFromContentType
2676 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2678 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2683 if(IsEqualGUID(&IID_nsISupports, riid))
2684 *result = &nsIOService;
2685 else if(IsEqualGUID(&IID_nsIIOService, riid))
2686 *result = &nsIOService;
2687 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2688 *result = &nsNetUtil;
2691 nsISupports_AddRef((nsISupports*)*result);
2695 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2696 return NS_NOINTERFACE;
2699 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2704 if(IsEqualGUID(&IID_nsISupports, riid)) {
2705 TRACE("(IID_nsISupports %p)\n", result);
2707 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2708 TRACE("(IID_nsIFactory %p)\n", result);
2713 nsIFactory_AddRef(iface);
2717 WARN("(%s %p)\n", debugstr_guid(riid), result);
2718 return NS_NOINTERFACE;
2721 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2726 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2731 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2732 nsISupports *aOuter, const nsIID *iid, void **result)
2734 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2737 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2739 WARN("(%x)\n", lock);
2743 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2744 nsIOServiceFactory_QueryInterface,
2745 nsIOServiceFactory_AddRef,
2746 nsIOServiceFactory_Release,
2747 nsIOServiceFactory_CreateInstance,
2748 nsIOServiceFactory_LockFactory
2751 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2753 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2755 nsIFactory *old_factory = NULL;
2758 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2759 &IID_nsIFactory, (void**)&old_factory);
2760 if(NS_FAILED(nsres)) {
2761 ERR("Could not get factory: %08x\n", nsres);
2765 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2766 if(NS_FAILED(nsres)) {
2767 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2768 nsIFactory_Release(old_factory);
2772 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2773 if(NS_FAILED(nsres)) {
2774 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2775 nsIIOService_Release(nsio);
2779 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2780 nsIFactory_Release(old_factory);
2781 if(NS_FAILED(nsres))
2782 ERR("UnregisterFactory failed: %08x\n", nsres);
2784 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2785 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2786 if(NS_FAILED(nsres))
2787 ERR("RegisterFactory failed: %08x\n", nsres);
2790 void release_nsio(void)
2793 nsINetUtil_Release(net_util);
2798 nsIIOService_Release(nsio);