mshtml: Added more Exec tests and fixes.
[wine] / dlls / mshtml / nsio.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "shlguid.h"
30
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "mshtml_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 #define LOAD_INITIAL_DOCUMENT_URI 0x80000
39
40 #define NS_IOSERVICE_CLASSNAME "nsIOService"
41 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
42
43 static const IID NS_IOSERVICE_CID =
44     {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
45
46 static nsIIOService *nsio = NULL;
47
48 typedef struct {
49     const nsIWineURIVtbl *lpWineURIVtbl;
50
51     LONG ref;
52
53     nsIURI *uri;
54     NSContainer *container;
55     IMoniker *mon;
56     LPSTR spec;
57 } nsURI;
58
59 #define NSURI(x)         ((nsIURI*)            &(x)->lpWineURIVtbl)
60
61 static nsresult create_uri(nsIURI*,NSContainer*,nsIURI**);
62
63 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
64 {
65     IOleCommandTarget *cmdtrg = NULL;
66     HRESULT hres;
67
68     hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
69                                          (void**)&cmdtrg);
70     if(SUCCEEDED(hres)) {
71         VARIANT varUrl, varRes;
72
73         V_VT(&varUrl) = VT_BSTR;
74         V_BSTR(&varUrl) = SysAllocString(url);
75         V_VT(&varRes) = VT_BOOL;
76
77         hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
78
79         IOleCommandTarget_Release(cmdtrg);
80         SysFreeString(V_BSTR(&varUrl));
81
82         if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
83             TRACE("got VARIANT_FALSE, do not load\n");
84             return FALSE;
85         }
86     }
87
88     return TRUE;
89 }
90
91 static BOOL handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
92 {
93     IServiceProvider *service_provider;
94     HTMLDocument *doc = container->doc;
95     DWORD hlnf = 0;
96     HRESULT hres;
97
98     if(!doc) {
99         NSContainer *container_iter = container;
100
101         hlnf = HLNF_OPENINNEWWINDOW;
102         while(!container_iter->doc)
103             container_iter = container_iter->parent;
104         doc = container_iter->doc;
105     }
106
107     if(!hlnf && !exec_shldocvw_67(doc, uri))
108         return FALSE;
109
110     hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
111                                          (void**)&service_provider);
112     if(SUCCEEDED(hres)) {
113         IHlinkFrame *hlink_frame;
114
115         hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
116                                              &IID_IHlinkFrame, (void**)&hlink_frame);
117         IServiceProvider_Release(service_provider);
118         if(SUCCEEDED(hres)) {
119             hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
120             IHlinkFrame_Release(hlink_frame);
121
122             return FALSE;
123         }
124     }
125
126     return TRUE;
127 }
128
129 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
130 {
131     nsACString uri_str;
132     const char *uria;
133     LPWSTR uri;
134     DWORD len;
135     BOOL ret;
136
137     nsACString_Init(&uri_str, NULL);
138     nsIWineURI_GetSpec(channel->uri, &uri_str);
139     nsACString_GetData(&uri_str, &uria, NULL);
140     len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
141     uri = mshtml_alloc(len*sizeof(WCHAR));
142     MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
143     nsACString_Finish(&uri_str);
144
145     ret = handle_uri(container, channel, uri);
146
147     mshtml_free(uri);
148
149     return ret;
150 }
151
152 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
153
154 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
155 {
156     nsChannel *This = NSCHANNEL_THIS(iface);
157
158     *result = NULL;
159
160     if(IsEqualGUID(&IID_nsISupports, riid)) {
161         TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
162         *result = NSCHANNEL(This);
163     }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
164         TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
165         *result = NSCHANNEL(This);
166     }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
167         TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
168         *result = NSCHANNEL(This);
169     }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
170         TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
171         *result = NSHTTPCHANNEL(This);
172     }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
173         TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
174         *result = NSUPCHANNEL(This);
175     }
176
177     if(*result) {
178         nsIChannel_AddRef(NSCHANNEL(This));
179         return NS_OK;
180     }
181
182     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
183
184     if(This->channel)
185         return nsIChannel_QueryInterface(This->channel, riid, result);
186     return NS_NOINTERFACE;
187 }
188
189 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
190 {
191     nsChannel *This = NSCHANNEL_THIS(iface);
192     nsrefcnt ref = InterlockedIncrement(&This->ref);
193
194     TRACE("(%p) ref=%ld\n", This, ref);
195
196     return ref;
197 }
198
199 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
200 {
201     nsChannel *This = NSCHANNEL_THIS(iface);
202     LONG ref = InterlockedDecrement(&This->ref);
203
204     if(!ref) {
205         nsIWineURI_Release(This->uri);
206         if(This->channel)
207             nsIChannel_Release(This->channel);
208         if(This->http_channel)
209             nsIHttpChannel_Release(This->http_channel);
210         if(This->post_data_stream)
211             nsIInputStream_Release(This->post_data_stream);
212         if(This->load_group)
213             nsILoadGroup_Release(This->load_group);
214         if(This->notif_callback)
215             nsIInterfaceRequestor_Release(This->notif_callback);
216         if(This->original_uri)
217             nsIURI_Release(This->original_uri);
218         mshtml_free(This->content);
219         mshtml_free(This);
220     }
221
222     return ref;
223 }
224
225 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
226 {
227     nsChannel *This = NSCHANNEL_THIS(iface);
228
229     TRACE("(%p)->(%p)\n", This, aName);
230
231     if(This->channel)
232         return nsIChannel_GetName(This->channel, aName);
233
234     FIXME("default action not implemented\n");
235     return NS_ERROR_NOT_IMPLEMENTED;
236 }
237
238 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
239 {
240     nsChannel *This = NSCHANNEL_THIS(iface);
241
242     TRACE("(%p)->(%p)\n", This, _retval);
243
244     if(This->channel)
245         return nsIChannel_IsPending(This->channel, _retval);
246
247     FIXME("default action not implemented\n");
248     return NS_ERROR_NOT_IMPLEMENTED;
249 }
250
251 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
252 {
253     nsChannel *This = NSCHANNEL_THIS(iface);
254
255     TRACE("(%p)->(%p)\n", This, aStatus);
256
257     if(This->channel)
258         return nsIChannel_GetStatus(This->channel, aStatus);
259
260     TRACE("returning NS_OK\n");
261     return *aStatus = NS_OK;
262 }
263
264 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
265 {
266     nsChannel *This = NSCHANNEL_THIS(iface);
267
268     TRACE("(%p)->(%08lx)\n", This, aStatus);
269
270     if(This->channel)
271         return nsIChannel_Cancel(This->channel, aStatus);
272
273     FIXME("default action not implemented\n");
274     return NS_ERROR_NOT_IMPLEMENTED;
275 }
276
277 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
278 {
279     nsChannel *This = NSCHANNEL_THIS(iface);
280
281     TRACE("(%p)\n", This);
282
283     if(This->channel)
284         return nsIChannel_Suspend(This->channel);
285
286     FIXME("default action not implemented\n");
287     return NS_ERROR_NOT_IMPLEMENTED;
288 }
289
290 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
291 {
292     nsChannel *This = NSCHANNEL_THIS(iface);
293
294     TRACE("(%p)\n", This);
295
296     if(This->channel)
297         return nsIChannel_Resume(This->channel);
298
299     FIXME("default action not implemented\n");
300     return NS_ERROR_NOT_IMPLEMENTED;
301 }
302
303 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
304 {
305     nsChannel *This = NSCHANNEL_THIS(iface);
306
307     TRACE("(%p)->(%p)\n", This, aLoadGroup);
308
309     if(This->load_group)
310         nsILoadGroup_AddRef(This->load_group);
311
312     *aLoadGroup = This->load_group;
313     return NS_OK;
314 }
315
316 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
317 {
318     nsChannel *This = NSCHANNEL_THIS(iface);
319
320     TRACE("(%p)->(%p)\n", This, aLoadGroup);
321
322     if(This->load_group)
323         nsILoadGroup_Release(This->load_group);
324     if(aLoadGroup)
325         nsILoadGroup_AddRef(aLoadGroup);
326
327     This->load_group = aLoadGroup;
328
329     if(This->channel)
330         return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
331     return NS_OK;
332 }
333
334 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
335 {
336     nsChannel *This = NSCHANNEL_THIS(iface);
337
338     TRACE("(%p)->(%p)\n", This, aLoadFlags);
339
340     *aLoadFlags = This->load_flags;
341     return NS_OK;
342 }
343
344 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
345 {
346     nsChannel *This = NSCHANNEL_THIS(iface);
347
348     TRACE("(%p)->(%08lx)\n", This, aLoadFlags);
349
350     This->load_flags = aLoadFlags;
351
352     if(This->channel)
353         return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
354     return NS_OK;
355 }
356
357 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
358 {
359     nsChannel *This = NSCHANNEL_THIS(iface);
360
361     TRACE("(%p)->(%p)\n", This, aOriginalURI);
362
363     if(This->original_uri)
364         nsIURI_AddRef(This->original_uri);
365
366     *aOriginalURI = This->original_uri;
367     return NS_OK;
368 }
369
370 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
371 {
372     nsChannel *This = NSCHANNEL_THIS(iface);
373
374     TRACE("(%p)->(%p)\n", This, aOriginalURI);
375
376     if(This->original_uri)
377         nsIURI_Release(This->original_uri);
378
379     nsIURI_AddRef(aOriginalURI);
380     This->original_uri = aOriginalURI;
381
382     if(This->channel)
383         return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
384     return NS_OK;
385 }
386
387 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
388 {
389     nsChannel *This = NSCHANNEL_THIS(iface);
390
391     TRACE("(%p)->(%p)\n", This, aURI);
392
393     nsIWineURI_AddRef(This->uri);
394     *aURI = (nsIURI*)This->uri;
395
396     return NS_OK;
397 }
398
399 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
400 {
401     nsChannel *This = NSCHANNEL_THIS(iface);
402
403     TRACE("(%p)->(%p)\n", This, aOwner);
404
405     if(This->channel)
406         return nsIChannel_GetOwner(This->channel, aOwner);
407
408     FIXME("default action not implemented\n");
409     return NS_ERROR_NOT_IMPLEMENTED;
410 }
411
412 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
413 {
414     nsChannel *This = NSCHANNEL_THIS(iface);
415
416     TRACE("(%p)->(%p)\n", This, aOwner);
417
418     if(This->channel)
419         return nsIChannel_SetOwner(This->channel, aOwner);
420
421     FIXME("default action not implemented\n");
422     return NS_ERROR_NOT_IMPLEMENTED;
423 }
424
425 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
426         nsIInterfaceRequestor **aNotificationCallbacks)
427 {
428     nsChannel *This = NSCHANNEL_THIS(iface);
429
430     TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
431
432     if(This->notif_callback)
433         nsIInterfaceRequestor_AddRef(This->notif_callback);
434     *aNotificationCallbacks = This->notif_callback;
435
436     return NS_OK;
437 }
438
439 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
440         nsIInterfaceRequestor *aNotificationCallbacks)
441 {
442     nsChannel *This = NSCHANNEL_THIS(iface);
443
444     TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
445
446     if(This->notif_callback)
447         nsIInterfaceRequestor_Release(This->notif_callback);
448     if(aNotificationCallbacks)
449         nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
450
451     This->notif_callback = aNotificationCallbacks;
452
453     if(This->channel)
454         return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
455     return NS_OK;
456 }
457
458 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
459 {
460     nsChannel *This = NSCHANNEL_THIS(iface);
461
462     TRACE("(%p)->(%p)\n", This, aSecurityInfo);
463
464     if(This->channel)
465         return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
466
467     FIXME("default action not implemented\n");
468     return NS_ERROR_NOT_IMPLEMENTED;
469 }
470
471 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
472 {
473     nsChannel *This = NSCHANNEL_THIS(iface);
474
475     TRACE("(%p)->(%p)\n", This, aContentType);
476
477     if(This->content) {
478         nsACString_Init(aContentType, This->content);
479         return S_OK;
480     }
481
482     if(This->channel)
483         return nsIChannel_GetContentType(This->channel, aContentType);
484
485     TRACE("returning default text/html\n");
486     nsACString_Init(aContentType, "text/html");
487     return NS_OK;
488 }
489
490 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
491                                                const nsACString *aContentType)
492 {
493     nsChannel *This = NSCHANNEL_THIS(iface);
494
495     TRACE("(%p)->(%p)\n", This, aContentType);
496
497     if(This->channel)
498         return nsIChannel_SetContentType(This->channel, aContentType);
499
500     FIXME("default action not implemented\n");
501     return NS_ERROR_NOT_IMPLEMENTED;
502 }
503
504 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
505                                                   nsACString *aContentCharset)
506 {
507     nsChannel *This = NSCHANNEL_THIS(iface);
508
509     TRACE("(%p)->(%p)\n", This, aContentCharset);
510
511     if(This->channel)
512         return nsIChannel_GetContentCharset(This->channel, aContentCharset);
513
514     FIXME("default action not implemented\n");
515     return NS_ERROR_NOT_IMPLEMENTED;
516 }
517
518 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
519                                                   const nsACString *aContentCharset)
520 {
521     nsChannel *This = NSCHANNEL_THIS(iface);
522
523     TRACE("(%p)->(%p)\n", This, aContentCharset);
524
525     if(This->channel)
526         return nsIChannel_SetContentCharset(This->channel, aContentCharset);
527
528     FIXME("default action not implemented\n");
529     return NS_ERROR_NOT_IMPLEMENTED;
530 }
531
532 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
533 {
534     nsChannel *This = NSCHANNEL_THIS(iface);
535
536     TRACE("(%p)->(%p)\n", This, aContentLength);
537
538     if(This->channel)
539         return nsIChannel_GetContentLength(This->channel, aContentLength);
540
541     FIXME("default action not implemented\n");
542     return NS_ERROR_NOT_IMPLEMENTED;
543 }
544
545 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
546 {
547     nsChannel *This = NSCHANNEL_THIS(iface);
548
549     TRACE("(%p)->(%ld)\n", This, aContentLength);
550
551     if(This->channel)
552         return nsIChannel_SetContentLength(This->channel, aContentLength);
553
554     FIXME("default action not implemented\n");
555     return NS_ERROR_NOT_IMPLEMENTED;
556 }
557
558 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
559 {
560     nsChannel *This = NSCHANNEL_THIS(iface);
561
562     TRACE("(%p)->(%p)\n", This, _retval);
563
564     if(This->channel)
565         return nsIChannel_Open(This->channel, _retval);
566
567     FIXME("default action not implemented\n");
568     return NS_ERROR_NOT_IMPLEMENTED;
569 }
570
571 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
572                                           nsISupports *aContext)
573 {
574     nsChannel *This = NSCHANNEL_THIS(iface);
575     BSCallback *bscallback;
576     nsIWineURI *wine_uri;
577     IMoniker *mon;
578     nsresult nsres;
579
580     TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
581
582     if(This->load_flags & LOAD_INITIAL_DOCUMENT_URI) {
583         NSContainer *container;
584
585         nsIWineURI_GetNSContainer(This->uri, &container);
586         if(!container) {
587             ERR("container = NULL\n");
588             return NS_ERROR_UNEXPECTED;
589         }
590
591         if(container->bscallback) {
592             nsIChannel_AddRef(NSCHANNEL(This));
593             container->bscallback->nschannel = This;
594
595             nsIStreamListener_AddRef(aListener);
596             container->bscallback->nslistener = aListener;
597
598             if(aContext) {
599                 nsISupports_AddRef(aContext);
600                 container->bscallback->nscontext = aContext;
601             }
602
603             nsIWebBrowserChrome_Release(NSWBCHROME(container));
604
605             if(!This->channel) {
606                 if(This->load_group) {
607                     nsres = nsILoadGroup_AddRequest(This->load_group,
608                                                     (nsIRequest*)NSCHANNEL(This), NULL);
609
610                     if(NS_FAILED(nsres))
611                         ERR("AddRequest failed:%08lx\n", nsres);
612                 }
613
614                 return WINE_NS_LOAD_FROM_MONIKER;
615             }
616         }else {
617             BOOL cont = before_async_open(This, container);
618             nsIWebBrowserChrome_Release(NSWBCHROME(container));
619
620             if(!cont) {
621                 TRACE("canceled\n");
622                 return NS_ERROR_UNEXPECTED;
623             }
624         }
625     }
626
627     if(This->channel) {
628         if(This->post_data_stream) {
629             nsIUploadChannel *upload_channel;
630
631             nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
632                                           (void**)&upload_channel);
633             if(NS_SUCCEEDED(nsres)) {
634                 nsACString empty_string;
635                 nsACString_Init(&empty_string, "");
636
637                 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
638                                                          &empty_string, -1);
639                 nsIUploadChannel_Release(upload_channel);
640                 if(NS_FAILED(nsres))
641                     WARN("SetUploadStream failed: %08lx\n", nsres);
642
643                 nsACString_Finish(&empty_string);
644             }
645         }
646
647         return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
648     }
649
650     TRACE("channel == NULL\n");
651
652     if(!This->original_uri) {
653         ERR("original_uri == NULL\n");
654         return NS_ERROR_UNEXPECTED;
655     }
656
657     nsres = nsIURI_QueryInterface(This->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
658     if(NS_FAILED(nsres)) {
659         ERR("Could not get nsIWineURI: %08lx\n", nsres);
660         return NS_ERROR_UNEXPECTED;
661     }
662
663     nsIWineURI_GetMoniker(wine_uri, &mon);
664     nsIWineURI_Release(wine_uri);
665
666     if(!mon) {
667         WARN("mon == NULL\n");
668         return NS_ERROR_UNEXPECTED;
669     }
670
671     bscallback = create_bscallback(NULL, mon);
672     IMoniker_Release(mon);
673
674     nsIChannel_AddRef(NSCHANNEL(This));
675     bscallback->nschannel = This;
676
677     nsIStreamListener_AddRef(aListener);
678     bscallback->nslistener = aListener;
679
680     if(aContext) {
681         nsISupports_AddRef(aContext);
682         bscallback->nscontext = aContext;
683     }
684
685     if(This->load_group) {
686         nsres = nsILoadGroup_AddRequest(This->load_group,
687                 (nsIRequest*)NSCHANNEL(This), NULL);
688
689         if(NS_FAILED(nsres))
690             ERR("AddRequest failed:%08lx\n", nsres);
691     }
692
693     start_binding(bscallback);
694     IBindStatusCallback_Release(STATUSCLB(bscallback));
695
696     return NS_OK;
697 }
698
699 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
700 {
701     nsChannel *This = NSCHANNEL_THIS(iface);
702
703     TRACE("(%p)->(%p)\n", This, aRequestMethod);
704
705     if(This->http_channel)
706         return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
707
708     return NS_ERROR_NOT_IMPLEMENTED;
709 }
710
711 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
712                                                  const nsACString *aRequestMethod)
713 {
714     nsChannel *This = NSCHANNEL_THIS(iface);
715
716     TRACE("(%p)->(%p)\n", This, aRequestMethod);
717
718     if(This->http_channel)
719         return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
720
721     return NS_ERROR_NOT_IMPLEMENTED;
722 }
723
724 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
725 {
726     nsChannel *This = NSCHANNEL_THIS(iface);
727
728     TRACE("(%p)->(%p)\n", This, aReferrer);
729
730     if(This->http_channel)
731         return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
732
733     return NS_ERROR_NOT_IMPLEMENTED;
734 }
735
736 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
737 {
738     nsChannel *This = NSCHANNEL_THIS(iface);
739
740     TRACE("(%p)->(%p)\n", This, aReferrer);
741
742     if(This->http_channel)
743         return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
744
745     return NS_ERROR_NOT_IMPLEMENTED;
746 }
747
748 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
749          const nsACString *aHeader, nsACString *_retval)
750 {
751     nsChannel *This = NSCHANNEL_THIS(iface);
752
753     TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
754
755     if(This->http_channel)
756         return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
757
758     return NS_ERROR_NOT_IMPLEMENTED;
759 }
760
761 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
762          const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
763 {
764     nsChannel *This = NSCHANNEL_THIS(iface);
765
766     TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
767
768     if(This->http_channel)
769         return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
770
771     return NS_ERROR_NOT_IMPLEMENTED;
772 }
773
774 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
775                                                     nsIHttpHeaderVisitor *aVisitor)
776 {
777     nsChannel *This = NSCHANNEL_THIS(iface);
778
779     TRACE("(%p)->(%p)\n", This, aVisitor);
780
781     if(This->http_channel)
782         return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
783
784     return NS_ERROR_NOT_IMPLEMENTED;
785 }
786
787 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
788 {
789     nsChannel *This = NSCHANNEL_THIS(iface);
790
791     TRACE("(%p)->(%p)\n", This, aAllowPipelining);
792
793     if(This->http_channel)
794         return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
795
796     return NS_ERROR_NOT_IMPLEMENTED;
797 }
798
799 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
800 {
801     nsChannel *This = NSCHANNEL_THIS(iface);
802
803     TRACE("(%p)->(%x)\n", This, aAllowPipelining);
804
805     if(This->http_channel)
806         return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
807
808     return NS_ERROR_NOT_IMPLEMENTED;
809 }
810
811 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
812 {
813     nsChannel *This = NSCHANNEL_THIS(iface);
814
815     TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
816
817     if(This->http_channel)
818         return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
819
820     return NS_ERROR_NOT_IMPLEMENTED;
821 }
822
823 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
824 {
825     nsChannel *This = NSCHANNEL_THIS(iface);
826
827     TRACE("(%p)->(%lu)\n", This, aRedirectionLimit);
828
829     if(This->http_channel)
830         return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
831
832     return NS_ERROR_NOT_IMPLEMENTED;
833 }
834
835 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
836 {
837     nsChannel *This = NSCHANNEL_THIS(iface);
838
839     TRACE("(%p)->(%p)\n", This, aResponseStatus);
840
841     if(This->http_channel)
842         return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
843
844     return NS_ERROR_NOT_IMPLEMENTED;
845 }
846
847 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
848                                                       nsACString *aResponseStatusText)
849 {
850     nsChannel *This = NSCHANNEL_THIS(iface);
851
852     TRACE("(%p)->(%p)\n", This, aResponseStatusText);
853
854     if(This->http_channel)
855         return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
856
857     return NS_ERROR_NOT_IMPLEMENTED;
858 }
859
860 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
861                                                     PRBool *aRequestSucceeded)
862 {
863     nsChannel *This = NSCHANNEL_THIS(iface);
864
865     TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
866
867     if(This->http_channel)
868         return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
869
870     return NS_ERROR_NOT_IMPLEMENTED;
871 }
872
873 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
874          const nsACString *header, nsACString *_retval)
875 {
876     nsChannel *This = NSCHANNEL_THIS(iface);
877
878     TRACE("(%p)->(%p %p)\n", This, header, _retval);
879
880     if(This->http_channel)
881         return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
882
883     return NS_ERROR_NOT_IMPLEMENTED;
884 }
885
886 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
887         const nsACString *header, const nsACString *value, PRBool merge)
888 {
889     nsChannel *This = NSCHANNEL_THIS(iface);
890
891     TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
892
893     if(This->http_channel)
894         return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
895
896     return NS_ERROR_NOT_IMPLEMENTED;
897 }
898
899 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
900         nsIHttpHeaderVisitor *aVisitor)
901 {
902     nsChannel *This = NSCHANNEL_THIS(iface);
903
904     TRACE("(%p)->(%p)\n", This, aVisitor);
905
906     if(This->http_channel)
907         return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
908
909     return NS_ERROR_NOT_IMPLEMENTED;
910 }
911
912 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
913 {
914     nsChannel *This = NSCHANNEL_THIS(iface);
915
916     TRACE("(%p)->(%p)\n", This, _retval);
917
918     if(This->http_channel)
919         return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
920
921     return NS_ERROR_NOT_IMPLEMENTED;
922 }
923
924 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
925 {
926     nsChannel *This = NSCHANNEL_THIS(iface);
927
928     TRACE("(%p)->(%p)\n", This, _retval);
929
930     if(This->http_channel)
931         return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
932
933     return NS_ERROR_NOT_IMPLEMENTED;
934 }
935
936 #undef NSCHANNEL_THIS
937
938 static const nsIHttpChannelVtbl nsChannelVtbl = {
939     nsChannel_QueryInterface,
940     nsChannel_AddRef,
941     nsChannel_Release,
942     nsChannel_GetName,
943     nsChannel_IsPending,
944     nsChannel_GetStatus,
945     nsChannel_Cancel,
946     nsChannel_Suspend,
947     nsChannel_Resume,
948     nsChannel_GetLoadGroup,
949     nsChannel_SetLoadGroup,
950     nsChannel_GetLoadFlags,
951     nsChannel_SetLoadFlags,
952     nsChannel_GetOriginalURI,
953     nsChannel_SetOriginalURI,
954     nsChannel_GetURI,
955     nsChannel_GetOwner,
956     nsChannel_SetOwner,
957     nsChannel_GetNotificationCallbacks,
958     nsChannel_SetNotificationCallbacks,
959     nsChannel_GetSecurityInfo,
960     nsChannel_GetContentType,
961     nsChannel_SetContentType,
962     nsChannel_GetContentCharset,
963     nsChannel_SetContentCharset,
964     nsChannel_GetContentLength,
965     nsChannel_SetContentLength,
966     nsChannel_Open,
967     nsChannel_AsyncOpen,
968     nsChannel_GetRequestMethod,
969     nsChannel_SetRequestMethod,
970     nsChannel_GetReferrer,
971     nsChannel_SetReferrer,
972     nsChannel_GetRequestHeader,
973     nsChannel_SetRequestHeader,
974     nsChannel_VisitRequestHeaders,
975     nsChannel_GetAllowPipelining,
976     nsChannel_SetAllowPipelining,
977     nsChannel_GetRedirectionLimit,
978     nsChannel_SetRedirectionLimit,
979     nsChannel_GetResponseStatus,
980     nsChannel_GetResponseStatusText,
981     nsChannel_GetRequestSucceeded,
982     nsChannel_GetResponseHeader,
983     nsChannel_SetResponseHeader,
984     nsChannel_VisitResponseHeaders,
985     nsChannel_IsNoStoreResponse,
986     nsChannel_IsNoCacheResponse
987 };
988
989 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
990
991 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
992                                                      nsQIResult result)
993 {
994     nsChannel *This = NSUPCHANNEL_THIS(iface);
995     return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
996 }
997
998 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
999 {
1000     nsChannel *This = NSUPCHANNEL_THIS(iface);
1001     return nsIChannel_AddRef(NSCHANNEL(This));
1002 }
1003
1004 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1005 {
1006     nsChannel *This = NSUPCHANNEL_THIS(iface);
1007     return nsIChannel_Release(NSCHANNEL(This));
1008 }
1009
1010 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1011         nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1012 {
1013     nsChannel *This = NSUPCHANNEL_THIS(iface);
1014     const char *content_type;
1015
1016     TRACE("(%p)->(%p %p %ld)\n", This, aStream, aContentType, aContentLength);
1017
1018     if(This->post_data_stream)
1019         nsIInputStream_Release(This->post_data_stream);
1020
1021     if(aContentType) {
1022         nsACString_GetData(aContentType, &content_type, NULL);
1023         if(*content_type)
1024             FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1025     }
1026
1027     if(aContentLength != -1)
1028         FIXME("Unsupported acontentLength = %ld\n", aContentLength);
1029
1030     if(aStream)
1031         nsIInputStream_AddRef(aStream);
1032     This->post_data_stream = aStream;
1033
1034     return NS_OK;
1035 }
1036
1037 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1038         nsIInputStream **aUploadStream)
1039 {
1040     nsChannel *This = NSUPCHANNEL_THIS(iface);
1041
1042     TRACE("(%p)->(%p)\n", This, aUploadStream);
1043
1044     if(This->post_data_stream)
1045         nsIInputStream_AddRef(This->post_data_stream);
1046
1047     *aUploadStream = This->post_data_stream;
1048     return NS_OK;
1049 }
1050
1051 #undef NSUPCHANNEL_THIS
1052
1053 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1054     nsUploadChannel_QueryInterface,
1055     nsUploadChannel_AddRef,
1056     nsUploadChannel_Release,
1057     nsUploadChannel_SetUploadStream,
1058     nsUploadChannel_GetUploadStream
1059 };
1060
1061 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1062
1063 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1064 {
1065     nsURI *This = NSURI_THIS(iface);
1066
1067     *result = NULL;
1068
1069     if(IsEqualGUID(&IID_nsISupports, riid)) {
1070         TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1071         *result = NSURI(This);
1072     }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1073         TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1074         *result = NSURI(This);
1075     }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1076         TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1077         *result = NSURI(This);
1078     }
1079
1080     if(*result) {
1081         nsIURI_AddRef(NSURI(This));
1082         return NS_OK;
1083     }
1084
1085     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1086     return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1087 }
1088
1089 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1090 {
1091     nsURI *This = NSURI_THIS(iface);
1092     LONG ref = InterlockedIncrement(&This->ref);
1093
1094     TRACE("(%p) ref=%ld\n", This, ref);
1095
1096     return ref;
1097 }
1098
1099 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1100 {
1101     nsURI *This = NSURI_THIS(iface);
1102     LONG ref = InterlockedDecrement(&This->ref);
1103
1104     TRACE("(%p) ref=%ld\n", This, ref);
1105
1106     if(!ref) {
1107         if(This->container)
1108             nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1109         if(This->uri)
1110             nsIURI_Release(This->uri);
1111         if(This->mon)
1112             IMoniker_Release(This->mon);
1113         mshtml_free(This->spec);
1114         mshtml_free(This);
1115     }
1116
1117     return ref;
1118 }
1119
1120 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1121 {
1122     nsURI *This = NSURI_THIS(iface);
1123
1124     TRACE("(%p)->(%p)\n", This, aSpec);
1125
1126     if(This->uri)
1127         return nsIURI_GetSpec(This->uri, aSpec);
1128
1129     if(This->spec) {
1130         nsACString_Init(aSpec, This->spec);
1131         return NS_OK;
1132     }
1133
1134     WARN("mon and uri are NULL\n");
1135     return NS_ERROR_NOT_IMPLEMENTED;
1136
1137 }
1138
1139 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1140 {
1141     nsURI *This = NSURI_THIS(iface);
1142
1143     TRACE("(%p)->(%p)\n", This, aSpec);
1144
1145     if(This->uri)
1146         return nsIURI_SetSpec(This->uri, aSpec);
1147
1148     FIXME("default action not implemented\n");
1149     return NS_ERROR_NOT_IMPLEMENTED;
1150 }
1151
1152 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1153 {
1154     nsURI *This = NSURI_THIS(iface);
1155
1156     TRACE("(%p)->(%p)\n", This, aPrePath);
1157
1158     if(This->uri)
1159         return nsIURI_GetPrePath(This->uri, aPrePath);
1160
1161     FIXME("default action not implemented\n");
1162     return NS_ERROR_NOT_IMPLEMENTED;
1163 }
1164
1165 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1166 {
1167     nsURI *This = NSURI_THIS(iface);
1168
1169     TRACE("(%p)->(%p)\n", This, aScheme);
1170
1171     if(This->uri)
1172         return nsIURI_GetScheme(This->uri, aScheme);
1173
1174     FIXME("default action not implemented\n");
1175     return NS_ERROR_NOT_IMPLEMENTED;
1176 }
1177
1178 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1179 {
1180     nsURI *This = NSURI_THIS(iface);
1181
1182     TRACE("(%p)->(%p)\n", This, aScheme);
1183
1184     if(This->uri)
1185         return nsIURI_SetScheme(This->uri, aScheme);
1186
1187     FIXME("default action not implemented\n");
1188     return NS_ERROR_NOT_IMPLEMENTED;
1189 }
1190
1191 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1192 {
1193     nsURI *This = NSURI_THIS(iface);
1194
1195     TRACE("(%p)->(%p)\n", This, aUserPass);
1196
1197     if(This->uri)
1198         return nsIURI_GetUserPass(This->uri, aUserPass);
1199
1200     FIXME("default action not implemented\n");
1201     return NS_ERROR_NOT_IMPLEMENTED;
1202 }
1203
1204 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1205 {
1206     nsURI *This = NSURI_THIS(iface);
1207
1208     TRACE("(%p)->(%p)\n", This, aUserPass);
1209
1210     if(This->uri)
1211         return nsIURI_SetUserPass(This->uri, aUserPass);
1212
1213     FIXME("default action not implemented\n");
1214     return NS_ERROR_NOT_IMPLEMENTED;
1215 }
1216
1217 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1218 {
1219     nsURI *This = NSURI_THIS(iface);
1220
1221     TRACE("(%p)->(%p)\n", This, aUsername);
1222
1223     if(This->uri)
1224         return nsIURI_GetUsername(This->uri, aUsername);
1225
1226     FIXME("default action not implemented\n");
1227     return NS_ERROR_NOT_IMPLEMENTED;
1228 }
1229
1230 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1231 {
1232     nsURI *This = NSURI_THIS(iface);
1233
1234     TRACE("(%p)->(%p)\n", This, aUsername);
1235
1236     if(This->uri)
1237         return nsIURI_SetUsername(This->uri, aUsername);
1238
1239     FIXME("default action not implemented\n");
1240     return NS_ERROR_NOT_IMPLEMENTED;
1241 }
1242
1243 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1244 {
1245     nsURI *This = NSURI_THIS(iface);
1246
1247     TRACE("(%p)->(%p)\n", This, aPassword);
1248
1249     if(This->uri)
1250         return nsIURI_GetPassword(This->uri, aPassword);
1251
1252     FIXME("default action not implemented\n");
1253     return NS_ERROR_NOT_IMPLEMENTED;
1254 }
1255
1256 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1257 {
1258     nsURI *This = NSURI_THIS(iface);
1259
1260     TRACE("(%p)->(%p)\n", This, aPassword);
1261
1262     if(This->uri)
1263         return nsIURI_SetPassword(This->uri, aPassword);
1264
1265     FIXME("default action not implemented\n");
1266     return NS_ERROR_NOT_IMPLEMENTED;
1267 }
1268
1269 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1270 {
1271     nsURI *This = NSURI_THIS(iface);
1272
1273     TRACE("(%p)->(%p)\n", This, aHostPort);
1274
1275     if(This->uri)
1276         return nsIURI_GetHostPort(This->uri, aHostPort);
1277
1278     FIXME("default action not implemented\n");
1279     return NS_ERROR_NOT_IMPLEMENTED;
1280 }
1281
1282 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1283 {
1284     nsURI *This = NSURI_THIS(iface);
1285
1286     TRACE("(%p)->(%p)\n", This, aHostPort);
1287
1288     if(This->uri)
1289         return nsIURI_SetHostPort(This->uri, aHostPort);
1290
1291     FIXME("default action not implemented\n");
1292     return NS_ERROR_NOT_IMPLEMENTED;
1293 }
1294
1295 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1296 {
1297     nsURI *This = NSURI_THIS(iface);
1298
1299     TRACE("(%p)->(%p)\n", This, aHost);
1300
1301     if(This->uri)
1302         return nsIURI_GetHost(This->uri, aHost);
1303
1304     FIXME("default action not implemented\n");
1305     return NS_ERROR_NOT_IMPLEMENTED;
1306 }
1307
1308 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1309 {
1310     nsURI *This = NSURI_THIS(iface);
1311
1312     TRACE("(%p)->(%p)\n", This, aHost);
1313
1314     if(This->uri)
1315         return nsIURI_SetHost(This->uri, aHost);
1316
1317     FIXME("default action not implemented\n");
1318     return NS_ERROR_NOT_IMPLEMENTED;
1319 }
1320
1321 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1322 {
1323     nsURI *This = NSURI_THIS(iface);
1324
1325     TRACE("(%p)->(%p)\n", This, aPort);
1326
1327     if(This->uri)
1328         return nsIURI_GetPort(This->uri, aPort);
1329
1330     FIXME("default action not implemented\n");
1331     return NS_ERROR_NOT_IMPLEMENTED;
1332 }
1333
1334 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1335 {
1336     nsURI *This = NSURI_THIS(iface);
1337
1338     TRACE("(%p)->(%ld)\n", This, aPort);
1339
1340     if(This->uri)
1341         return nsIURI_SetPort(This->uri, aPort);
1342
1343     FIXME("default action not implemented\n");
1344     return NS_ERROR_NOT_IMPLEMENTED;
1345 }
1346
1347 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1348 {
1349     nsURI *This = NSURI_THIS(iface);
1350
1351     TRACE("(%p)->(%p)\n", This, aPath);
1352
1353     if(This->uri)
1354         return nsIURI_GetPath(This->uri, aPath);
1355
1356     FIXME("default action not implemented\n");
1357     return NS_ERROR_NOT_IMPLEMENTED;
1358 }
1359
1360 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1361 {
1362     nsURI *This = NSURI_THIS(iface);
1363
1364     TRACE("(%p)->(%p)\n", This, aPath);
1365
1366     if(This->uri)
1367         return nsIURI_SetPath(This->uri, aPath);
1368
1369     FIXME("default action not implemented\n");
1370     return NS_ERROR_NOT_IMPLEMENTED;
1371 }
1372
1373 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1374 {
1375     nsURI *This = NSURI_THIS(iface);
1376
1377     TRACE("(%p)->(%p %p)\n", This, other, _retval);
1378
1379     if(This->uri)
1380         return nsIURI_Equals(This->uri, other, _retval);
1381
1382     FIXME("default action not implemented\n");
1383     return NS_ERROR_NOT_IMPLEMENTED;
1384 }
1385
1386 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1387 {
1388     nsURI *This = NSURI_THIS(iface);
1389
1390     TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1391
1392     if(This->uri)
1393         return nsIURI_SchemeIs(This->uri, scheme, _retval);
1394
1395     FIXME("default action not implemented\n");
1396     return NS_ERROR_NOT_IMPLEMENTED;
1397 }
1398
1399 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1400 {
1401     nsURI *This = NSURI_THIS(iface);
1402
1403     TRACE("(%p)->(%p)\n", This, _retval);
1404
1405     if(This->uri) {
1406         nsIURI *uri;
1407         nsresult nsres;
1408
1409         nsres = nsIURI_Clone(This->uri, &uri);
1410         if(NS_FAILED(nsres)) {
1411             WARN("Clone failed: %08lx\n", nsres);
1412             return nsres;
1413         }
1414
1415         return create_uri(uri, This->container, _retval);
1416     }
1417
1418     FIXME("default action not implemented\n");
1419     return NS_ERROR_NOT_IMPLEMENTED;
1420 }
1421
1422 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1423         nsACString *_retval)
1424 {
1425     nsURI *This = NSURI_THIS(iface);
1426
1427     TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1428
1429     if(This->uri)
1430         return nsIURI_Resolve(This->uri, arelativePath, _retval);
1431
1432     FIXME("default action not implemented\n");
1433     return NS_ERROR_NOT_IMPLEMENTED;
1434 }
1435
1436 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1437 {
1438     nsURI *This = NSURI_THIS(iface);
1439
1440     TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1441
1442     if(This->uri)
1443         return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1444
1445     FIXME("default action not implemented\n");
1446     return NS_ERROR_NOT_IMPLEMENTED;
1447 }
1448
1449 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1450 {
1451     nsURI *This = NSURI_THIS(iface);
1452
1453     TRACE("(%p)->(%p)\n", This, aAsciiHost);
1454
1455     if(This->uri)
1456         return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1457
1458     FIXME("default action not implemented\n");
1459     return NS_ERROR_NOT_IMPLEMENTED;
1460 }
1461
1462 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1463 {
1464     nsURI *This = NSURI_THIS(iface);
1465
1466     TRACE("(%p)->(%p)\n", This, aOriginCharset);
1467
1468     if(This->uri)
1469         return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1470
1471     FIXME("default action not implemented\n");
1472     return NS_ERROR_NOT_IMPLEMENTED;
1473 }
1474
1475 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1476 {
1477     nsURI *This = NSURI_THIS(iface);
1478
1479     TRACE("(%p)->(%p)\n", This, aContainer);
1480
1481     if(This->container)
1482         nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1483     *aContainer = This->container;
1484
1485     return NS_OK;
1486 }
1487
1488 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1489 {
1490     nsURI *This = NSURI_THIS(iface);
1491
1492     TRACE("(%p)->(%p)\n", This, aContainer);
1493
1494     if(This->container) {
1495         WARN("Container already set: %p\n", This->container);
1496         nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1497     }
1498
1499     if(aContainer)
1500         nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1501     This->container = aContainer;
1502
1503     return NS_OK;
1504 }
1505
1506 static nsresult NSAPI nsURI_GetMoniker(nsIWineURI *iface, IMoniker **aMoniker)
1507 {
1508     nsURI *This = NSURI_THIS(iface);
1509
1510     TRACE("(%p)->(%p)\n", This, aMoniker);
1511
1512     if(This->mon)
1513         IMoniker_AddRef(This->mon);
1514     *aMoniker = This->mon;
1515
1516     return NS_OK;
1517 }
1518
1519 static nsresult NSAPI nsURI_SetMoniker(nsIWineURI *iface, IMoniker *aMoniker)
1520 {
1521     nsURI *This = NSURI_THIS(iface);
1522
1523     TRACE("(%p)->(%p)\n", This, aMoniker);
1524
1525     if(This->mon) {
1526         WARN("Moniker already set: %p\n", This->container);
1527         IMoniker_Release(This->mon);
1528
1529         mshtml_free(This->spec);
1530         This->spec = NULL;
1531     }
1532
1533     if(aMoniker) {
1534         LPWSTR url = NULL;
1535         HRESULT hres;
1536
1537         hres = IMoniker_GetDisplayName(aMoniker, NULL, NULL, &url);
1538         if(SUCCEEDED(hres)) {
1539             DWORD len;
1540
1541             len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, 0, NULL, NULL);
1542             This->spec = mshtml_alloc(len*sizeof(WCHAR));
1543             WideCharToMultiByte(CP_ACP, 0, url, -1, This->spec, -1, NULL, NULL);
1544             CoTaskMemFree(url);
1545
1546             TRACE("spec %s\n", debugstr_a(This->spec));
1547         }else {
1548             ERR("GetDisplayName failed: %08lx\n", hres);
1549         }
1550
1551         IMoniker_AddRef(aMoniker);
1552     }
1553     This->mon = aMoniker;
1554
1555     return NS_OK;
1556 }
1557
1558 #undef NSURI_THIS
1559
1560 static const nsIWineURIVtbl nsWineURIVtbl = {
1561     nsURI_QueryInterface,
1562     nsURI_AddRef,
1563     nsURI_Release,
1564     nsURI_GetSpec,
1565     nsURI_SetSpec,
1566     nsURI_GetPrePath,
1567     nsURI_GetScheme,
1568     nsURI_SetScheme,
1569     nsURI_GetUserPass,
1570     nsURI_SetUserPass,
1571     nsURI_GetUsername,
1572     nsURI_SetUsername,
1573     nsURI_GetPassword,
1574     nsURI_SetPassword,
1575     nsURI_GetHostPort,
1576     nsURI_SetHostPort,
1577     nsURI_GetHost,
1578     nsURI_SetHost,
1579     nsURI_GetPort,
1580     nsURI_SetPort,
1581     nsURI_GetPath,
1582     nsURI_SetPath,
1583     nsURI_Equals,
1584     nsURI_SchemeIs,
1585     nsURI_Clone,
1586     nsURI_Resolve,
1587     nsURI_GetAsciiSpec,
1588     nsURI_GetAsciiHost,
1589     nsURI_GetOriginCharset,
1590     nsURI_GetNSContainer,
1591     nsURI_SetNSContainer,
1592     nsURI_GetMoniker,
1593     nsURI_SetMoniker
1594 };
1595
1596 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIURI **_retval)
1597 {
1598     nsURI *ret = mshtml_alloc(sizeof(nsURI));
1599
1600     ret->lpWineURIVtbl = &nsWineURIVtbl;
1601     ret->ref = 1;
1602     ret->uri = uri;
1603     ret->container = container;
1604     ret->mon = NULL;
1605     ret->spec = NULL;
1606
1607     if(container)
1608         nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1609
1610     TRACE("retval=%p\n", ret);
1611     *_retval = NSURI(ret);
1612     return NS_OK;
1613 }
1614
1615 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1616                                                  nsQIResult result)
1617 {
1618     *result = NULL;
1619
1620     if(IsEqualGUID(&IID_nsISupports, riid)) {
1621         TRACE("(IID_nsISupports %p)\n", result);
1622         *result = iface;
1623     }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1624         TRACE("(IID_nsIIOService %p)\n", result);
1625         *result = iface;
1626     }
1627
1628     if(*result) {
1629         nsIIOService_AddRef(iface);
1630         return S_OK;
1631     }
1632
1633     WARN("(%s %p)\n", debugstr_guid(riid), result);
1634     return NS_NOINTERFACE;
1635 }
1636
1637 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1638 {
1639     return 2;
1640 }
1641
1642 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1643 {
1644     return 1;
1645 }
1646
1647 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1648                                                      nsIProtocolHandler **_retval)
1649 {
1650     TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1651     return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1652 }
1653
1654 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1655                                                     PRUint32 *_retval)
1656 {
1657     TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1658     return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1659 }
1660
1661 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1662         const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1663 {
1664     const char *spec = NULL;
1665     NSContainer *nscontainer = NULL;
1666     nsIURI *uri = NULL;
1667     PRBool is_javascript = FALSE;
1668     IMoniker *base_mon = NULL;
1669     nsresult nsres;
1670
1671     nsACString_GetData(aSpec, &spec, NULL);
1672
1673     TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1674           aBaseURI, _retval);
1675
1676     if(aBaseURI) {
1677         nsACString base_uri_str;
1678         const char *base_uri = NULL;
1679
1680         nsACString_Init(&base_uri_str, NULL);
1681
1682         nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1683         if(NS_SUCCEEDED(nsres)) {
1684             nsACString_GetData(&base_uri_str, &base_uri, NULL);
1685             TRACE("uri=%s\n", debugstr_a(base_uri));
1686         }else {
1687             ERR("GetSpec failed: %08lx\n", nsres);
1688         }
1689
1690         nsACString_Finish(&base_uri_str);
1691     }
1692
1693     nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1694     if(NS_FAILED(nsres))
1695         TRACE("NewURI failed: %08lx\n", nsres);
1696
1697     if(uri) {
1698         nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1699         if(is_javascript) {
1700             TRACE("returning javascript uri: %p\n", uri);
1701             *_retval = uri;
1702             return NS_OK;
1703         }
1704     }
1705
1706     if(aBaseURI) {
1707         nsIWineURI *wine_uri;
1708
1709         nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&wine_uri);
1710         if(NS_SUCCEEDED(nsres)) {
1711             nsIWineURI_GetNSContainer(wine_uri, &nscontainer);
1712             nsIWineURI_GetMoniker(wine_uri, &base_mon);
1713             nsIWineURI_Release(wine_uri);
1714         }else {
1715             ERR("Could not get nsIWineURI: %08lx\n", nsres);
1716         }
1717     }
1718
1719     nsres = create_uri(uri, nscontainer, _retval);
1720
1721     if(nscontainer)
1722         nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
1723
1724     if(base_mon) {
1725         LPWSTR url;
1726         IMoniker *mon;
1727         DWORD len;
1728         HRESULT hres;
1729
1730         len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
1731         url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1732         MultiByteToWideChar(CP_ACP, 0, spec, -1, url, -1);
1733
1734         hres = CreateURLMoniker(base_mon, url, &mon);
1735         HeapFree(GetProcessHeap(), 0, url);
1736         if(SUCCEEDED(hres)) {
1737             nsIWineURI_SetMoniker((nsIWineURI*)*_retval, mon);
1738             IMoniker_Release(mon);
1739         }else {
1740             WARN("CreateURLMoniker failed: %08lx\n", hres);
1741         }
1742     }
1743
1744     return nsres;
1745 }
1746
1747 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1748                                              nsIURI **_retval)
1749 {
1750     TRACE("(%p %p)\n", aFile, _retval);
1751     return nsIIOService_NewFileURI(nsio, aFile, _retval);
1752 }
1753
1754 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1755                                                      nsIChannel **_retval)
1756 {
1757     nsIChannel *channel = NULL;
1758     nsChannel *ret;
1759     nsIWineURI *wine_uri;
1760     nsresult nsres;
1761
1762     TRACE("(%p %p)\n", aURI, _retval);
1763
1764     nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1765     if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1766         WARN("NewChannelFromURI failed: %08lx\n", nsres);
1767         *_retval = channel;
1768         return nsres;
1769     }
1770
1771     nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1772     if(NS_FAILED(nsres)) {
1773         WARN("Could not get nsIWineURI: %08lx\n", nsres);
1774         *_retval = channel;
1775         return channel ? NS_OK : NS_ERROR_UNEXPECTED;
1776     }
1777
1778     ret = mshtml_alloc(sizeof(nsChannel));
1779
1780     ret->lpHttpChannelVtbl = &nsChannelVtbl;
1781     ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1782     ret->ref = 1;
1783     ret->channel = channel;
1784     ret->http_channel = NULL;
1785     ret->uri = wine_uri;
1786     ret->post_data_stream = NULL;
1787     ret->load_group = NULL;
1788     ret->notif_callback = NULL;
1789     ret->load_flags = 0;
1790     ret->content = NULL;
1791
1792     nsIURI_AddRef(aURI);
1793     ret->original_uri = aURI;
1794
1795     if(channel)
1796         nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1797
1798     *_retval = NSCHANNEL(ret);
1799     return NS_OK;
1800 }
1801
1802 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1803         const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1804 {
1805     TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1806     return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1807 }
1808
1809 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1810 {
1811     TRACE("(%p)\n", aOffline);
1812     return nsIIOService_GetOffline(nsio, aOffline);
1813 }
1814
1815 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1816 {
1817     TRACE("(%x)\n", aOffline);
1818     return nsIIOService_SetOffline(nsio, aOffline);
1819 }
1820
1821 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1822                                              const char *aScheme, PRBool *_retval)
1823 {
1824     TRACE("(%ld %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1825     return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1826 }
1827
1828 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1829                                                  nsACString * _retval)
1830 {
1831     TRACE("(%p %p)\n", urlString, _retval);
1832     return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1833 }
1834
1835 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1836     nsIOService_QueryInterface,
1837     nsIOService_AddRef,
1838     nsIOService_Release,
1839     nsIOService_GetProtocolHandler,
1840     nsIOService_GetProtocolFlags,
1841     nsIOService_NewURI,
1842     nsIOService_NewFileURI,
1843     nsIOService_NewChannelFromURI,
1844     nsIOService_NewChannel,
1845     nsIOService_GetOffline,
1846     nsIOService_SetOffline,
1847     nsIOService_AllowPort,
1848     nsIOService_ExtractScheme
1849 };
1850
1851 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1852
1853 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1854                                                         nsQIResult result)
1855 {
1856     *result = NULL;
1857
1858     if(IsEqualGUID(&IID_nsISupports, riid)) {
1859         TRACE("(IID_nsISupoprts %p)\n", result);
1860         *result = iface;
1861     }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1862         TRACE("(IID_nsIFactory %p)\n", result);
1863         *result = iface;
1864     }
1865
1866     if(*result) {
1867         nsIFactory_AddRef(iface);
1868         return NS_OK;
1869     }
1870
1871     WARN("(%s %p)\n", debugstr_guid(riid), result);
1872     return NS_NOINTERFACE;
1873 }
1874
1875 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1876 {
1877     return 2;
1878 }
1879
1880 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1881 {
1882     return 1;
1883 }
1884
1885 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1886         nsISupports *aOuter, const nsIID *iid, void **result)
1887 {
1888     return nsIIOService_QueryInterface(&nsIOService, iid, result);
1889 }
1890
1891 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1892 {
1893     WARN("(%x)\n", lock);
1894     return NS_OK;
1895 }
1896
1897 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1898     nsIOServiceFactory_QueryInterface,
1899     nsIOServiceFactory_AddRef,
1900     nsIOServiceFactory_Release,
1901     nsIOServiceFactory_CreateInstance,
1902     nsIOServiceFactory_LockFactory
1903 };
1904
1905 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1906
1907 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1908 {
1909     nsIFactory *old_factory = NULL;
1910     nsresult nsres;
1911
1912     nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1913                                                &IID_nsIFactory, (void**)&old_factory);
1914     if(NS_FAILED(nsres)) {
1915         ERR("Could not get factory: %08lx\n", nsres);
1916         nsIFactory_Release(old_factory);
1917         return;
1918     }
1919
1920     nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
1921     if(NS_FAILED(nsres)) {
1922         ERR("Couldn not create nsIOService instance %08lx\n", nsres);
1923         nsIFactory_Release(old_factory);
1924         return;
1925     }
1926
1927     nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
1928     nsIFactory_Release(old_factory);
1929     if(NS_FAILED(nsres))
1930         ERR("UnregisterFactory failed: %08lx\n", nsres);
1931
1932     nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
1933             NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
1934     if(NS_FAILED(nsres))
1935         ERR("RegisterFactory failed: %08lx\n", nsres);
1936 }