2012-05-21 11:12:37 +00: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/. */
|
2002-09-02 00:14:20 +00:00
|
|
|
|
|
|
|
#ifndef nsPrefetchService_h__
|
|
|
|
#define nsPrefetchService_h__
|
|
|
|
|
|
|
|
#include "nsCPrefetchService.h"
|
|
|
|
#include "nsIObserver.h"
|
2005-06-29 20:57:34 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
2012-07-31 18:59:17 +00:00
|
|
|
#include "nsIRedirectResultListener.h"
|
2002-09-02 00:14:20 +00:00
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2007-07-09 06:19:27 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2012-06-13 03:53:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-02-22 09:29:00 +00:00
|
|
|
#include <deque>
|
2002-09-02 00:14:20 +00:00
|
|
|
|
|
|
|
class nsPrefetchService;
|
|
|
|
class nsPrefetchNode;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsPrefetchService
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsPrefetchService final : public nsIPrefetchService
|
2015-03-27 18:52:19 +00:00
|
|
|
, public nsIWebProgressListener
|
|
|
|
, public nsIObserver
|
|
|
|
, public nsSupportsWeakReference
|
2002-09-02 00:14:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPREFETCHSERVICE
|
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsPrefetchService();
|
|
|
|
|
|
|
|
nsresult Init();
|
2015-10-19 19:46:57 +00:00
|
|
|
void ProcessNextURI(nsPrefetchNode *aFinished);
|
2007-07-09 06:19:27 +00:00
|
|
|
|
|
|
|
void NotifyLoadRequested(nsPrefetchNode *node);
|
|
|
|
void NotifyLoadCompleted(nsPrefetchNode *node);
|
2002-09-02 00:14:20 +00:00
|
|
|
|
|
|
|
private:
|
2005-06-29 20:57:34 +00:00
|
|
|
~nsPrefetchService();
|
2002-09-02 00:14:20 +00:00
|
|
|
|
2007-03-14 01:52:07 +00:00
|
|
|
nsresult Prefetch(nsIURI *aURI,
|
|
|
|
nsIURI *aReferrerURI,
|
2007-07-09 06:19:27 +00:00
|
|
|
nsIDOMNode *aSource,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aExplicit);
|
2007-03-14 01:52:07 +00:00
|
|
|
|
2003-01-27 22:23:28 +00:00
|
|
|
void AddProgressListener();
|
|
|
|
void RemoveProgressListener();
|
2007-07-09 06:19:27 +00:00
|
|
|
nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI,
|
2008-08-25 03:37:10 +00:00
|
|
|
nsIDOMNode *aSource, nsPrefetchNode **node);
|
|
|
|
void EmptyQueue();
|
2007-05-14 20:09:20 +00:00
|
|
|
|
2002-09-02 00:14:20 +00:00
|
|
|
void StartPrefetching();
|
|
|
|
void StopPrefetching();
|
|
|
|
|
2016-02-22 09:29:00 +00:00
|
|
|
std::deque<RefPtr<nsPrefetchNode>> mQueue;
|
|
|
|
nsTArray<RefPtr<nsPrefetchNode>> mCurrentNodes;
|
|
|
|
int32_t mMaxParallelism;
|
|
|
|
int32_t mStopCount;
|
2007-05-29 09:45:30 +00:00
|
|
|
// true if pending document loads have ever reached zero.
|
2016-02-22 09:29:00 +00:00
|
|
|
int32_t mHaveProcessed;
|
|
|
|
bool mDisabled;
|
2002-09-02 00:14:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2007-07-09 06:19:27 +00:00
|
|
|
// nsPrefetchNode
|
2002-09-02 00:14:20 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsPrefetchNode final : public nsIStreamListener
|
2015-03-27 18:52:19 +00:00
|
|
|
, public nsIInterfaceRequestor
|
|
|
|
, public nsIChannelEventSink
|
|
|
|
, public nsIRedirectResultListener
|
2002-09-02 00:14:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2005-06-29 20:57:34 +00:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2012-07-31 18:59:17 +00:00
|
|
|
NS_DECL_NSIREDIRECTRESULTLISTENER
|
2002-09-02 00:14:20 +00:00
|
|
|
|
2007-07-09 06:19:27 +00:00
|
|
|
nsPrefetchNode(nsPrefetchService *aPrefetchService,
|
|
|
|
nsIURI *aURI,
|
|
|
|
nsIURI *aReferrerURI,
|
2008-08-25 03:37:10 +00:00
|
|
|
nsIDOMNode *aSource);
|
2005-06-29 20:57:34 +00:00
|
|
|
|
2007-07-09 06:19:27 +00:00
|
|
|
nsresult OpenChannel();
|
|
|
|
nsresult CancelChannel(nsresult error);
|
2002-09-02 00:14:20 +00:00
|
|
|
|
2016-02-26 01:41:00 +00:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsCOMPtr<nsIURI> mReferrerURI;
|
|
|
|
nsTArray<nsCOMPtr<nsIWeakReference>> mSources;
|
2002-09-02 00:14:20 +00:00
|
|
|
|
2007-07-09 06:19:27 +00:00
|
|
|
private:
|
2014-06-23 18:49:09 +00:00
|
|
|
~nsPrefetchNode() {}
|
|
|
|
|
2016-02-22 09:29:00 +00:00
|
|
|
RefPtr<nsPrefetchService> mService;
|
2007-07-09 06:19:27 +00:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2012-07-31 18:59:17 +00:00
|
|
|
nsCOMPtr<nsIChannel> mRedirectChannel;
|
2012-10-22 17:51:07 +00:00
|
|
|
int64_t mBytesRead;
|
2002-09-02 00:14:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !nsPrefetchService_h__
|