Files
palemoon27/netwerk/base/nsIOService.h
T
roytam1 7254e4308f import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1048131 - Remove MOZ_CAPTIVEDETECT and enable captive portal detector for all products. r=mcmanus (d2b2980c1)
- Bug 1048131 - Implement CaptivePortalService using nsICaptivePortalDetector r=mcmanus (d62c390d4)
- Bug 1048131 - Make some network events trigger a captive portal recheck r=mcmanus (8c19273f0)
- Bug 1166910 - Gecko changes for adding referrer attribute. r=hsivonen (46676ae77)
- Bug 1166910 - Referrer attribute for img tag. r=ckerschb, r=hsivonen, r=bz (f833f3e6c)
- Bug 1174913 - anchor and area referrer attributes. r=ckerschb, r=bz (f99a956be) (backend parts only)
- missing bits of Bug 1210302 - Part 1: Rename nsINetUtil.parseContentType() to parseResponseContentType(); r=mcmanus (eb8fba336)
- Bug 1210302 - Part 2: Rename NS_ParseContentType to NS_ParseResponseContentType; r=mcmanus,sicking (74f4cd98d)
- remaining bits of Bug 1210302 - Part 3: Add a NS_ParseRequestContentType API; r=mcmanus,sicking (56477b434)
- pointer style (ca5142301)
- Bug 1172109 - Name some anonymous structs to help out the analysis, r=terrence (775d17318)
- Bug 1173042 - Remove unused GCChunkSet and chunk hashing functions; r=ehoogeveen (357e0887d)
- Bug 1177778 - Allow HeapPtr destruction while shutting down the GC r=terrence (793654cb2)
- Bug 1181306 - Skip compacting phase when finishing an incremental GC non-incrementally r=terrence (7547c11ad)
- Bug 1162961 - Fix logspam in mochitest-dt by passing the URL along in network progress events;r=past (3b4c9048f)
- Bug 1149235 part 1. Move nsScriptLoadRequest into nsScriptLoader.h. r=sicking (df56a3e9d)
- Bug 1149235 part 2. Switch to using linked lists for nsScriptLoadRequest. r=sicking (7a0536b53)
- Bug 1149235 part 3. Store async requests in the scriptloader in two lists, so we don't have to grovel about looking for loaded ones. r=sicking (db45689c6)
- Bug 1154598. Keep better track of our script requests. r=smaug (a2232a237)
- Bug 1157995 - Tell the cycle collector about Navigator::mMediaDevices. r=smaug (9a9147bdf)
- Bug 1181619. Make sure we've entered a microtask before we call nsJSUtils::EvaluateString, and put those microtasks outside the relevant AutoEntryScripts so we report any possible exceptions before doing the microtask checkpoint. r=bholley (851e371ac)
2021-06-02 10:13:46 +08:00

