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
4 : *
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/
9 : *
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
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsIOService_h__
39 : #define nsIOService_h__
40 :
41 : #include "necko-config.h"
42 :
43 : #include "nsString.h"
44 : #include "nsIIOService2.h"
45 : #include "nsTArray.h"
46 : #include "nsPISocketTransportService.h"
47 : #include "nsPIDNSService.h"
48 : #include "nsIProtocolProxyService2.h"
49 : #include "nsCOMPtr.h"
50 : #include "nsURLHelper.h"
51 : #include "nsWeakPtr.h"
52 : #include "nsIURLParser.h"
53 : #include "nsIObserver.h"
54 : #include "nsWeakReference.h"
55 : #include "nsINetUtil.h"
56 : #include "nsIChannelEventSink.h"
57 : #include "nsIContentSniffer.h"
58 : #include "nsCategoryCache.h"
59 : #include "nsINetworkLinkService.h"
60 : #include "nsAsyncRedirectVerifyHelper.h"
61 :
62 : #define NS_N(x) (sizeof(x)/sizeof(*x))
63 :
64 : // We don't want to expose this observer topic.
65 : // Intended internal use only for remoting offline/inline events.
66 : // See Bug 552829
67 : #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
68 :
69 : static const char gScheme[][sizeof("resource")] =
70 : {"chrome", "file", "http", "jar", "resource"};
71 :
72 : class nsIPrefBranch;
73 :
74 : class nsIOService : public nsIIOService2
75 : , public nsIObserver
76 : , public nsINetUtil
77 : , public nsSupportsWeakReference
78 : {
79 : public:
80 : NS_DECL_ISUPPORTS
81 : NS_DECL_NSIIOSERVICE
82 : NS_DECL_NSIIOSERVICE2
83 : NS_DECL_NSIOBSERVER
84 : NS_DECL_NSINETUTIL
85 :
86 : // Gets the singleton instance of the IO Service, creating it as needed
87 : // Returns nsnull on out of memory or failure to initialize.
88 : // Returns an addrefed pointer.
89 : static nsIOService* GetInstance();
90 :
91 : NS_HIDDEN_(nsresult) Init();
92 : NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI,
93 : nsIURI* *result,
94 : nsIProtocolHandler* *hdlrResult);
95 :
96 : // Called by channels before a redirect happens. This notifies the global
97 : // redirect observers.
98 : nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
99 : PRUint32 flags,
100 : nsAsyncRedirectVerifyHelper *helper);
101 :
102 : // Gets the array of registered content sniffers
103 8 : const nsCOMArray<nsIContentSniffer>& GetContentSniffers() {
104 8 : return mContentSniffers.GetEntries();
105 : }
106 :
107 14067 : bool IsOffline() { return mOffline; }
108 : bool IsLinkUp();
109 :
110 4271 : bool IsComingOnline() const {
111 4271 : return mOffline && mSettingOffline && !mSetOfflineValue;
112 : }
113 :
114 : private:
115 : // These shouldn't be called directly:
116 : // - construct using GetInstance
117 : // - destroy using Release
118 : nsIOService() NS_HIDDEN;
119 : ~nsIOService() NS_HIDDEN;
120 :
121 : NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline();
122 :
123 : NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme,
124 : nsIProtocolHandler* *hdlrResult,
125 : PRUint32 start=0,
126 : PRUint32 end=0);
127 : NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme,
128 : nsIProtocolHandler* hdlr);
129 :
130 : // Prefs wrangling
131 : NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nsnull);
132 : NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch **);
133 : NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
134 :
135 : nsresult InitializeSocketTransportService();
136 : nsresult InitializeNetworkLinkService();
137 :
138 : private:
139 : bool mOffline;
140 : bool mOfflineForProfileChange;
141 : bool mManageOfflineStatus;
142 :
143 : // Used to handle SetOffline() reentrancy. See the comment in
144 : // SetOffline() for more details.
145 : bool mSettingOffline;
146 : bool mSetOfflineValue;
147 :
148 : bool mShutdown;
149 :
150 : nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
151 : nsCOMPtr<nsPIDNSService> mDNSService;
152 : nsCOMPtr<nsIProtocolProxyService2> mProxyService;
153 : nsCOMPtr<nsINetworkLinkService> mNetworkLinkService;
154 : bool mNetworkLinkServiceInitialized;
155 :
156 : // Cached protocol handlers
157 : nsWeakPtr mWeakHandler[NS_N(gScheme)];
158 :
159 : // cached categories
160 : nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
161 : nsCategoryCache<nsIContentSniffer> mContentSniffers;
162 :
163 : nsTArray<PRInt32> mRestrictedPortList;
164 :
165 : bool mAutoDialEnabled;
166 : public:
167 : // Used for all default buffer sizes that necko allocates.
168 : static PRUint32 gDefaultSegmentSize;
169 : static PRUint32 gDefaultSegmentCount;
170 : };
171 :
172 : /**
173 : * Reference to the IO service singleton. May be null.
174 : */
175 : extern nsIOService* gIOService;
176 :
177 : #endif // nsIOService_h__
|