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/. */
|
2002-09-02 04:14:20 +04:00
|
|
|
|
|
|
|
#ifndef nsPrefetchService_h__
|
|
|
|
#define nsPrefetchService_h__
|
|
|
|
|
|
|
|
#include "nsIObserver.h"
|
2005-06-30 00:57:34 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
2018-12-17 04:27:58 +03:00
|
|
|
#include "nsIPrefetchService.h"
|
2012-07-31 22:59:17 +04:00
|
|
|
#include "nsIRedirectResultListener.h"
|
2002-09-02 04:14:20 +04:00
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-06-13 07:53:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-02-22 12:29:00 +03:00
|
|
|
#include <deque>
|
2002-09-02 04:14:20 +04:00
|
|
|
|
|
|
|
class nsPrefetchService;
|
|
|
|
class nsPrefetchNode;
|
2019-07-19 14:42:09 +03:00
|
|
|
class nsIReferrerInfo;
|
2002-09-02 04:14:20 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsPrefetchService
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsPrefetchService final : public nsIPrefetchService,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIWebProgressListener,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsSupportsWeakReference {
|
2002-09-02 04:14:20 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPREFETCHSERVICE
|
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
|
|
|
NS_DECL_NSIOBSERVER
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-09-02 04:14:20 +04:00
|
|
|
nsPrefetchService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-09-02 04:14:20 +04:00
|
|
|
nsresult Init();
|
2017-07-10 16:05:23 +03:00
|
|
|
void RemoveNodeAndMaybeStartNextPrefetchURI(nsPrefetchNode* aFinished);
|
|
|
|
void ProcessNextPrefetchURI();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-07-09 10:19:27 +04:00
|
|
|
void NotifyLoadRequested(nsPrefetchNode* node);
|
|
|
|
void NotifyLoadCompleted(nsPrefetchNode* node);
|
2016-08-12 10:09:05 +03:00
|
|
|
void DispatchEvent(nsPrefetchNode* node, bool aSuccess);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-09-02 04:14:20 +04:00
|
|
|
private:
|
2005-06-30 00:57:34 +04:00
|
|
|
~nsPrefetchService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-19 14:42:09 +03:00
|
|
|
nsresult Prefetch(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo,
|
|
|
|
nsINode* aSource, bool aExplicit);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-19 14:42:09 +03:00
|
|
|
nsresult Preload(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo,
|
|
|
|
nsINode* aSource, nsContentPolicyType aPolicyType);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-28 01:23:28 +03:00
|
|
|
void AddProgressListener();
|
|
|
|
void RemoveProgressListener();
|
2019-07-19 14:42:09 +03:00
|
|
|
nsresult EnqueueURI(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo,
|
|
|
|
nsINode* aSource, nsPrefetchNode** node);
|
2017-07-10 16:05:23 +03:00
|
|
|
void EmptyPrefetchQueue();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-09-02 04:14:20 +04:00
|
|
|
void StartPrefetching();
|
|
|
|
void StopPrefetching();
|
2017-07-10 16:05:23 +03:00
|
|
|
void StopCurrentPrefetchsPreloads(bool aPreload);
|
|
|
|
void StopAll();
|
2019-07-19 14:42:09 +03:00
|
|
|
nsresult CheckURIScheme(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-10 16:05:23 +03:00
|
|
|
std::deque<RefPtr<nsPrefetchNode>> mPrefetchQueue;
|
2016-02-22 12:29:00 +03:00
|
|
|
nsTArray<RefPtr<nsPrefetchNode>> mCurrentNodes;
|
|
|
|
int32_t mMaxParallelism;
|
|
|
|
int32_t mStopCount;
|
2017-07-10 16:05:23 +03:00
|
|
|
bool mHaveProcessed;
|
|
|
|
bool mPrefetchDisabled;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-12 10:09:05 +03:00
|
|
|
// In usual case prefetch does not start until all normal loads are done.
|
|
|
|
// Aggressive mode ignores normal loads and just start prefetch ASAP.
|
|
|
|
// It's mainly for testing purpose and discoraged for normal use;
|
|
|
|
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1281415 for details.
|
|
|
|
bool mAggressive;
|
2002-09-02 04:14:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-07-10 16:05:23 +03:00
|
|
|
// nsPreFetchingNode
|
2002-09-02 04:14:20 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsPrefetchNode final : public nsIStreamListener,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIRedirectResultListener {
|
2002-09-02 04:14:20 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2005-06-30 00:57:34 +04:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2012-07-31 22:59:17 +04:00
|
|
|
NS_DECL_NSIREDIRECTRESULTLISTENER
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-07-09 10:19:27 +04:00
|
|
|
nsPrefetchNode(nsPrefetchService* aPrefetchService, nsIURI* aURI,
|
2019-07-19 14:42:09 +03:00
|
|
|
nsIReferrerInfo* aReferrerInfo, nsINode* aSource,
|
2017-07-10 16:05:23 +03:00
|
|
|
nsContentPolicyType aPolicyType, bool aPreload);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-07-09 10:19:27 +04:00
|
|
|
nsresult OpenChannel();
|
|
|
|
nsresult CancelChannel(nsresult error);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-26 04:41:00 +03:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2019-07-19 14:42:09 +03:00
|
|
|
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
2018-10-31 23:39:03 +03:00
|
|
|
nsTArray<nsWeakPtr> mSources;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-10 16:05:23 +03:00
|
|
|
// The policy type to be used for fetching the resource.
|
|
|
|
nsContentPolicyType mPolicyType;
|
|
|
|
// nsPrefetchNode is used for prefetching and preloading resource.
|
|
|
|
// mPreload is true if a resource is preloaded. Preloads and
|
|
|
|
// prefetches are fetched in different phases (during load and
|
|
|
|
// after a page load), therefore we need to distinguish them.
|
|
|
|
bool mPreload;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-07-09 10:19:27 +04:00
|
|
|
private:
|
2014-06-23 22:49:09 +04:00
|
|
|
~nsPrefetchNode() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-22 12:29:00 +03:00
|
|
|
RefPtr<nsPrefetchService> mService;
|
2007-07-09 10:19:27 +04:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2012-07-31 22:59:17 +04:00
|
|
|
nsCOMPtr<nsIChannel> mRedirectChannel;
|
2012-10-22 21:51:07 +04:00
|
|
|
int64_t mBytesRead;
|
2016-08-12 10:09:05 +03:00
|
|
|
bool mShouldFireLoadEvent;
|
2002-09-02 04:14:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !nsPrefetchService_h__
|