2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsIOService_h__
|
|
|
|
#define nsIOService_h__
|
|
|
|
|
2013-09-21 20:04:57 -07:00
|
|
|
#include "nsStringFwd.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIIOService2.h"
|
2009-02-22 17:05:28 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsWeakPtr.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsINetUtil.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsCategoryCache.h"
|
2012-04-25 05:54:42 -07:00
|
|
|
#include "nsISpeculativeConnect.h"
|
2014-08-22 20:05:56 -07:00
|
|
|
#include "nsDataHashtable.h"
|
2012-06-05 20:18:25 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_N(x) (sizeof(x)/sizeof(*x))
|
|
|
|
|
2010-05-11 05:44:12 -07: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 10:22:34 -07:00
|
|
|
#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
|
2010-05-11 05:44:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const char gScheme[][sizeof("resource")] =
|
|
|
|
{"chrome", "file", "http", "jar", "resource"};
|
|
|
|
|
2013-09-21 20:04:57 -07:00
|
|
|
class nsAsyncRedirectVerifyHelper;
|
|
|
|
class nsINetworkLinkService;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIPrefBranch;
|
2013-09-21 20:04:57 -07:00
|
|
|
class nsIProtocolProxyService2;
|
|
|
|
class nsIProxyInfo;
|
|
|
|
class nsPIDNSService;
|
|
|
|
class nsPISocketTransportService;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-22 20:05:56 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
class NeckoChild;
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-06-05 20:18:25 -07:00
|
|
|
class nsIOService MOZ_FINAL : public nsIIOService2
|
|
|
|
, public nsIObserver
|
|
|
|
, public nsINetUtil
|
|
|
|
, public nsISpeculativeConnect
|
|
|
|
, public nsSupportsWeakReference
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:24:13 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIIOSERVICE
|
|
|
|
NS_DECL_NSIIOSERVICE2
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
NS_DECL_NSINETUTIL
|
2012-04-25 05:54:42 -07:00
|
|
|
NS_DECL_NSISPECULATIVECONNECT
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Gets the singleton instance of the IO Service, creating it as needed
|
2012-07-30 07:20:58 -07:00
|
|
|
// Returns nullptr on out of memory or failure to initialize.
|
2007-03-22 10:30:00 -07:00
|
|
|
// Returns an addrefed pointer.
|
|
|
|
static nsIOService* GetInstance();
|
|
|
|
|
2014-06-02 05:08:21 -07:00
|
|
|
nsresult Init();
|
|
|
|
nsresult NewURI(const char* aSpec, nsIURI* aBaseURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI* *result,
|
|
|
|
nsIProtocolHandler* *hdlrResult);
|
|
|
|
|
|
|
|
// Called by channels before a redirect happens. This notifies the global
|
|
|
|
// redirect observers.
|
2010-08-04 19:15:55 -07:00
|
|
|
nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags,
|
2010-08-04 19:15:55 -07:00
|
|
|
nsAsyncRedirectVerifyHelper *helper);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsOffline() { return mOffline; }
|
|
|
|
bool IsLinkUp();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsComingOnline() const {
|
2010-11-24 21:20:11 -08:00
|
|
|
return mOffline && mSettingOffline && !mSetOfflineValue;
|
|
|
|
}
|
|
|
|
|
2014-08-22 20:05:56 -07:00
|
|
|
// Should only be called from NeckoChild. Use SetAppOffline instead.
|
|
|
|
void SetAppOfflineInternal(uint32_t appId, int32_t status);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
// These shouldn't be called directly:
|
|
|
|
// - construct using GetInstance
|
|
|
|
// - destroy using Release
|
2014-06-02 05:08:24 -07:00
|
|
|
nsIOService();
|
|
|
|
~nsIOService();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-09-24 20:14:00 -07:00
|
|
|
nsresult OnNetworkLinkEvent(const char *data);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-02 05:08:21 -07:00
|
|
|
nsresult GetCachedProtocolHandler(const char *scheme,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIProtocolHandler* *hdlrResult,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t start=0,
|
|
|
|
uint32_t end=0);
|
2014-06-02 05:08:21 -07:00
|
|
|
nsresult CacheProtocolHandler(const char *scheme,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIProtocolHandler* hdlr);
|
|
|
|
|
|
|
|
// Prefs wrangling
|
2014-06-02 05:08:21 -07:00
|
|
|
void PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr);
|
|
|
|
void GetPrefBranch(nsIPrefBranch **);
|
|
|
|
void ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-11-24 21:20:11 -08:00
|
|
|
nsresult InitializeSocketTransportService();
|
2011-10-18 02:46:59 -07:00
|
|
|
nsresult InitializeNetworkLinkService();
|
2010-11-24 21:20:11 -08:00
|
|
|
|
2012-04-25 05:54:42 -07:00
|
|
|
// consolidated helper function
|
2012-08-22 08:56:38 -07:00
|
|
|
void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
|
2012-04-25 05:54:42 -07:00
|
|
|
nsCString *aScheme, nsIProxyInfo **outPI);
|
|
|
|
|
2014-08-22 20:05:56 -07:00
|
|
|
// 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*);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mOffline;
|
|
|
|
bool mOfflineForProfileChange;
|
|
|
|
bool mManageOfflineStatus;
|
2009-02-22 11:09:09 -08:00
|
|
|
|
|
|
|
// Used to handle SetOffline() reentrancy. See the comment in
|
|
|
|
// SetOffline() for more details.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mSettingOffline;
|
|
|
|
bool mSetOfflineValue;
|
2009-02-22 11:09:09 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mShutdown;
|
2009-03-18 07:52:31 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
|
|
|
|
nsCOMPtr<nsPIDNSService> mDNSService;
|
|
|
|
nsCOMPtr<nsIProtocolProxyService2> mProxyService;
|
|
|
|
nsCOMPtr<nsINetworkLinkService> mNetworkLinkService;
|
2011-10-18 02:46:59 -07:00
|
|
|
bool mNetworkLinkServiceInitialized;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Cached protocol handlers
|
|
|
|
nsWeakPtr mWeakHandler[NS_N(gScheme)];
|
|
|
|
|
|
|
|
// cached categories
|
|
|
|
nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTArray<int32_t> mRestrictedPortList;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAutoDialEnabled;
|
2014-09-19 03:36:00 -07:00
|
|
|
bool mNetworkNotifyChanged;
|
2014-08-22 20:05:56 -07:00
|
|
|
int32_t mPreviousWifiState;
|
|
|
|
// Hashtable of (appId, nsIAppOffineInfo::mode) pairs
|
|
|
|
// that is used especially in IsAppOffline
|
|
|
|
nsDataHashtable<nsUint32HashKey, int32_t> mAppsOfflineStatus;
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2012-01-09 19:43:52 -08:00
|
|
|
// Used for all default buffer sizes that necko allocates.
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t gDefaultSegmentSize;
|
|
|
|
static uint32_t gDefaultSegmentCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-08-22 20:05:56 -07:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
*aMode = mMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP GetAppId(uint32_t *aAppId)
|
|
|
|
{
|
|
|
|
*aAppId = mAppId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~nsAppOfflineInfo() {}
|
|
|
|
|
|
|
|
uint32_t mAppId;
|
|
|
|
int32_t mMode;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Reference to the IO service singleton. May be null.
|
|
|
|
*/
|
|
|
|
extern nsIOService* gIOService;
|
|
|
|
|
|
|
|
#endif // nsIOService_h__
|