2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-06-08 01:33:30 +04:00
|
|
|
|
|
|
|
#ifndef nsIOService_h__
|
|
|
|
#define nsIOService_h__
|
|
|
|
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "nsStringFwd.h"
|
2006-04-05 01:26:17 +04:00
|
|
|
#include "nsIIOService2.h"
|
2009-02-23 04:05:28 +03:00
|
|
|
#include "nsTArray.h"
|
2000-01-19 10:58:40 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2000-08-22 10:16:50 +04:00
|
|
|
#include "nsWeakPtr.h"
|
2001-10-09 02:27:14 +04:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
2005-07-26 00:27:04 +04:00
|
|
|
#include "nsINetUtil.h"
|
2006-02-22 17:07:21 +03:00
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsCategoryCache.h"
|
2012-04-25 16:54:42 +04:00
|
|
|
#include "nsISpeculativeConnect.h"
|
2014-08-23 07:05:56 +04:00
|
|
|
#include "nsDataHashtable.h"
|
2015-07-07 12:13:00 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-07-07 12:13:00 +03:00
|
|
|
#include "prtime.h"
|
2014-10-14 01:35:51 +04:00
|
|
|
#include "nsICaptivePortalService.h"
|
2000-08-22 10:16:50 +04:00
|
|
|
|
|
|
|
#define NS_N(x) (sizeof(x)/sizeof(*x))
|
2003-04-23 07:47:43 +04:00
|
|
|
|
2010-05-11 16:44:12 +04:00
|
|
|
// We don't want to expose this observer topic.
|
|
|
|
// Intended internal use only for remoting offline/inline events.
|
|
|
|
// See Bug 552829
|
2010-05-11 21:22:34 +04:00
|
|
|
#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
|
2015-05-02 00:14:39 +03:00
|
|
|
#define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
|
2010-05-11 16:44:12 +04:00
|
|
|
|
2015-12-17 18:39:41 +03:00
|
|
|
static const char gScheme[][sizeof("moz-safe-about")] =
|
|
|
|
{"chrome", "file", "http", "https", "jar", "data", "about", "moz-safe-about", "resource"};
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2013-09-22 07:04:57 +04:00
|
|
|
class nsINetworkLinkService;
|
2001-10-09 02:27:14 +04:00
|
|
|
class nsIPrefBranch;
|
2013-09-22 07:04:57 +04:00
|
|
|
class nsIProtocolProxyService2;
|
|
|
|
class nsIProxyInfo;
|
|
|
|
class nsPIDNSService;
|
|
|
|
class nsPISocketTransportService;
|
2001-10-09 02:27:14 +04:00
|
|
|
|
2014-08-23 07:05:56 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
2016-05-19 05:02:57 +03:00
|
|
|
class NeckoChild;
|
|
|
|
class nsAsyncRedirectVerifyHelper;
|
2014-08-23 07:05:56 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsIOService final : public nsIIOService2
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsIObserver
|
|
|
|
, public nsINetUtil
|
|
|
|
, public nsISpeculativeConnect
|
|
|
|
, public nsSupportsWeakReference
|
2015-05-02 00:14:39 +03:00
|
|
|
, public nsIIOServiceInternal
|
1999-06-08 01:33:30 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
1999-08-23 03:52:07 +04:00
|
|
|
NS_DECL_NSIIOSERVICE
|
2006-04-05 01:26:17 +04:00
|
|
|
NS_DECL_NSIIOSERVICE2
|
2001-10-09 02:27:14 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2005-07-26 00:27:04 +04:00
|
|
|
NS_DECL_NSINETUTIL
|
2012-04-25 16:54:42 +04:00
|
|
|
NS_DECL_NSISPECULATIVECONNECT
|
2015-05-02 00:14:39 +03:00
|
|
|
NS_DECL_NSIIOSERVICEINTERNAL
|
2001-10-09 02:27:14 +04:00
|
|
|
|
2006-03-01 21:45:14 +03:00
|
|
|
// Gets the singleton instance of the IO Service, creating it as needed
|
2012-07-30 18:20:58 +04:00
|
|
|
// Returns nullptr on out of memory or failure to initialize.
|
2006-03-01 21:45:14 +03:00
|
|
|
// Returns an addrefed pointer.
|
|
|
|
static nsIOService* GetInstance();
|
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult Init();
|
|
|
|
nsresult NewURI(const char* aSpec, nsIURI* aBaseURI,
|
2004-07-02 03:31:47 +04:00
|
|
|
nsIURI* *result,
|
|
|
|
nsIProtocolHandler* *hdlrResult);
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
// Called by channels before a redirect happens. This notifies the global
|
|
|
|
// redirect observers.
|
2010-08-05 06:15:55 +04:00
|
|
|
nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags,
|
2010-08-05 06:15:55 +04:00
|
|
|
nsAsyncRedirectVerifyHelper *helper);
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsOffline() { return mOffline; }
|
2015-07-07 12:13:00 +03:00
|
|
|
PRIntervalTime LastOfflineStateChange() { return mLastOfflineStateChange; }
|
|
|
|
PRIntervalTime LastConnectivityChange() { return mLastConnectivityChange; }
|
|
|
|
PRIntervalTime LastNetworkLinkChange() { return mLastNetworkLinkChange; }
|
2016-02-04 06:14:00 +03:00
|
|
|
bool IsNetTearingDown() { return mShutdown || mOfflineForProfileChange ||
|
|
|
|
mHttpHandlerAlreadyShutingDown; }
|
2016-01-18 10:20:00 +03:00
|
|
|
PRIntervalTime NetTearingDownStarted() { return mNetTearingDownStarted; }
|
2016-02-04 06:14:00 +03:00
|
|
|
|
|
|
|
// nsHttpHandler is going to call this function to inform nsIOService that network
|
|
|
|
// is in process of tearing down. Moving nsHttpConnectionMgr::Shutdown to nsIOService
|
|
|
|
// caused problems (bug 1242755) so we doing it in this way.
|
|
|
|
// As soon as nsIOService gets notification that it is shutdown it is going to
|
|
|
|
// reset mHttpHandlerAlreadyShutingDown.
|
|
|
|
void SetHttpHandlerAlreadyShutingDown();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsLinkUp();
|
2007-03-14 04:52:07 +03:00
|
|
|
|
2017-01-26 20:40:32 +03:00
|
|
|
static bool IsInheritSecurityContextForDataURIEnabled();
|
|
|
|
|
2017-05-10 20:23:54 +03:00
|
|
|
// Used to count the total number of HTTP requests made
|
|
|
|
void IncrementRequestNumber() { mTotalRequests++; }
|
|
|
|
uint32_t GetTotalRequestNumber() { return mTotalRequests; }
|
|
|
|
// Used to keep "race cache with network" stats
|
|
|
|
void IncrementCacheWonRequestNumber() { mCacheWon++; }
|
|
|
|
uint32_t GetCacheWonRequestNumber() { return mCacheWon; }
|
|
|
|
void IncrementNetWonRequestNumber() { mNetWon++; }
|
|
|
|
uint32_t GetNetWonRequestNumber() { return mNetWon; }
|
|
|
|
|
2016-05-18 00:55:52 +03:00
|
|
|
// Used to trigger a recheck of the captive portal status
|
|
|
|
nsresult RecheckCaptivePortal();
|
2006-03-03 22:34:25 +03:00
|
|
|
private:
|
|
|
|
// These shouldn't be called directly:
|
|
|
|
// - construct using GetInstance
|
|
|
|
// - destroy using Release
|
2014-06-02 16:08:24 +04:00
|
|
|
nsIOService();
|
|
|
|
~nsIOService();
|
2015-05-02 00:14:39 +03:00
|
|
|
nsresult SetConnectivityInternal(bool aConnectivity);
|
2006-03-03 22:34:25 +03:00
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
nsresult OnNetworkLinkEvent(const char *data);
|
2006-04-05 01:26:17 +04:00
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult GetCachedProtocolHandler(const char *scheme,
|
2004-07-02 03:31:47 +04:00
|
|
|
nsIProtocolHandler* *hdlrResult,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t start=0,
|
|
|
|
uint32_t end=0);
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult CacheProtocolHandler(const char *scheme,
|
2004-07-02 03:31:47 +04:00
|
|
|
nsIProtocolHandler* hdlr);
|
2000-08-22 10:16:50 +04:00
|
|
|
|
2014-10-14 01:35:51 +04:00
|
|
|
nsresult InitializeCaptivePortalService();
|
|
|
|
nsresult RecheckCaptivePortalIfLocalRedirect(nsIChannel* newChan);
|
|
|
|
|
2001-10-09 02:27:14 +04:00
|
|
|
// Prefs wrangling
|
2014-06-02 16:08:21 +04:00
|
|
|
void PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr);
|
|
|
|
void GetPrefBranch(nsIPrefBranch **);
|
|
|
|
void ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
|
2001-10-09 02:27:14 +04:00
|
|
|
|
2010-11-25 08:20:11 +03:00
|
|
|
nsresult InitializeSocketTransportService();
|
2011-10-18 13:46:59 +04:00
|
|
|
nsresult InitializeNetworkLinkService();
|
2010-11-25 08:20:11 +03:00
|
|
|
|
2012-04-25 16:54:42 +04:00
|
|
|
// consolidated helper function
|
2012-08-22 19:56:38 +04:00
|
|
|
void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
|
2012-04-25 16:54:42 +04:00
|
|
|
nsCString *aScheme, nsIProxyInfo **outPI);
|
|
|
|
|
2014-12-13 01:24:57 +03:00
|
|
|
nsresult NewChannelFromURIWithProxyFlagsInternal(nsIURI* aURI,
|
|
|
|
nsIURI* aProxyURI,
|
|
|
|
uint32_t aProxyFlags,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** result);
|
2015-05-06 04:15:36 +03:00
|
|
|
|
|
|
|
nsresult SpeculativeConnectInternal(nsIURI *aURI,
|
2016-10-24 07:18:25 +03:00
|
|
|
nsIPrincipal *aPrincipal,
|
2015-05-06 04:15:36 +03:00
|
|
|
nsIInterfaceRequestor *aCallbacks,
|
|
|
|
bool aAnonymous);
|
|
|
|
|
2006-03-03 22:34:25 +03:00
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOffline;
|
2016-01-16 09:19:00 +03:00
|
|
|
mozilla::Atomic<bool, mozilla::Relaxed> mOfflineForProfileChange;
|
2015-05-02 00:14:39 +03:00
|
|
|
bool mManageLinkStatus;
|
|
|
|
bool mConnectivity;
|
2015-03-26 14:19:47 +03:00
|
|
|
// If true, the connectivity state will be mirrored by IOService.offline
|
|
|
|
// meaning if !mConnectivity, GetOffline() will return true
|
|
|
|
bool mOfflineMirrorsConnectivity;
|
2009-02-22 22:09:09 +03:00
|
|
|
|
|
|
|
// Used to handle SetOffline() reentrancy. See the comment in
|
|
|
|
// SetOffline() for more details.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSettingOffline;
|
|
|
|
bool mSetOfflineValue;
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2016-01-16 09:19:00 +03:00
|
|
|
mozilla::Atomic<bool, mozilla::Relaxed> mShutdown;
|
2016-02-04 06:14:00 +03:00
|
|
|
mozilla::Atomic<bool, mozilla::Relaxed> mHttpHandlerAlreadyShutingDown;
|
2009-03-18 17:52:31 +03:00
|
|
|
|
2005-04-15 03:18:34 +04:00
|
|
|
nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
|
|
|
|
nsCOMPtr<nsPIDNSService> mDNSService;
|
2006-03-30 21:31:15 +04:00
|
|
|
nsCOMPtr<nsIProtocolProxyService2> mProxyService;
|
2014-10-14 01:35:51 +04:00
|
|
|
nsCOMPtr<nsICaptivePortalService> mCaptivePortalService;
|
2006-04-05 01:26:17 +04:00
|
|
|
nsCOMPtr<nsINetworkLinkService> mNetworkLinkService;
|
2011-10-18 13:46:59 +04:00
|
|
|
bool mNetworkLinkServiceInitialized;
|
|
|
|
|
2016-08-09 14:43:00 +03:00
|
|
|
// Cached protocol handlers, only accessed on the main thread
|
2005-04-15 03:18:34 +04:00
|
|
|
nsWeakPtr mWeakHandler[NS_N(gScheme)];
|
2001-06-06 04:10:09 +04:00
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
// cached categories
|
|
|
|
nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsTArray<int32_t> mRestrictedPortList;
|
2002-07-02 22:15:19 +04:00
|
|
|
|
2014-09-19 14:36:00 +04:00
|
|
|
bool mNetworkNotifyChanged;
|
2015-02-06 16:27:33 +03:00
|
|
|
|
2017-01-26 20:40:32 +03:00
|
|
|
static bool sDataURIInheritSecurityContext;
|
|
|
|
|
2017-05-10 20:23:54 +03:00
|
|
|
uint32_t mTotalRequests;
|
|
|
|
uint32_t mCacheWon;
|
|
|
|
uint32_t mNetWon;
|
|
|
|
|
2015-07-07 12:13:00 +03:00
|
|
|
// These timestamps are needed for collecting telemetry on PR_Connect,
|
|
|
|
// PR_ConnectContinue and PR_Close blocking time. If we spend very long
|
|
|
|
// time in any of these functions we want to know if and what network
|
|
|
|
// change has happened shortly before.
|
2016-01-18 10:20:00 +03:00
|
|
|
mozilla::Atomic<PRIntervalTime> mLastOfflineStateChange;
|
|
|
|
mozilla::Atomic<PRIntervalTime> mLastConnectivityChange;
|
|
|
|
mozilla::Atomic<PRIntervalTime> mLastNetworkLinkChange;
|
|
|
|
|
|
|
|
// Time a network tearing down started.
|
|
|
|
mozilla::Atomic<PRIntervalTime> mNetTearingDownStarted;
|
2002-07-02 22:15:19 +04:00
|
|
|
public:
|
2012-01-10 07:43:52 +04:00
|
|
|
// Used for all default buffer sizes that necko allocates.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t gDefaultSegmentSize;
|
|
|
|
static uint32_t gDefaultSegmentCount;
|
1999-06-08 01:33:30 +04:00
|
|
|
};
|
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
/**
|
|
|
|
* Reference to the IO service singleton. May be null.
|
|
|
|
*/
|
|
|
|
extern nsIOService* gIOService;
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
#endif // nsIOService_h__
|