1 /* ***** BEGIN LICENSE BLOCK *****
2 Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 The contents of this file are subject to the Mozilla Public License Version
5 1.1 (the "License"); you may not use this file except in compliance with
6 the License. You may obtain a copy of the License at
7 http://www.mozilla.org/MPL/
9 Software distributed under the License is distributed on an "AS IS" basis,
10 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 for the specific language governing rights and limitations under the
14 The Original Code is mozilla.org code.
16 The Initial Developer of the Original Code is
17 Netscape Communications Corporation.
18 Portions created by the Initial Developer are Copyright (C) 1998
19 the Initial Developer. All Rights Reserved.
22 Ashish Bhatt <ashishbhatt@netscape.com> Original Author
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
36 ***** END LICENSE BLOCK ***** */
40 Components
.interfaces
.nsIIOService
41 const IO_SERVICE_CTRID
=
42 "@mozilla.org/network/io-service;1" ;
49 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
50 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
53 this.service
= Components
.classes
[IO_SERVICE_CTRID
].getService(nsIIOService
);
66 IOService
.prototype.service
= null ;
67 IOService
.prototype.success
= null ;
68 IOService
.prototype.exception
= null ;
69 IOService
.prototype.returnvalue
= null ;
72 IOService
.prototype.getProtocolHandler = function(aScheme
)
76 * Returns a protocol handler for a given URI scheme.
78 * @param aScheme the URI scheme
79 * @return reference to corresponding nsIProtocolHandler
81 * nsIProtocolHandler getProtocolHandler(in string aScheme)
86 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
87 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
89 this.returnvalue
= this.service
.getProtocolHandler(aScheme
) ;
102 IOService
.prototype.getProtocolFlags= function(aScheme
)
105 * Returns the protocol flags for a given scheme.
107 * @param aScheme the URI scheme
108 * @return value of corresponding nsIProtocolHandler::protocolFlags
110 * unsigned long getProtocolFlags(in string aScheme);
116 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
117 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
119 this.returnvalue
= this.service
.getProtocolFlags(aScheme
) ;
120 if (this.returnvalue
>=0)
123 this.success
= false;
126 this.success
= false;
131 IOService
.prototype.newURI = function(aSpec
,aOriginCharset
,aBaseURI
)
134 * This method constructs a new URI by determining the scheme of the
135 * URI spec, and then delegating the construction of the URI to the
136 * protocol handler for that scheme. QueryInterface can be used on
137 * the resulting URI object to obtain a more specific type of URI.
139 * @see nsIProtocolHandler::newURI
141 * nsIURI newURI(in AUTF8String aSpec,
142 * in string aOriginCharset,
143 * in nsIURI aBaseURI);
148 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
149 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
151 this.returnvalue
= this.service
.newURI(aSpec
,aOriginCharset
,aBaseURI
) ;
153 if (this.returnvalue
)
156 this.success
= false;
159 this.success
= false;
165 IOService
.prototype.newFileURI= function(file
)
168 * This method constructs a new URI from a nsIFile.
170 * @param aFile specifies the file path
171 * @return reference to a new nsIURI object
173 * nsIURI newFileURI(in nsIFile aFile);
178 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
179 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
181 this.returnvalue
= this.service
.newFileURI(file
) ;
183 if (this.returnvalue
)
186 this.success
= false;
189 this.success
= false;
196 IOService
.prototype.newChannelFromURI = function(aURI
)
199 * Creates a channel for a given URI.
201 * @param aURI nsIURI from which to make a channel
202 * @return reference to the new nsIChannel object
204 * nsIChannel newChannelFromURI(in nsIURI aURI);
209 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
210 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
212 this.returnvalue
= this.service
.newChannelFromURI(aURI
) ;
214 if (this.returnvalue
)
217 this.success
= false;
220 this.success
= false;
227 IOService
.prototype.newChannel = function(aSpec
,aOriginCharset
,aBaseURI
)
230 * Equivalent to newChannelFromURI(newURI(...))
232 * nsIChannel newChannel(in AUTF8String aSpec,
233 * in string aOriginCharset,
234 * in nsIURI aBaseURI);
239 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
240 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
242 this.returnvalue
= this.service
.newChannel(aSpec
,aOriginCharset
,aBaseURI
) ;
244 if (this.returnvalue
)
247 this.success
= false;
250 this.success
= false;
256 IOService
.prototype.Getoffline = function()
260 * Returns true if networking is in "offline" mode. When in offline mode,
261 * attempts to access the network will fail (although this does not
262 * necessarily correlate with whether there is actually a network
263 * available -- that's hard to detect without causing the dialer to
266 * attribute boolean offline;
271 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
272 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
274 this.returnvalue
= this.service
.offline
;
278 this.success
= false;
284 IOService
.prototype. Setoffline = function(aOffline
)
287 * Returns true if networking is in "offline" mode. When in offline mode,
288 * attempts to access the network will fail (although this does not
289 * necessarily correlate with whether there is actually a network
290 * available -- that's hard to detect without causing the dialer to
293 * attribute boolean offline;
298 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
299 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
301 this.service
.offline
= aOffline
;
302 this.returnvalue
= this.service
.offline
306 this.success
= false;
312 IOService
.prototype.allowPort= function(aPort
, aScheme
)
315 * Checks if a port number is banned. This involves consulting a list of
316 * unsafe ports, corresponding to network services that may be easily
317 * exploitable. If the given port is considered unsafe, then the protocol
318 * handler (corresponding to aScheme) will be asked whether it wishes to
319 * override the IO service's decision to block the port. This gives the
320 * protocol handler ultimate control over its own security policy while
321 * ensuring reasonable, default protection.
323 * @see nsIProtocolHandler::allowPort
325 * boolean allowPort(in long aPort, in string aScheme);
331 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
332 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
334 this.returnvalue
= this.service
.allowPort(aPort
, aScheme
) ;
336 if (this.returnvalue
)
339 this.success
= false;
342 this.success
= false;
348 IOService
.prototype.extractScheme = function(urlString
)
351 * Utility to extract the scheme from a URL string, consistently and
352 * according to spec (see RFC 2396).
354 * NOTE: Most URL parsing is done via nsIURI, and in fact the scheme
355 * can also be extracted from a URL string via nsIURI. This method
356 * is provided purely as an optimization.
358 * @param aSpec the URL string to parse
361 * @throws NS_ERROR_MALFORMED_URI if URL string is not of the right form.
363 * ACString extractScheme(in AUTF8String urlString);
369 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalBrowserRead");
370 netscape
.security
.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
372 this.returnvalue
= this.service
.extractScheme(urlString
) ;
374 if (this.returnvalue
)
377 this.success
= false;
381 this.success
= false;