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 kWebSQLKey
[];
42 extern const char kExtensionsKey
[];
43 extern const char kOriginTypesKey
[];
44 extern const char kProtectedWebKey
[];
45 extern const char kSinceKey
[];
46 extern const char kUnprotectedWebKey
[];
49 extern const char kBadDataTypeDetails
[];
50 extern const char kDeleteProhibitedError
[];
51 extern const char kOneAtATimeError
[];
53 } // namespace extension_browsing_data_api_constants
55 class BrowsingDataSettingsFunction
: public ChromeSyncExtensionFunction
{
57 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS
)
60 bool RunSync() override
;
63 ~BrowsingDataSettingsFunction() override
{}
66 // Sets a boolean value in the |selected_dict| with the |data_type| as a key,
67 // indicating whether the data type is both selected and permitted to be
68 // removed; and a value in the |permitted_dict| with the |data_type| as a
69 // key, indicating only whether the data type is permitted to be removed.
70 void SetDetails(base::DictionaryValue
* selected_dict
,
71 base::DictionaryValue
* permitted_dict
,
72 const char* data_type
,
76 // This serves as a base class from which the browsing data API removal
77 // functions will inherit. Each needs to be an observer of BrowsingDataRemover
78 // events, and each will handle those events in the same way (by calling the
79 // passed-in callback function).
81 // Each child class must implement GetRemovalMask(), which returns the bitmask
82 // of data types to remove.
83 class BrowsingDataRemoverFunction
: public ChromeAsyncExtensionFunction
,
84 public BrowsingDataRemover::Observer
{
86 // BrowsingDataRemover::Observer interface method.
87 void OnBrowsingDataRemoverDone() override
;
90 bool RunAsync() override
;
93 ~BrowsingDataRemoverFunction() override
{}
95 // Children should override this method to provide the proper removal mask
96 // based on the API call they represent.
97 virtual int GetRemovalMask() = 0;
100 // Updates the removal bitmask according to whether removing plugin data is
102 void CheckRemovingPluginDataSupported(
103 scoped_refptr
<PluginPrefs
> plugin_prefs
);
105 // Parse the developer-provided |origin_types| object into an origin_type_mask
106 // that can be used with the BrowsingDataRemover.
107 int ParseOriginTypeMask(const base::DictionaryValue
& options
);
109 // Called when we're ready to start removing data.
110 void StartRemoving();
112 base::Time remove_since_
;
114 int origin_type_mask_
;
117 class BrowsingDataRemoveAppcacheFunction
: public BrowsingDataRemoverFunction
{
119 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
120 BROWSINGDATA_REMOVEAPPCACHE
)
123 ~BrowsingDataRemoveAppcacheFunction() override
{}
125 // BrowsingDataRemoverFunction:
126 int GetRemovalMask() override
;
129 class BrowsingDataRemoveFunction
: public BrowsingDataRemoverFunction
{
131 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE
)
134 ~BrowsingDataRemoveFunction() override
{}
136 // BrowsingDataRemoverFunction:
137 int GetRemovalMask() override
;
140 class BrowsingDataRemoveCacheFunction
: public BrowsingDataRemoverFunction
{
142 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
143 BROWSINGDATA_REMOVECACHE
)
146 ~BrowsingDataRemoveCacheFunction() override
{}
148 // BrowsingDataRemoverFunction:
149 int GetRemovalMask() override
;
152 class BrowsingDataRemoveCookiesFunction
: public BrowsingDataRemoverFunction
{
154 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
155 BROWSINGDATA_REMOVECOOKIES
)
158 ~BrowsingDataRemoveCookiesFunction() override
{}
160 // BrowsingDataRemoverFunction:
161 int GetRemovalMask() override
;
164 class BrowsingDataRemoveDownloadsFunction
: public BrowsingDataRemoverFunction
{
166 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
167 BROWSINGDATA_REMOVEDOWNLOADS
)
170 ~BrowsingDataRemoveDownloadsFunction() override
{}
172 // BrowsingDataRemoverFunction:
173 int GetRemovalMask() override
;
176 class BrowsingDataRemoveFileSystemsFunction
177 : public BrowsingDataRemoverFunction
{
179 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
180 BROWSINGDATA_REMOVEFILESYSTEMS
)
183 ~BrowsingDataRemoveFileSystemsFunction() override
{}
185 // BrowsingDataRemoverFunction:
186 int GetRemovalMask() override
;
189 class BrowsingDataRemoveFormDataFunction
: public BrowsingDataRemoverFunction
{
191 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
192 BROWSINGDATA_REMOVEFORMDATA
)
195 ~BrowsingDataRemoveFormDataFunction() override
{}
197 // BrowsingDataRemoverFunction:
198 int GetRemovalMask() override
;
201 class BrowsingDataRemoveHistoryFunction
: public BrowsingDataRemoverFunction
{
203 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
204 BROWSINGDATA_REMOVEHISTORY
)
207 ~BrowsingDataRemoveHistoryFunction() override
{}
209 // BrowsingDataRemoverFunction:
210 int GetRemovalMask() override
;
213 class BrowsingDataRemoveIndexedDBFunction
: public BrowsingDataRemoverFunction
{
215 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
216 BROWSINGDATA_REMOVEINDEXEDDB
)
219 ~BrowsingDataRemoveIndexedDBFunction() override
{}
221 // BrowsingDataRemoverFunction:
222 int GetRemovalMask() override
;
225 class BrowsingDataRemoveLocalStorageFunction
226 : public BrowsingDataRemoverFunction
{
228 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
229 BROWSINGDATA_REMOVELOCALSTORAGE
)
232 ~BrowsingDataRemoveLocalStorageFunction() override
{}
234 // BrowsingDataRemoverFunction:
235 int GetRemovalMask() override
;
238 class BrowsingDataRemovePluginDataFunction
239 : public BrowsingDataRemoverFunction
{
241 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
242 BROWSINGDATA_REMOVEPLUGINDATA
)
245 ~BrowsingDataRemovePluginDataFunction() override
{}
247 // BrowsingDataRemoverFunction:
248 int GetRemovalMask() override
;
251 class BrowsingDataRemovePasswordsFunction
: public BrowsingDataRemoverFunction
{
253 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
254 BROWSINGDATA_REMOVEPASSWORDS
)
257 ~BrowsingDataRemovePasswordsFunction() override
{}
259 // BrowsingDataRemoverFunction:
260 int GetRemovalMask() override
;
263 class BrowsingDataRemoveServiceWorkersFunction
264 : public BrowsingDataRemoverFunction
{
266 DECLARE_EXTENSION_FUNCTION("browsingData.removeServiceWorkers",
267 BROWSINGDATA_REMOVESERVICEWORKERS
)
270 ~BrowsingDataRemoveServiceWorkersFunction() override
{}
272 // BrowsingDataRemoverFunction:
273 int GetRemovalMask() override
;
276 class BrowsingDataRemoveWebSQLFunction
: public BrowsingDataRemoverFunction
{
278 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
279 BROWSINGDATA_REMOVEWEBSQL
)
282 ~BrowsingDataRemoveWebSQLFunction() override
{}
284 // BrowsingDataRemoverFunction:
285 int GetRemovalMask() override
;
288 #endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_