1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Defines the Chrome Extensions BrowsingData API functions, which entail
6 // clearing browsing data, and clearing the browser's cache (which, let's be
7 // honest, are the same thing), as specified in the extension API JSON.
9 #ifndef CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
10 #define CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
19 namespace extension_browsing_data_api_constants
{
21 // Parameter name keys.
22 extern const char kDataRemovalPermittedKey
[];
23 extern const char kDataToRemoveKey
[];
24 extern const char kOptionsKey
[];
27 extern const char kAppCacheKey
[];
28 extern const char kCacheKey
[];
29 extern const char kCookiesKey
[];
30 extern const char kDownloadsKey
[];
31 extern const char kFileSystemsKey
[];
32 extern const char kFormDataKey
[];
33 extern const char kHistoryKey
[];
34 extern const char kIndexedDBKey
[];
35 extern const char kPluginDataKey
[];
36 extern const char kLocalStorageKey
[];
37 extern const char kPasswordsKey
[];
38 extern const char kServiceWorkersKey
[];
39 extern const char kCacheStorageKey
[];
40 extern const char kWebSQLKey
[];
43 extern const char kExtensionsKey
[];
44 extern const char kOriginTypesKey
[];
45 extern const char kProtectedWebKey
[];
46 extern const char kSinceKey
[];
47 extern const char kUnprotectedWebKey
[];
50 extern const char kBadDataTypeDetails
[];
51 extern const char kDeleteProhibitedError
[];
52 extern const char kOneAtATimeError
[];
54 } // namespace extension_browsing_data_api_constants
56 class BrowsingDataSettingsFunction
: public ChromeSyncExtensionFunction
{
58 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS
)
61 bool RunSync() override
;
64 ~BrowsingDataSettingsFunction() override
{}
67 // Sets a boolean value in the |selected_dict| with the |data_type| as a key,
68 // indicating whether the data type is both selected and permitted to be
69 // removed; and a value in the |permitted_dict| with the |data_type| as a
70 // key, indicating only whether the data type is permitted to be removed.
71 void SetDetails(base::DictionaryValue
* selected_dict
,
72 base::DictionaryValue
* permitted_dict
,
73 const char* data_type
,
77 // This serves as a base class from which the browsing data API removal
78 // functions will inherit. Each needs to be an observer of BrowsingDataRemover
79 // events, and each will handle those events in the same way (by calling the
80 // passed-in callback function).
82 // Each child class must implement GetRemovalMask(), which returns the bitmask
83 // of data types to remove.
84 class BrowsingDataRemoverFunction
: public ChromeAsyncExtensionFunction
,
85 public BrowsingDataRemover::Observer
{
87 // BrowsingDataRemover::Observer interface method.
88 void OnBrowsingDataRemoverDone() override
;
91 bool RunAsync() override
;
94 ~BrowsingDataRemoverFunction() override
{}
96 // Children should override this method to provide the proper removal mask
97 // based on the API call they represent.
98 virtual int GetRemovalMask() = 0;
101 // Updates the removal bitmask according to whether removing plugin data is
103 void CheckRemovingPluginDataSupported(
104 scoped_refptr
<PluginPrefs
> plugin_prefs
);
106 // Parse the developer-provided |origin_types| object into an origin_type_mask
107 // that can be used with the BrowsingDataRemover.
108 int ParseOriginTypeMask(const base::DictionaryValue
& options
);
110 // Called when we're ready to start removing data.
111 void StartRemoving();
113 base::Time remove_since_
;
115 int origin_type_mask_
;
118 class BrowsingDataRemoveAppcacheFunction
: public BrowsingDataRemoverFunction
{
120 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
121 BROWSINGDATA_REMOVEAPPCACHE
)
124 ~BrowsingDataRemoveAppcacheFunction() override
{}
126 // BrowsingDataRemoverFunction:
127 int GetRemovalMask() override
;
130 class BrowsingDataRemoveFunction
: public BrowsingDataRemoverFunction
{
132 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE
)
135 ~BrowsingDataRemoveFunction() override
{}
137 // BrowsingDataRemoverFunction:
138 int GetRemovalMask() override
;
141 class BrowsingDataRemoveCacheFunction
: public BrowsingDataRemoverFunction
{
143 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
144 BROWSINGDATA_REMOVECACHE
)
147 ~BrowsingDataRemoveCacheFunction() override
{}
149 // BrowsingDataRemoverFunction:
150 int GetRemovalMask() override
;
153 class BrowsingDataRemoveCookiesFunction
: public BrowsingDataRemoverFunction
{
155 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
156 BROWSINGDATA_REMOVECOOKIES
)
159 ~BrowsingDataRemoveCookiesFunction() override
{}
161 // BrowsingDataRemoverFunction:
162 int GetRemovalMask() override
;
165 class BrowsingDataRemoveDownloadsFunction
: public BrowsingDataRemoverFunction
{
167 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
168 BROWSINGDATA_REMOVEDOWNLOADS
)
171 ~BrowsingDataRemoveDownloadsFunction() override
{}
173 // BrowsingDataRemoverFunction:
174 int GetRemovalMask() override
;
177 class BrowsingDataRemoveFileSystemsFunction
178 : public BrowsingDataRemoverFunction
{
180 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
181 BROWSINGDATA_REMOVEFILESYSTEMS
)
184 ~BrowsingDataRemoveFileSystemsFunction() override
{}
186 // BrowsingDataRemoverFunction:
187 int GetRemovalMask() override
;
190 class BrowsingDataRemoveFormDataFunction
: public BrowsingDataRemoverFunction
{
192 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
193 BROWSINGDATA_REMOVEFORMDATA
)
196 ~BrowsingDataRemoveFormDataFunction() override
{}
198 // BrowsingDataRemoverFunction:
199 int GetRemovalMask() override
;
202 class BrowsingDataRemoveHistoryFunction
: public BrowsingDataRemoverFunction
{
204 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
205 BROWSINGDATA_REMOVEHISTORY
)
208 ~BrowsingDataRemoveHistoryFunction() override
{}
210 // BrowsingDataRemoverFunction:
211 int GetRemovalMask() override
;
214 class BrowsingDataRemoveIndexedDBFunction
: public BrowsingDataRemoverFunction
{
216 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
217 BROWSINGDATA_REMOVEINDEXEDDB
)
220 ~BrowsingDataRemoveIndexedDBFunction() override
{}
222 // BrowsingDataRemoverFunction:
223 int GetRemovalMask() override
;
226 class BrowsingDataRemoveLocalStorageFunction
227 : public BrowsingDataRemoverFunction
{
229 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
230 BROWSINGDATA_REMOVELOCALSTORAGE
)
233 ~BrowsingDataRemoveLocalStorageFunction() override
{}
235 // BrowsingDataRemoverFunction:
236 int GetRemovalMask() override
;
239 class BrowsingDataRemovePluginDataFunction
240 : public BrowsingDataRemoverFunction
{
242 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
243 BROWSINGDATA_REMOVEPLUGINDATA
)
246 ~BrowsingDataRemovePluginDataFunction() override
{}
248 // BrowsingDataRemoverFunction:
249 int GetRemovalMask() override
;
252 class BrowsingDataRemovePasswordsFunction
: public BrowsingDataRemoverFunction
{
254 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
255 BROWSINGDATA_REMOVEPASSWORDS
)
258 ~BrowsingDataRemovePasswordsFunction() override
{}
260 // BrowsingDataRemoverFunction:
261 int GetRemovalMask() override
;
264 class BrowsingDataRemoveServiceWorkersFunction
265 : public BrowsingDataRemoverFunction
{
267 DECLARE_EXTENSION_FUNCTION("browsingData.removeServiceWorkers",
268 BROWSINGDATA_REMOVESERVICEWORKERS
)
271 ~BrowsingDataRemoveServiceWorkersFunction() override
{}
273 // BrowsingDataRemoverFunction:
274 int GetRemovalMask() override
;
277 class BrowsingDataRemoveCacheStorageFunction
278 : public BrowsingDataRemoverFunction
{
280 DECLARE_EXTENSION_FUNCTION("browsingData.removeCacheStorage",
281 BROWSINGDATA_REMOVECACHESTORAGE
)
284 ~BrowsingDataRemoveCacheStorageFunction() override
{}
286 // BrowsingDataRemoverFunction:
287 int GetRemovalMask() override
;
290 class BrowsingDataRemoveWebSQLFunction
: public BrowsingDataRemoverFunction
{
292 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
293 BROWSINGDATA_REMOVEWEBSQL
)
296 ~BrowsingDataRemoveWebSQLFunction() override
{}
298 // BrowsingDataRemoverFunction:
299 int GetRemovalMask() override
;
302 #endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_