Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / browsing_data / browsing_data_api.h
bloba70f45d049cc4097c1328ef39dc4399f690d3f1f
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_
12 #include <string>
14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
17 class PluginPrefs;
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[];
26 // Type keys.
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[];
42 // Option keys.
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[];
49 // Errors!
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 {
57 public:
58 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS)
60 // ExtensionFunction:
61 bool RunSync() override;
63 protected:
64 ~BrowsingDataSettingsFunction() override {}
66 private:
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,
74 bool is_selected);
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 {
86 public:
87 // BrowsingDataRemover::Observer interface method.
88 void OnBrowsingDataRemoverDone() override;
90 // ExtensionFunction:
91 bool RunAsync() override;
93 protected:
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;
100 private:
101 // Updates the removal bitmask according to whether removing plugin data is
102 // supported or not.
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_;
114 int removal_mask_;
115 int origin_type_mask_;
118 class BrowsingDataRemoveAppcacheFunction : public BrowsingDataRemoverFunction {
119 public:
120 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
121 BROWSINGDATA_REMOVEAPPCACHE)
123 protected:
124 ~BrowsingDataRemoveAppcacheFunction() override {}
126 // BrowsingDataRemoverFunction:
127 int GetRemovalMask() override;
130 class BrowsingDataRemoveFunction : public BrowsingDataRemoverFunction {
131 public:
132 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE)
134 protected:
135 ~BrowsingDataRemoveFunction() override {}
137 // BrowsingDataRemoverFunction:
138 int GetRemovalMask() override;
141 class BrowsingDataRemoveCacheFunction : public BrowsingDataRemoverFunction {
142 public:
143 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
144 BROWSINGDATA_REMOVECACHE)
146 protected:
147 ~BrowsingDataRemoveCacheFunction() override {}
149 // BrowsingDataRemoverFunction:
150 int GetRemovalMask() override;
153 class BrowsingDataRemoveCookiesFunction : public BrowsingDataRemoverFunction {
154 public:
155 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
156 BROWSINGDATA_REMOVECOOKIES)
158 protected:
159 ~BrowsingDataRemoveCookiesFunction() override {}
161 // BrowsingDataRemoverFunction:
162 int GetRemovalMask() override;
165 class BrowsingDataRemoveDownloadsFunction : public BrowsingDataRemoverFunction {
166 public:
167 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
168 BROWSINGDATA_REMOVEDOWNLOADS)
170 protected:
171 ~BrowsingDataRemoveDownloadsFunction() override {}
173 // BrowsingDataRemoverFunction:
174 int GetRemovalMask() override;
177 class BrowsingDataRemoveFileSystemsFunction
178 : public BrowsingDataRemoverFunction {
179 public:
180 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
181 BROWSINGDATA_REMOVEFILESYSTEMS)
183 protected:
184 ~BrowsingDataRemoveFileSystemsFunction() override {}
186 // BrowsingDataRemoverFunction:
187 int GetRemovalMask() override;
190 class BrowsingDataRemoveFormDataFunction : public BrowsingDataRemoverFunction {
191 public:
192 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
193 BROWSINGDATA_REMOVEFORMDATA)
195 protected:
196 ~BrowsingDataRemoveFormDataFunction() override {}
198 // BrowsingDataRemoverFunction:
199 int GetRemovalMask() override;
202 class BrowsingDataRemoveHistoryFunction : public BrowsingDataRemoverFunction {
203 public:
204 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
205 BROWSINGDATA_REMOVEHISTORY)
207 protected:
208 ~BrowsingDataRemoveHistoryFunction() override {}
210 // BrowsingDataRemoverFunction:
211 int GetRemovalMask() override;
214 class BrowsingDataRemoveIndexedDBFunction : public BrowsingDataRemoverFunction {
215 public:
216 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
217 BROWSINGDATA_REMOVEINDEXEDDB)
219 protected:
220 ~BrowsingDataRemoveIndexedDBFunction() override {}
222 // BrowsingDataRemoverFunction:
223 int GetRemovalMask() override;
226 class BrowsingDataRemoveLocalStorageFunction
227 : public BrowsingDataRemoverFunction {
228 public:
229 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
230 BROWSINGDATA_REMOVELOCALSTORAGE)
232 protected:
233 ~BrowsingDataRemoveLocalStorageFunction() override {}
235 // BrowsingDataRemoverFunction:
236 int GetRemovalMask() override;
239 class BrowsingDataRemovePluginDataFunction
240 : public BrowsingDataRemoverFunction {
241 public:
242 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
243 BROWSINGDATA_REMOVEPLUGINDATA)
245 protected:
246 ~BrowsingDataRemovePluginDataFunction() override {}
248 // BrowsingDataRemoverFunction:
249 int GetRemovalMask() override;
252 class BrowsingDataRemovePasswordsFunction : public BrowsingDataRemoverFunction {
253 public:
254 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
255 BROWSINGDATA_REMOVEPASSWORDS)
257 protected:
258 ~BrowsingDataRemovePasswordsFunction() override {}
260 // BrowsingDataRemoverFunction:
261 int GetRemovalMask() override;
264 class BrowsingDataRemoveServiceWorkersFunction
265 : public BrowsingDataRemoverFunction {
266 public:
267 DECLARE_EXTENSION_FUNCTION("browsingData.removeServiceWorkers",
268 BROWSINGDATA_REMOVESERVICEWORKERS)
270 protected:
271 ~BrowsingDataRemoveServiceWorkersFunction() override {}
273 // BrowsingDataRemoverFunction:
274 int GetRemovalMask() override;
277 class BrowsingDataRemoveCacheStorageFunction
278 : public BrowsingDataRemoverFunction {
279 public:
280 DECLARE_EXTENSION_FUNCTION("browsingData.removeCacheStorage",
281 BROWSINGDATA_REMOVECACHESTORAGE)
283 protected:
284 ~BrowsingDataRemoveCacheStorageFunction() override {}
286 // BrowsingDataRemoverFunction:
287 int GetRemovalMask() override;
290 class BrowsingDataRemoveWebSQLFunction : public BrowsingDataRemoverFunction {
291 public:
292 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
293 BROWSINGDATA_REMOVEWEBSQL)
295 protected:
296 ~BrowsingDataRemoveWebSQLFunction() override {}
298 // BrowsingDataRemoverFunction:
299 int GetRemovalMask() override;
302 #endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_