Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / browsing_data / browsing_data_api.h
blobd02b34d1e0b3949eeab1646171d959d1714aa670
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 kWebSQLKey[];
41 // Option keys.
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[];
48 // Errors!
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 {
56 public:
57 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS)
59 // ExtensionFunction:
60 bool RunSync() override;
62 protected:
63 ~BrowsingDataSettingsFunction() override {}
65 private:
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,
73 bool is_selected);
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 {
85 public:
86 // BrowsingDataRemover::Observer interface method.
87 void OnBrowsingDataRemoverDone() override;
89 // ExtensionFunction:
90 bool RunAsync() override;
92 protected:
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;
99 private:
100 // Updates the removal bitmask according to whether removing plugin data is
101 // supported or not.
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_;
113 int removal_mask_;
114 int origin_type_mask_;
117 class BrowsingDataRemoveAppcacheFunction : public BrowsingDataRemoverFunction {
118 public:
119 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
120 BROWSINGDATA_REMOVEAPPCACHE)
122 protected:
123 ~BrowsingDataRemoveAppcacheFunction() override {}
125 // BrowsingDataRemoverFunction:
126 int GetRemovalMask() override;
129 class BrowsingDataRemoveFunction : public BrowsingDataRemoverFunction {
130 public:
131 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE)
133 protected:
134 ~BrowsingDataRemoveFunction() override {}
136 // BrowsingDataRemoverFunction:
137 int GetRemovalMask() override;
140 class BrowsingDataRemoveCacheFunction : public BrowsingDataRemoverFunction {
141 public:
142 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
143 BROWSINGDATA_REMOVECACHE)
145 protected:
146 ~BrowsingDataRemoveCacheFunction() override {}
148 // BrowsingDataRemoverFunction:
149 int GetRemovalMask() override;
152 class BrowsingDataRemoveCookiesFunction : public BrowsingDataRemoverFunction {
153 public:
154 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
155 BROWSINGDATA_REMOVECOOKIES)
157 protected:
158 ~BrowsingDataRemoveCookiesFunction() override {}
160 // BrowsingDataRemoverFunction:
161 int GetRemovalMask() override;
164 class BrowsingDataRemoveDownloadsFunction : public BrowsingDataRemoverFunction {
165 public:
166 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
167 BROWSINGDATA_REMOVEDOWNLOADS)
169 protected:
170 ~BrowsingDataRemoveDownloadsFunction() override {}
172 // BrowsingDataRemoverFunction:
173 int GetRemovalMask() override;
176 class BrowsingDataRemoveFileSystemsFunction
177 : public BrowsingDataRemoverFunction {
178 public:
179 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
180 BROWSINGDATA_REMOVEFILESYSTEMS)
182 protected:
183 ~BrowsingDataRemoveFileSystemsFunction() override {}
185 // BrowsingDataRemoverFunction:
186 int GetRemovalMask() override;
189 class BrowsingDataRemoveFormDataFunction : public BrowsingDataRemoverFunction {
190 public:
191 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
192 BROWSINGDATA_REMOVEFORMDATA)
194 protected:
195 ~BrowsingDataRemoveFormDataFunction() override {}
197 // BrowsingDataRemoverFunction:
198 int GetRemovalMask() override;
201 class BrowsingDataRemoveHistoryFunction : public BrowsingDataRemoverFunction {
202 public:
203 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
204 BROWSINGDATA_REMOVEHISTORY)
206 protected:
207 ~BrowsingDataRemoveHistoryFunction() override {}
209 // BrowsingDataRemoverFunction:
210 int GetRemovalMask() override;
213 class BrowsingDataRemoveIndexedDBFunction : public BrowsingDataRemoverFunction {
214 public:
215 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
216 BROWSINGDATA_REMOVEINDEXEDDB)
218 protected:
219 ~BrowsingDataRemoveIndexedDBFunction() override {}
221 // BrowsingDataRemoverFunction:
222 int GetRemovalMask() override;
225 class BrowsingDataRemoveLocalStorageFunction
226 : public BrowsingDataRemoverFunction {
227 public:
228 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
229 BROWSINGDATA_REMOVELOCALSTORAGE)
231 protected:
232 ~BrowsingDataRemoveLocalStorageFunction() override {}
234 // BrowsingDataRemoverFunction:
235 int GetRemovalMask() override;
238 class BrowsingDataRemovePluginDataFunction
239 : public BrowsingDataRemoverFunction {
240 public:
241 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
242 BROWSINGDATA_REMOVEPLUGINDATA)
244 protected:
245 ~BrowsingDataRemovePluginDataFunction() override {}
247 // BrowsingDataRemoverFunction:
248 int GetRemovalMask() override;
251 class BrowsingDataRemovePasswordsFunction : public BrowsingDataRemoverFunction {
252 public:
253 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
254 BROWSINGDATA_REMOVEPASSWORDS)
256 protected:
257 ~BrowsingDataRemovePasswordsFunction() override {}
259 // BrowsingDataRemoverFunction:
260 int GetRemovalMask() override;
263 class BrowsingDataRemoveServiceWorkersFunction
264 : public BrowsingDataRemoverFunction {
265 public:
266 DECLARE_EXTENSION_FUNCTION("browsingData.removeServiceWorkers",
267 BROWSINGDATA_REMOVESERVICEWORKERS)
269 protected:
270 ~BrowsingDataRemoveServiceWorkersFunction() override {}
272 // BrowsingDataRemoverFunction:
273 int GetRemovalMask() override;
276 class BrowsingDataRemoveWebSQLFunction : public BrowsingDataRemoverFunction {
277 public:
278 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
279 BROWSINGDATA_REMOVEWEBSQL)
281 protected:
282 ~BrowsingDataRemoveWebSQLFunction() override {}
284 // BrowsingDataRemoverFunction:
285 int GetRemovalMask() override;
288 #endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_