michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsPrefetchService_h__ michael@0: #define nsPrefetchService_h__ michael@0: michael@0: #include "nsCPrefetchService.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsIChannelEventSink.h" michael@0: #include "nsIRedirectResultListener.h" michael@0: #include "nsIWebProgressListener.h" michael@0: #include "nsIStreamListener.h" michael@0: #include "nsIChannel.h" michael@0: #include "nsIURI.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsPrefetchService; michael@0: class nsPrefetchListener; michael@0: class nsPrefetchNode; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // nsPrefetchService michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: class nsPrefetchService MOZ_FINAL : public nsIPrefetchService michael@0: , public nsIWebProgressListener michael@0: , public nsIObserver michael@0: , public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIPREFETCHSERVICE michael@0: NS_DECL_NSIWEBPROGRESSLISTENER michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: nsPrefetchService(); michael@0: michael@0: nsresult Init(); michael@0: void ProcessNextURI(); michael@0: michael@0: nsPrefetchNode *GetCurrentNode() { return mCurrentNode.get(); } michael@0: nsPrefetchNode *GetQueueHead() { return mQueueHead; } michael@0: michael@0: void NotifyLoadRequested(nsPrefetchNode *node); michael@0: void NotifyLoadCompleted(nsPrefetchNode *node); michael@0: michael@0: private: michael@0: ~nsPrefetchService(); michael@0: michael@0: nsresult Prefetch(nsIURI *aURI, michael@0: nsIURI *aReferrerURI, michael@0: nsIDOMNode *aSource, michael@0: bool aExplicit); michael@0: michael@0: void AddProgressListener(); michael@0: void RemoveProgressListener(); michael@0: nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI, michael@0: nsIDOMNode *aSource, nsPrefetchNode **node); michael@0: nsresult EnqueueNode(nsPrefetchNode *node); michael@0: nsresult DequeueNode(nsPrefetchNode **node); michael@0: void EmptyQueue(); michael@0: michael@0: void StartPrefetching(); michael@0: void StopPrefetching(); michael@0: michael@0: nsPrefetchNode *mQueueHead; michael@0: nsPrefetchNode *mQueueTail; michael@0: nsRefPtr mCurrentNode; michael@0: int32_t mStopCount; michael@0: // true if pending document loads have ever reached zero. michael@0: int32_t mHaveProcessed; michael@0: bool mDisabled; michael@0: }; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // nsPrefetchNode michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: class nsPrefetchNode MOZ_FINAL : public nsIStreamListener michael@0: , public nsIInterfaceRequestor michael@0: , public nsIChannelEventSink michael@0: , public nsIRedirectResultListener michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSISTREAMLISTENER michael@0: NS_DECL_NSIINTERFACEREQUESTOR michael@0: NS_DECL_NSICHANNELEVENTSINK michael@0: NS_DECL_NSIREDIRECTRESULTLISTENER michael@0: michael@0: nsPrefetchNode(nsPrefetchService *aPrefetchService, michael@0: nsIURI *aURI, michael@0: nsIURI *aReferrerURI, michael@0: nsIDOMNode *aSource); michael@0: michael@0: ~nsPrefetchNode() {} michael@0: michael@0: nsresult OpenChannel(); michael@0: nsresult CancelChannel(nsresult error); michael@0: michael@0: nsPrefetchNode *mNext; michael@0: nsCOMPtr mURI; michael@0: nsCOMPtr mReferrerURI; michael@0: nsCOMPtr mSource; michael@0: michael@0: private: michael@0: nsRefPtr mService; michael@0: nsCOMPtr mChannel; michael@0: nsCOMPtr mRedirectChannel; michael@0: int64_t mBytesRead; michael@0: }; michael@0: michael@0: #endif // !nsPrefetchService_h__