1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
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 ***** */
38 #ifndef nsIOService_h__
39 #define nsIOService_h__
41 #include "necko-config.h"
44 #include "nsIIOService2.h"
45 #include "nsVoidArray.h"
46 #include "nsPISocketTransportService.h"
47 #include "nsPIDNSService.h"
48 #include "nsIProtocolProxyService2.h"
50 #include "nsURLHelper.h"
51 #include "nsWeakPtr.h"
52 #include "nsIURLParser.h"
53 #include "nsSupportsArray.h"
54 #include "nsIObserver.h"
55 #include "nsWeakReference.h"
56 #include "nsINetUtil.h"
57 #include "nsIChannelEventSink.h"
58 #include "nsIContentSniffer.h"
59 #include "nsCategoryCache.h"
60 #include "nsINetworkLinkService.h"
62 #define NS_N(x) (sizeof(x)/sizeof(*x))
64 #ifdef NECKO_SMALL_BUFFERS
65 #define NS_NECKO_BUFFER_CACHE_COUNT (10) // Max holdings: 10 * 2k = 20k
67 #define NS_NECKO_BUFFER_CACHE_COUNT (24) // Max holdings: 24 * 4k = 96k
69 #define NS_NECKO_15_MINS (15 * 60)
71 static const char gScheme
[][sizeof("resource")] =
72 {"chrome", "file", "http", "jar", "resource"};
77 class nsIOService
: public nsIIOService2
80 , public nsINetUtil_MOZILLA_1_9_1
81 , public nsSupportsWeakReference
89 NS_DECL_NSINETUTIL_MOZILLA_1_9_1
91 // Gets the singleton instance of the IO Service, creating it as needed
92 // Returns nsnull on out of memory or failure to initialize.
93 // Returns an addrefed pointer.
94 static nsIOService
* GetInstance();
96 NS_HIDDEN_(nsresult
) Init();
97 NS_HIDDEN_(nsresult
) NewURI(const char* aSpec
, nsIURI
* aBaseURI
,
99 nsIProtocolHandler
* *hdlrResult
);
101 // Called by channels before a redirect happens. This notifies the global
102 // redirect observers.
103 nsresult
OnChannelRedirect(nsIChannel
* oldChan
, nsIChannel
* newChan
,
106 // Gets the array of registered content sniffers
107 const nsCOMArray
<nsIContentSniffer
>& GetContentSniffers() {
108 return mContentSniffers
.GetEntries();
111 PRBool
IsOffline() { return mOffline
; }
114 // These shouldn't be called directly:
115 // - construct using GetInstance
116 // - destroy using Release
117 nsIOService() NS_HIDDEN
;
118 ~nsIOService() NS_HIDDEN
;
120 NS_HIDDEN_(nsresult
) TrackNetworkLinkStatusForOffline();
122 NS_HIDDEN_(nsresult
) GetCachedProtocolHandler(const char *scheme
,
123 nsIProtocolHandler
* *hdlrResult
,
126 NS_HIDDEN_(nsresult
) CacheProtocolHandler(const char *scheme
,
127 nsIProtocolHandler
* hdlr
);
130 NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch
*prefs
, const char *pref
= nsnull
);
131 NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch2
**);
132 NS_HIDDEN_(void) ParsePortList(nsIPrefBranch
*prefBranch
, const char *pref
, PRBool remove
);
135 PRPackedBool mOffline
;
136 PRPackedBool mOfflineForProfileChange
;
137 PRPackedBool mManageOfflineStatus
;
138 nsCOMPtr
<nsPISocketTransportService
> mSocketTransportService
;
139 nsCOMPtr
<nsPIDNSService
> mDNSService
;
140 nsCOMPtr
<nsIProtocolProxyService2
> mProxyService
;
141 nsCOMPtr
<nsINetworkLinkService
> mNetworkLinkService
;
143 // Cached protocol handlers
144 nsWeakPtr mWeakHandler
[NS_N(gScheme
)];
147 nsCategoryCache
<nsIChannelEventSink
> mChannelEventSinks
;
148 nsCategoryCache
<nsIContentSniffer
> mContentSniffers
;
150 nsVoidArray mRestrictedPortList
;
153 // Necko buffer cache. Used for all default buffer sizes that necko
155 static nsIMemory
*gBufferCache
;
159 * Reference to the IO service singleton. May be null.
161 extern nsIOService
* gIOService
;
163 #endif // nsIOService_h__