uriloader/prefetch/nsPrefetchService.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial