1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/prefetch/nsPrefetchService.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef nsPrefetchService_h__ 1.9 +#define nsPrefetchService_h__ 1.10 + 1.11 +#include "nsCPrefetchService.h" 1.12 +#include "nsIObserver.h" 1.13 +#include "nsIInterfaceRequestor.h" 1.14 +#include "nsIChannelEventSink.h" 1.15 +#include "nsIRedirectResultListener.h" 1.16 +#include "nsIWebProgressListener.h" 1.17 +#include "nsIStreamListener.h" 1.18 +#include "nsIChannel.h" 1.19 +#include "nsIURI.h" 1.20 +#include "nsWeakReference.h" 1.21 +#include "nsCOMPtr.h" 1.22 +#include "nsAutoPtr.h" 1.23 +#include "mozilla/Attributes.h" 1.24 + 1.25 +class nsPrefetchService; 1.26 +class nsPrefetchListener; 1.27 +class nsPrefetchNode; 1.28 + 1.29 +//----------------------------------------------------------------------------- 1.30 +// nsPrefetchService 1.31 +//----------------------------------------------------------------------------- 1.32 + 1.33 +class nsPrefetchService MOZ_FINAL : public nsIPrefetchService 1.34 + , public nsIWebProgressListener 1.35 + , public nsIObserver 1.36 + , public nsSupportsWeakReference 1.37 +{ 1.38 +public: 1.39 + NS_DECL_ISUPPORTS 1.40 + NS_DECL_NSIPREFETCHSERVICE 1.41 + NS_DECL_NSIWEBPROGRESSLISTENER 1.42 + NS_DECL_NSIOBSERVER 1.43 + 1.44 + nsPrefetchService(); 1.45 + 1.46 + nsresult Init(); 1.47 + void ProcessNextURI(); 1.48 + 1.49 + nsPrefetchNode *GetCurrentNode() { return mCurrentNode.get(); } 1.50 + nsPrefetchNode *GetQueueHead() { return mQueueHead; } 1.51 + 1.52 + void NotifyLoadRequested(nsPrefetchNode *node); 1.53 + void NotifyLoadCompleted(nsPrefetchNode *node); 1.54 + 1.55 +private: 1.56 + ~nsPrefetchService(); 1.57 + 1.58 + nsresult Prefetch(nsIURI *aURI, 1.59 + nsIURI *aReferrerURI, 1.60 + nsIDOMNode *aSource, 1.61 + bool aExplicit); 1.62 + 1.63 + void AddProgressListener(); 1.64 + void RemoveProgressListener(); 1.65 + nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI, 1.66 + nsIDOMNode *aSource, nsPrefetchNode **node); 1.67 + nsresult EnqueueNode(nsPrefetchNode *node); 1.68 + nsresult DequeueNode(nsPrefetchNode **node); 1.69 + void EmptyQueue(); 1.70 + 1.71 + void StartPrefetching(); 1.72 + void StopPrefetching(); 1.73 + 1.74 + nsPrefetchNode *mQueueHead; 1.75 + nsPrefetchNode *mQueueTail; 1.76 + nsRefPtr<nsPrefetchNode> mCurrentNode; 1.77 + int32_t mStopCount; 1.78 + // true if pending document loads have ever reached zero. 1.79 + int32_t mHaveProcessed; 1.80 + bool mDisabled; 1.81 +}; 1.82 + 1.83 +//----------------------------------------------------------------------------- 1.84 +// nsPrefetchNode 1.85 +//----------------------------------------------------------------------------- 1.86 + 1.87 +class nsPrefetchNode MOZ_FINAL : public nsIStreamListener 1.88 + , public nsIInterfaceRequestor 1.89 + , public nsIChannelEventSink 1.90 + , public nsIRedirectResultListener 1.91 +{ 1.92 +public: 1.93 + NS_DECL_ISUPPORTS 1.94 + NS_DECL_NSIREQUESTOBSERVER 1.95 + NS_DECL_NSISTREAMLISTENER 1.96 + NS_DECL_NSIINTERFACEREQUESTOR 1.97 + NS_DECL_NSICHANNELEVENTSINK 1.98 + NS_DECL_NSIREDIRECTRESULTLISTENER 1.99 + 1.100 + nsPrefetchNode(nsPrefetchService *aPrefetchService, 1.101 + nsIURI *aURI, 1.102 + nsIURI *aReferrerURI, 1.103 + nsIDOMNode *aSource); 1.104 + 1.105 + ~nsPrefetchNode() {} 1.106 + 1.107 + nsresult OpenChannel(); 1.108 + nsresult CancelChannel(nsresult error); 1.109 + 1.110 + nsPrefetchNode *mNext; 1.111 + nsCOMPtr<nsIURI> mURI; 1.112 + nsCOMPtr<nsIURI> mReferrerURI; 1.113 + nsCOMPtr<nsIWeakReference> mSource; 1.114 + 1.115 +private: 1.116 + nsRefPtr<nsPrefetchService> mService; 1.117 + nsCOMPtr<nsIChannel> mChannel; 1.118 + nsCOMPtr<nsIChannel> mRedirectChannel; 1.119 + int64_t mBytesRead; 1.120 +}; 1.121 + 1.122 +#endif // !nsPrefetchService_h__