michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsIOService_h__ michael@0: #define nsIOService_h__ michael@0: michael@0: #include "nsStringFwd.h" michael@0: #include "nsIIOService2.h" michael@0: #include "nsTArray.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsWeakPtr.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsINetUtil.h" michael@0: #include "nsIChannelEventSink.h" michael@0: #include "nsCategoryCache.h" michael@0: #include "nsISpeculativeConnect.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #define NS_N(x) (sizeof(x)/sizeof(*x)) michael@0: michael@0: // We don't want to expose this observer topic. michael@0: // Intended internal use only for remoting offline/inline events. michael@0: // See Bug 552829 michael@0: #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline" michael@0: michael@0: static const char gScheme[][sizeof("resource")] = michael@0: {"chrome", "file", "http", "jar", "resource"}; michael@0: michael@0: class nsAsyncRedirectVerifyHelper; michael@0: class nsINetworkLinkService; michael@0: class nsIPrefBranch; michael@0: class nsIProtocolProxyService2; michael@0: class nsIProxyInfo; michael@0: class nsPIDNSService; michael@0: class nsPISocketTransportService; michael@0: michael@0: class nsIOService MOZ_FINAL : public nsIIOService2 michael@0: , public nsIObserver michael@0: , public nsINetUtil michael@0: , public nsISpeculativeConnect michael@0: , public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIIOSERVICE michael@0: NS_DECL_NSIIOSERVICE2 michael@0: NS_DECL_NSIOBSERVER michael@0: NS_DECL_NSINETUTIL michael@0: NS_DECL_NSISPECULATIVECONNECT michael@0: michael@0: // Gets the singleton instance of the IO Service, creating it as needed michael@0: // Returns nullptr on out of memory or failure to initialize. michael@0: // Returns an addrefed pointer. michael@0: static nsIOService* GetInstance(); michael@0: michael@0: NS_HIDDEN_(nsresult) Init(); michael@0: NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI, michael@0: nsIURI* *result, michael@0: nsIProtocolHandler* *hdlrResult); michael@0: michael@0: // Called by channels before a redirect happens. This notifies the global michael@0: // redirect observers. michael@0: nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan, michael@0: uint32_t flags, michael@0: nsAsyncRedirectVerifyHelper *helper); michael@0: michael@0: bool IsOffline() { return mOffline; } michael@0: bool IsLinkUp(); michael@0: michael@0: bool IsComingOnline() const { michael@0: return mOffline && mSettingOffline && !mSetOfflineValue; michael@0: } michael@0: michael@0: private: michael@0: // These shouldn't be called directly: michael@0: // - construct using GetInstance michael@0: // - destroy using Release michael@0: nsIOService() NS_HIDDEN; michael@0: ~nsIOService() NS_HIDDEN; michael@0: michael@0: NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline(); michael@0: michael@0: NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme, michael@0: nsIProtocolHandler* *hdlrResult, michael@0: uint32_t start=0, michael@0: uint32_t end=0); michael@0: NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme, michael@0: nsIProtocolHandler* hdlr); michael@0: michael@0: // Prefs wrangling michael@0: NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr); michael@0: NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch **); michael@0: NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove); michael@0: michael@0: nsresult InitializeSocketTransportService(); michael@0: nsresult InitializeNetworkLinkService(); michael@0: michael@0: // consolidated helper function michael@0: void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags, michael@0: nsCString *aScheme, nsIProxyInfo **outPI); michael@0: michael@0: private: michael@0: bool mOffline; michael@0: bool mOfflineForProfileChange; michael@0: bool mManageOfflineStatus; michael@0: michael@0: // Used to handle SetOffline() reentrancy. See the comment in michael@0: // SetOffline() for more details. michael@0: bool mSettingOffline; michael@0: bool mSetOfflineValue; michael@0: michael@0: bool mShutdown; michael@0: michael@0: nsCOMPtr mSocketTransportService; michael@0: nsCOMPtr mDNSService; michael@0: nsCOMPtr mProxyService; michael@0: nsCOMPtr mNetworkLinkService; michael@0: bool mNetworkLinkServiceInitialized; michael@0: michael@0: // Cached protocol handlers michael@0: nsWeakPtr mWeakHandler[NS_N(gScheme)]; michael@0: michael@0: // cached categories michael@0: nsCategoryCache mChannelEventSinks; michael@0: michael@0: nsTArray mRestrictedPortList; michael@0: michael@0: bool mAutoDialEnabled; michael@0: public: michael@0: // Used for all default buffer sizes that necko allocates. michael@0: static uint32_t gDefaultSegmentSize; michael@0: static uint32_t gDefaultSegmentCount; michael@0: }; michael@0: michael@0: /** michael@0: * Reference to the IO service singleton. May be null. michael@0: */ michael@0: extern nsIOService* gIOService; michael@0: michael@0: #endif // nsIOService_h__