217 lines
7.6 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#ifndef nsIOService_h__
#define nsIOService_h__
#include "nsStringFwd.h"
#include "nsIIOService2.h"
#include "nsTArray.h"
#include "nsCOMPtr.h"
#include "nsWeakPtr.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsINetUtil.h"
#include "nsIChannelEventSink.h"
#include "nsCategoryCache.h"
#include "nsISpeculativeConnect.h"
#include "nsDataHashtable.h"
#include "mozilla/Attributes.h"
#include "nsICaptivePortalService.h"
#define NS_N(x) (sizeof(x)/sizeof(*x))
// We don't want to expose this observer topic.
// Intended internal use only for remoting offline/inline events.
// See Bug 552829
#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
#define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
static const char gScheme[][sizeof("resource")] =
{"chrome", "file", "http", "https", "jar", "data", "resource"};
class nsAsyncRedirectVerifyHelper;
class nsINetworkLinkService;
class nsIPrefBranch;
class nsIProtocolProxyService2;
class nsIProxyInfo;
class nsPIDNSService;
class nsPISocketTransportService;
namespace mozilla {
namespace net {
class NeckoChild;
} // namespace net
} // namespace mozilla
class nsIOService final : public nsIIOService2
, public nsIObserver
, public nsINetUtil
, public nsISpeculativeConnect
, public nsSupportsWeakReference
, public nsIIOServiceInternal
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIIOSERVICE
NS_DECL_NSIIOSERVICE2
NS_DECL_NSIOBSERVER
NS_DECL_NSINETUTIL
NS_DECL_NSISPECULATIVECONNECT
NS_DECL_NSIIOSERVICEINTERNAL
// Gets the singleton instance of the IO Service, creating it as needed
// Returns nullptr on out of memory or failure to initialize.
// Returns an addrefed pointer.
static nsIOService* GetInstance();
nsresult Init();
nsresult NewURI(const char* aSpec, nsIURI* aBaseURI,
nsIURI* *result,
nsIProtocolHandler* *hdlrResult);
// Called by channels before a redirect happens. This notifies the global
// redirect observers.
nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
uint32_t flags,
nsAsyncRedirectVerifyHelper *helper);
bool IsOffline() { return mOffline; }
bool IsLinkUp();
// Should only be called from NeckoChild. Use SetAppOffline instead.
void SetAppOfflineInternal(uint32_t appId, int32_t status);
private:
// These shouldn't be called directly:
// - construct using GetInstance
// - destroy using Release
nsIOService();
~nsIOService();
nsresult SetConnectivityInternal(bool aConnectivity);
nsresult OnNetworkLinkEvent(const char *data);
nsresult GetCachedProtocolHandler(const char *scheme,
nsIProtocolHandler* *hdlrResult,
uint32_t start=0,
uint32_t end=0);
nsresult CacheProtocolHandler(const char *scheme,
nsIProtocolHandler* hdlr);
nsresult InitializeCaptivePortalService();
nsresult RecheckCaptivePortalIfLocalRedirect(nsIChannel* newChan);
// Prefs wrangling
void PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr);
void GetPrefBranch(nsIPrefBranch **);
void ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
nsresult InitializeSocketTransportService();
nsresult InitializeNetworkLinkService();
// consolidated helper function
void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
nsCString *aScheme, nsIProxyInfo **outPI);
// notify content processes of offline status
// 'status' must be a nsIAppOfflineInfo mode constant.
void NotifyAppOfflineStatus(uint32_t appId, int32_t status);
static PLDHashOperator EnumerateWifiAppsChangingState(const unsigned int &, int32_t, void*);
nsresult NewChannelFromURIWithProxyFlagsInternal(nsIURI* aURI,
nsIURI* aProxyURI,
uint32_t aProxyFlags,
nsILoadInfo* aLoadInfo,
nsIChannel** result);
nsresult SpeculativeConnectInternal(nsIURI *aURI,
nsIInterfaceRequestor *aCallbacks,
bool aAnonymous);
private:
bool mOffline;
bool mOfflineForProfileChange;
bool mManageLinkStatus;
bool mConnectivity;
// If true, the connectivity state will be mirrored by IOService.offline
// meaning if !mConnectivity, GetOffline() will return true
bool mOfflineMirrorsConnectivity;
// Used to handle SetOffline() reentrancy. See the comment in
// SetOffline() for more details.
bool mSettingOffline;
bool mSetOfflineValue;
bool mShutdown;
nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
nsCOMPtr<nsPIDNSService> mDNSService;
nsCOMPtr<nsIProtocolProxyService2> mProxyService;
nsCOMPtr<nsICaptivePortalService> mCaptivePortalService;
nsCOMPtr<nsINetworkLinkService> mNetworkLinkService;
bool mNetworkLinkServiceInitialized;
// Cached protocol handlers
nsWeakPtr mWeakHandler[NS_N(gScheme)];
// cached categories
nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
nsTArray<int32_t> mRestrictedPortList;
bool mAutoDialEnabled;
bool mNetworkNotifyChanged;
int32_t mPreviousWifiState;
// Hashtable of (appId, nsIAppOffineInfo::mode) pairs
// that is used especially in IsAppOffline
nsDataHashtable<nsUint32HashKey, int32_t> mAppsOfflineStatus;
public:
// Used for all default buffer sizes that necko allocates.
static uint32_t gDefaultSegmentSize;
static uint32_t gDefaultSegmentCount;
};
/**
* This class is passed as the subject to a NotifyObservers call for the
* "network:app-offline-status-changed" topic.
* Observers will use the appId and mode to get the offline status of an app.
*/
class nsAppOfflineInfo : public nsIAppOfflineInfo
{
NS_DECL_THREADSAFE_ISUPPORTS
public:
nsAppOfflineInfo(uint32_t aAppId, int32_t aMode)
: mAppId(aAppId), mMode(aMode)
{
}
NS_IMETHODIMP GetMode(int32_t *aMode) override
{
*aMode = mMode;
return NS_OK;
}
NS_IMETHODIMP GetAppId(uint32_t *aAppId) override
{
*aAppId = mAppId;
return NS_OK;
}
private:
virtual ~nsAppOfflineInfo() {}
uint32_t mAppId;
int32_t mMode;
};
/**
* Reference to the IO service singleton. May be null.
*/
extern nsIOService* gIOService;
#endif // nsIOService_h__