Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsIOService_h__ |
michael@0 | 7 | #define nsIOService_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsStringFwd.h" |
michael@0 | 10 | #include "nsIIOService2.h" |
michael@0 | 11 | #include "nsTArray.h" |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "nsWeakPtr.h" |
michael@0 | 14 | #include "nsIObserver.h" |
michael@0 | 15 | #include "nsWeakReference.h" |
michael@0 | 16 | #include "nsINetUtil.h" |
michael@0 | 17 | #include "nsIChannelEventSink.h" |
michael@0 | 18 | #include "nsCategoryCache.h" |
michael@0 | 19 | #include "nsISpeculativeConnect.h" |
michael@0 | 20 | #include "mozilla/Attributes.h" |
michael@0 | 21 | |
michael@0 | 22 | #define NS_N(x) (sizeof(x)/sizeof(*x)) |
michael@0 | 23 | |
michael@0 | 24 | // We don't want to expose this observer topic. |
michael@0 | 25 | // Intended internal use only for remoting offline/inline events. |
michael@0 | 26 | // See Bug 552829 |
michael@0 | 27 | #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline" |
michael@0 | 28 | |
michael@0 | 29 | static const char gScheme[][sizeof("resource")] = |
michael@0 | 30 | {"chrome", "file", "http", "jar", "resource"}; |
michael@0 | 31 | |
michael@0 | 32 | class nsAsyncRedirectVerifyHelper; |
michael@0 | 33 | class nsINetworkLinkService; |
michael@0 | 34 | class nsIPrefBranch; |
michael@0 | 35 | class nsIProtocolProxyService2; |
michael@0 | 36 | class nsIProxyInfo; |
michael@0 | 37 | class nsPIDNSService; |
michael@0 | 38 | class nsPISocketTransportService; |
michael@0 | 39 | |
michael@0 | 40 | class nsIOService MOZ_FINAL : public nsIIOService2 |
michael@0 | 41 | , public nsIObserver |
michael@0 | 42 | , public nsINetUtil |
michael@0 | 43 | , public nsISpeculativeConnect |
michael@0 | 44 | , public nsSupportsWeakReference |
michael@0 | 45 | { |
michael@0 | 46 | public: |
michael@0 | 47 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 48 | NS_DECL_NSIIOSERVICE |
michael@0 | 49 | NS_DECL_NSIIOSERVICE2 |
michael@0 | 50 | NS_DECL_NSIOBSERVER |
michael@0 | 51 | NS_DECL_NSINETUTIL |
michael@0 | 52 | NS_DECL_NSISPECULATIVECONNECT |
michael@0 | 53 | |
michael@0 | 54 | // Gets the singleton instance of the IO Service, creating it as needed |
michael@0 | 55 | // Returns nullptr on out of memory or failure to initialize. |
michael@0 | 56 | // Returns an addrefed pointer. |
michael@0 | 57 | static nsIOService* GetInstance(); |
michael@0 | 58 | |
michael@0 | 59 | NS_HIDDEN_(nsresult) Init(); |
michael@0 | 60 | NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI, |
michael@0 | 61 | nsIURI* *result, |
michael@0 | 62 | nsIProtocolHandler* *hdlrResult); |
michael@0 | 63 | |
michael@0 | 64 | // Called by channels before a redirect happens. This notifies the global |
michael@0 | 65 | // redirect observers. |
michael@0 | 66 | nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan, |
michael@0 | 67 | uint32_t flags, |
michael@0 | 68 | nsAsyncRedirectVerifyHelper *helper); |
michael@0 | 69 | |
michael@0 | 70 | bool IsOffline() { return mOffline; } |
michael@0 | 71 | bool IsLinkUp(); |
michael@0 | 72 | |
michael@0 | 73 | bool IsComingOnline() const { |
michael@0 | 74 | return mOffline && mSettingOffline && !mSetOfflineValue; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | private: |
michael@0 | 78 | // These shouldn't be called directly: |
michael@0 | 79 | // - construct using GetInstance |
michael@0 | 80 | // - destroy using Release |
michael@0 | 81 | nsIOService() NS_HIDDEN; |
michael@0 | 82 | ~nsIOService() NS_HIDDEN; |
michael@0 | 83 | |
michael@0 | 84 | NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline(); |
michael@0 | 85 | |
michael@0 | 86 | NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme, |
michael@0 | 87 | nsIProtocolHandler* *hdlrResult, |
michael@0 | 88 | uint32_t start=0, |
michael@0 | 89 | uint32_t end=0); |
michael@0 | 90 | NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme, |
michael@0 | 91 | nsIProtocolHandler* hdlr); |
michael@0 | 92 | |
michael@0 | 93 | // Prefs wrangling |
michael@0 | 94 | NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr); |
michael@0 | 95 | NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch **); |
michael@0 | 96 | NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove); |
michael@0 | 97 | |
michael@0 | 98 | nsresult InitializeSocketTransportService(); |
michael@0 | 99 | nsresult InitializeNetworkLinkService(); |
michael@0 | 100 | |
michael@0 | 101 | // consolidated helper function |
michael@0 | 102 | void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags, |
michael@0 | 103 | nsCString *aScheme, nsIProxyInfo **outPI); |
michael@0 | 104 | |
michael@0 | 105 | private: |
michael@0 | 106 | bool mOffline; |
michael@0 | 107 | bool mOfflineForProfileChange; |
michael@0 | 108 | bool mManageOfflineStatus; |
michael@0 | 109 | |
michael@0 | 110 | // Used to handle SetOffline() reentrancy. See the comment in |
michael@0 | 111 | // SetOffline() for more details. |
michael@0 | 112 | bool mSettingOffline; |
michael@0 | 113 | bool mSetOfflineValue; |
michael@0 | 114 | |
michael@0 | 115 | bool mShutdown; |
michael@0 | 116 | |
michael@0 | 117 | nsCOMPtr<nsPISocketTransportService> mSocketTransportService; |
michael@0 | 118 | nsCOMPtr<nsPIDNSService> mDNSService; |
michael@0 | 119 | nsCOMPtr<nsIProtocolProxyService2> mProxyService; |
michael@0 | 120 | nsCOMPtr<nsINetworkLinkService> mNetworkLinkService; |
michael@0 | 121 | bool mNetworkLinkServiceInitialized; |
michael@0 | 122 | |
michael@0 | 123 | // Cached protocol handlers |
michael@0 | 124 | nsWeakPtr mWeakHandler[NS_N(gScheme)]; |
michael@0 | 125 | |
michael@0 | 126 | // cached categories |
michael@0 | 127 | nsCategoryCache<nsIChannelEventSink> mChannelEventSinks; |
michael@0 | 128 | |
michael@0 | 129 | nsTArray<int32_t> mRestrictedPortList; |
michael@0 | 130 | |
michael@0 | 131 | bool mAutoDialEnabled; |
michael@0 | 132 | public: |
michael@0 | 133 | // Used for all default buffer sizes that necko allocates. |
michael@0 | 134 | static uint32_t gDefaultSegmentSize; |
michael@0 | 135 | static uint32_t gDefaultSegmentCount; |
michael@0 | 136 | }; |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Reference to the IO service singleton. May be null. |
michael@0 | 140 | */ |
michael@0 | 141 | extern nsIOService* gIOService; |
michael@0 | 142 | |
michael@0 | 143 | #endif // nsIOService_h__ |