1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsAboutCache_h__
7 #define nsAboutCache_h__
9 #include "nsIAboutModule.h"
10 #include "nsICacheStorageVisitor.h"
11 #include "nsICacheStorage.h"
14 #include "nsIChannel.h"
15 #include "nsIOutputStream.h"
16 #include "nsILoadContextInfo.h"
21 #define NS_FORWARD_SAFE_NSICHANNEL_SUBSET(_to) \
22 NS_IMETHOD GetOriginalURI(nsIURI** aOriginalURI) override { \
23 return !(_to) ? NS_ERROR_NULL_POINTER \
24 : (_to)->GetOriginalURI(aOriginalURI); \
26 NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) override { \
27 return !(_to) ? NS_ERROR_NULL_POINTER \
28 : (_to)->SetOriginalURI(aOriginalURI); \
30 NS_IMETHOD GetURI(nsIURI** aURI) override { \
31 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->GetURI(aURI); \
33 NS_IMETHOD GetOwner(nsISupports** aOwner) override { \
34 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->GetOwner(aOwner); \
36 NS_IMETHOD SetOwner(nsISupports* aOwner) override { \
37 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->SetOwner(aOwner); \
39 NS_IMETHOD GetNotificationCallbacks( \
40 nsIInterfaceRequestor** aNotificationCallbacks) override { \
41 return !(_to) ? NS_ERROR_NULL_POINTER \
42 : (_to)->GetNotificationCallbacks(aNotificationCallbacks); \
44 NS_IMETHOD SetNotificationCallbacks( \
45 nsIInterfaceRequestor* aNotificationCallbacks) override { \
46 return !(_to) ? NS_ERROR_NULL_POINTER \
47 : (_to)->SetNotificationCallbacks(aNotificationCallbacks); \
49 NS_IMETHOD GetSecurityInfo(nsITransportSecurityInfo** aSecurityInfo) \
51 return !(_to) ? NS_ERROR_NULL_POINTER \
52 : (_to)->GetSecurityInfo(aSecurityInfo); \
54 NS_IMETHOD GetContentType(nsACString& aContentType) override { \
55 return !(_to) ? NS_ERROR_NULL_POINTER \
56 : (_to)->GetContentType(aContentType); \
58 NS_IMETHOD SetContentType(const nsACString& aContentType) override { \
59 return !(_to) ? NS_ERROR_NULL_POINTER \
60 : (_to)->SetContentType(aContentType); \
62 NS_IMETHOD GetContentCharset(nsACString& aContentCharset) override { \
63 return !(_to) ? NS_ERROR_NULL_POINTER \
64 : (_to)->GetContentCharset(aContentCharset); \
66 NS_IMETHOD SetContentCharset(const nsACString& aContentCharset) override { \
67 return !(_to) ? NS_ERROR_NULL_POINTER \
68 : (_to)->SetContentCharset(aContentCharset); \
70 NS_IMETHOD GetContentLength(int64_t* aContentLength) override { \
71 return !(_to) ? NS_ERROR_NULL_POINTER \
72 : (_to)->GetContentLength(aContentLength); \
74 NS_IMETHOD SetContentLength(int64_t aContentLength) override { \
75 return !(_to) ? NS_ERROR_NULL_POINTER \
76 : (_to)->SetContentLength(aContentLength); \
78 NS_IMETHOD GetContentDisposition(uint32_t* aContentDisposition) override { \
79 return !(_to) ? NS_ERROR_NULL_POINTER \
80 : (_to)->GetContentDisposition(aContentDisposition); \
82 NS_IMETHOD SetContentDisposition(uint32_t aContentDisposition) override { \
83 return !(_to) ? NS_ERROR_NULL_POINTER \
84 : (_to)->SetContentDisposition(aContentDisposition); \
86 NS_IMETHOD GetContentDispositionFilename( \
87 nsAString& aContentDispositionFilename) override { \
88 return !(_to) ? NS_ERROR_NULL_POINTER \
89 : (_to)->GetContentDispositionFilename( \
90 aContentDispositionFilename); \
92 NS_IMETHOD SetContentDispositionFilename( \
93 const nsAString& aContentDispositionFilename) override { \
94 return !(_to) ? NS_ERROR_NULL_POINTER \
95 : (_to)->SetContentDispositionFilename( \
96 aContentDispositionFilename); \
98 NS_IMETHOD GetContentDispositionHeader( \
99 nsACString& aContentDispositionHeader) override { \
100 return !(_to) ? NS_ERROR_NULL_POINTER \
101 : (_to)->GetContentDispositionHeader( \
102 aContentDispositionHeader); \
104 NS_IMETHOD GetLoadInfo(nsILoadInfo** aLoadInfo) override { \
105 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->GetLoadInfo(aLoadInfo); \
107 NS_IMETHOD SetLoadInfo(nsILoadInfo* aLoadInfo) override { \
108 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->SetLoadInfo(aLoadInfo); \
110 NS_IMETHOD GetIsDocument(bool* aIsDocument) override { \
111 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->GetIsDocument(aIsDocument); \
113 NS_IMETHOD GetCanceled(bool* aCanceled) override { \
114 return !(_to) ? NS_ERROR_NULL_POINTER : (_to)->GetCanceled(aCanceled); \
117 class nsAboutCache final
: public nsIAboutModule
{
120 NS_DECL_NSIABOUTMODULE
122 nsAboutCache() = default;
124 [[nodiscard
]] static nsresult
Create(REFNSIID aIID
, void** aResult
);
126 [[nodiscard
]] static nsresult
GetStorage(nsACString
const& storageName
,
127 nsILoadContextInfo
* loadInfo
,
128 nsICacheStorage
** storage
);
131 virtual ~nsAboutCache() = default;
133 class Channel final
: public nsIChannel
, public nsICacheStorageVisitor
{
135 NS_DECL_NSICACHESTORAGEVISITOR
136 NS_FORWARD_SAFE_NSIREQUEST(mChannel
)
137 NS_FORWARD_SAFE_NSICHANNEL_SUBSET(mChannel
)
138 NS_IMETHOD
AsyncOpen(nsIStreamListener
* aListener
) override
;
139 NS_IMETHOD
Open(nsIInputStream
** _retval
) override
;
142 virtual ~Channel() = default;
145 [[nodiscard
]] nsresult
Init(nsIURI
* aURI
, nsILoadInfo
* aLoadInfo
);
146 [[nodiscard
]] nsresult
ParseURI(nsIURI
* uri
, nsACString
& storage
);
148 // Finds a next storage we wish to visit (we use this method
149 // even there is a specified storage name, which is the only
150 // one in the list then.) Posts FireVisitStorage() when found.
151 [[nodiscard
]] nsresult
VisitNextStorage();
152 // Helper method that calls VisitStorage() for the current storage.
153 // When it fails, OnCacheEntryVisitCompleted is simulated to close
154 // the output stream and thus the about:cache channel.
155 void FireVisitStorage();
156 // Kiks the visit cycle for the given storage, names can be:
157 // "disk", "memory", "appcache"
158 // Note: any newly added storage type has to be manually handled here.
159 [[nodiscard
]] nsresult
VisitStorage(nsACString
const& storageName
);
161 // Writes content of mBuffer to mStream and truncates
162 // the buffer. It may fail when the input stream is closed by canceling
163 // the input stream channel. It can be used to stop the cache iteration
165 [[nodiscard
]] nsresult
FlushBuffer();
167 // Whether we are showing overview status of all available
169 bool mOverview
= false;
171 // Flag initially false, that indicates the entries header has
172 // been added to the output HTML.
173 bool mEntriesHeaderAdded
= false;
176 bool mCancel
= false;
178 // The list of all storage names we want to visit
179 nsTArray
<nsCString
> mStorageList
;
180 nsCString mStorageName
;
181 nsCOMPtr
<nsICacheStorage
> mStorage
;
183 // Output data buffering and streaming output
185 nsCOMPtr
<nsIOutputStream
> mStream
;
187 // The input stream channel, the one that actually does the job
188 nsCOMPtr
<nsIChannel
> mChannel
;
192 #define NS_ABOUT_CACHE_MODULE_CID \
193 { /* 9158c470-86e4-11d4-9be2-00e09872a416 */ \
194 0x9158c470, 0x86e4, 0x11d4, { \
195 0x9b, 0xe2, 0x00, 0xe0, 0x98, 0x72, 0xa4, 0x16 \
199 #endif // nsAboutCache_h__