|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef nsPrefetchService_h__ |
|
6 #define nsPrefetchService_h__ |
|
7 |
|
8 #include "nsCPrefetchService.h" |
|
9 #include "nsIObserver.h" |
|
10 #include "nsIInterfaceRequestor.h" |
|
11 #include "nsIChannelEventSink.h" |
|
12 #include "nsIRedirectResultListener.h" |
|
13 #include "nsIWebProgressListener.h" |
|
14 #include "nsIStreamListener.h" |
|
15 #include "nsIChannel.h" |
|
16 #include "nsIURI.h" |
|
17 #include "nsWeakReference.h" |
|
18 #include "nsCOMPtr.h" |
|
19 #include "nsAutoPtr.h" |
|
20 #include "mozilla/Attributes.h" |
|
21 |
|
22 class nsPrefetchService; |
|
23 class nsPrefetchListener; |
|
24 class nsPrefetchNode; |
|
25 |
|
26 //----------------------------------------------------------------------------- |
|
27 // nsPrefetchService |
|
28 //----------------------------------------------------------------------------- |
|
29 |
|
30 class nsPrefetchService MOZ_FINAL : public nsIPrefetchService |
|
31 , public nsIWebProgressListener |
|
32 , public nsIObserver |
|
33 , public nsSupportsWeakReference |
|
34 { |
|
35 public: |
|
36 NS_DECL_ISUPPORTS |
|
37 NS_DECL_NSIPREFETCHSERVICE |
|
38 NS_DECL_NSIWEBPROGRESSLISTENER |
|
39 NS_DECL_NSIOBSERVER |
|
40 |
|
41 nsPrefetchService(); |
|
42 |
|
43 nsresult Init(); |
|
44 void ProcessNextURI(); |
|
45 |
|
46 nsPrefetchNode *GetCurrentNode() { return mCurrentNode.get(); } |
|
47 nsPrefetchNode *GetQueueHead() { return mQueueHead; } |
|
48 |
|
49 void NotifyLoadRequested(nsPrefetchNode *node); |
|
50 void NotifyLoadCompleted(nsPrefetchNode *node); |
|
51 |
|
52 private: |
|
53 ~nsPrefetchService(); |
|
54 |
|
55 nsresult Prefetch(nsIURI *aURI, |
|
56 nsIURI *aReferrerURI, |
|
57 nsIDOMNode *aSource, |
|
58 bool aExplicit); |
|
59 |
|
60 void AddProgressListener(); |
|
61 void RemoveProgressListener(); |
|
62 nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI, |
|
63 nsIDOMNode *aSource, nsPrefetchNode **node); |
|
64 nsresult EnqueueNode(nsPrefetchNode *node); |
|
65 nsresult DequeueNode(nsPrefetchNode **node); |
|
66 void EmptyQueue(); |
|
67 |
|
68 void StartPrefetching(); |
|
69 void StopPrefetching(); |
|
70 |
|
71 nsPrefetchNode *mQueueHead; |
|
72 nsPrefetchNode *mQueueTail; |
|
73 nsRefPtr<nsPrefetchNode> mCurrentNode; |
|
74 int32_t mStopCount; |
|
75 // true if pending document loads have ever reached zero. |
|
76 int32_t mHaveProcessed; |
|
77 bool mDisabled; |
|
78 }; |
|
79 |
|
80 //----------------------------------------------------------------------------- |
|
81 // nsPrefetchNode |
|
82 //----------------------------------------------------------------------------- |
|
83 |
|
84 class nsPrefetchNode MOZ_FINAL : public nsIStreamListener |
|
85 , public nsIInterfaceRequestor |
|
86 , public nsIChannelEventSink |
|
87 , public nsIRedirectResultListener |
|
88 { |
|
89 public: |
|
90 NS_DECL_ISUPPORTS |
|
91 NS_DECL_NSIREQUESTOBSERVER |
|
92 NS_DECL_NSISTREAMLISTENER |
|
93 NS_DECL_NSIINTERFACEREQUESTOR |
|
94 NS_DECL_NSICHANNELEVENTSINK |
|
95 NS_DECL_NSIREDIRECTRESULTLISTENER |
|
96 |
|
97 nsPrefetchNode(nsPrefetchService *aPrefetchService, |
|
98 nsIURI *aURI, |
|
99 nsIURI *aReferrerURI, |
|
100 nsIDOMNode *aSource); |
|
101 |
|
102 ~nsPrefetchNode() {} |
|
103 |
|
104 nsresult OpenChannel(); |
|
105 nsresult CancelChannel(nsresult error); |
|
106 |
|
107 nsPrefetchNode *mNext; |
|
108 nsCOMPtr<nsIURI> mURI; |
|
109 nsCOMPtr<nsIURI> mReferrerURI; |
|
110 nsCOMPtr<nsIWeakReference> mSource; |
|
111 |
|
112 private: |
|
113 nsRefPtr<nsPrefetchService> mService; |
|
114 nsCOMPtr<nsIChannel> mChannel; |
|
115 nsCOMPtr<nsIChannel> mRedirectChannel; |
|
116 int64_t mBytesRead; |
|
117 }; |
|
118 |
|
119 #endif // !nsPrefetchService_h__ |