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__
|
|
|
|
|
|
|
|
#include "necko-config.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIIOService2.h"
|
2009-02-22 17:05:28 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPISocketTransportService.h"
|
|
|
|
#include "nsPIDNSService.h"
|
|
|
|
#include "nsIProtocolProxyService2.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsURLHelper.h"
|
|
|
|
#include "nsWeakPtr.h"
|
|
|
|
#include "nsIURLParser.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsINetUtil.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIContentSniffer.h"
|
|
|
|
#include "nsCategoryCache.h"
|
|
|
|
#include "nsINetworkLinkService.h"
|
2010-08-04 19:15:55 -07:00
|
|
|
#include "nsAsyncRedirectVerifyHelper.h"
|
2012-04-25 05:54:42 -07:00
|
|
|
#include "nsISpeculativeConnect.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"};
|
|
|
|
|
|
|
|
class nsIPrefBranch;
|
|
|
|
|
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:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
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();
|
|
|
|
|
|
|
|
NS_HIDDEN_(nsresult) Init();
|
|
|
|
NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI,
|
|
|
|
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,
|
|
|
|
PRUint32 flags,
|
|
|
|
nsAsyncRedirectVerifyHelper *helper);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Gets the array of registered content sniffers
|
2007-07-24 16:47:33 -07:00
|
|
|
const nsCOMArray<nsIContentSniffer>& GetContentSniffers() {
|
2007-03-22 10:30:00 -07:00
|
|
|
return mContentSniffers.GetEntries();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
// These shouldn't be called directly:
|
|
|
|
// - construct using GetInstance
|
|
|
|
// - destroy using Release
|
|
|
|
nsIOService() NS_HIDDEN;
|
|
|
|
~nsIOService() NS_HIDDEN;
|
|
|
|
|
|
|
|
NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline();
|
|
|
|
|
|
|
|
NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme,
|
|
|
|
nsIProtocolHandler* *hdlrResult,
|
|
|
|
PRUint32 start=0,
|
|
|
|
PRUint32 end=0);
|
|
|
|
NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme,
|
|
|
|
nsIProtocolHandler* hdlr);
|
|
|
|
|
|
|
|
// Prefs wrangling
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr);
|
2012-01-16 17:48:29 -08:00
|
|
|
NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch **);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_HIDDEN_(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
|
|
|
|
void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, PRUint32 aProxyFlags,
|
|
|
|
nsCString *aScheme, nsIProxyInfo **outPI);
|
|
|
|
|
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;
|
|
|
|
nsCategoryCache<nsIContentSniffer> mContentSniffers;
|
|
|
|
|
2009-02-22 17:05:28 -08:00
|
|
|
nsTArray<PRInt32> mRestrictedPortList;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAutoDialEnabled;
|
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.
|
2010-04-20 09:32:28 -07:00
|
|
|
static PRUint32 gDefaultSegmentSize;
|
|
|
|
static PRUint32 gDefaultSegmentCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to the IO service singleton. May be null.
|
|
|
|
*/
|
|
|
|
extern nsIOService* gIOService;
|
|
|
|
|
|
|
|
#endif // nsIOService_h__
|