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 kWebSQLKey
[];
41 extern const char kExtensionsKey
[];
42 extern const char kOriginTypesKey
[];
43 extern const char kProtectedWebKey
[];
44 extern const char kSinceKey
[];
45 extern const char kUnprotectedWebKey
[];
48 extern const char kBadDataTypeDetails
[];
49 extern const char kDeleteProhibitedError
[];
50 extern const char kOneAtATimeError
[];
52 } // namespace extension_browsing_data_api_constants
54 class BrowsingDataSettingsFunction
: public ChromeSyncExtensionFunction
{
56 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS
)
59 virtual bool RunSync() OVERRIDE
;
62 virtual ~BrowsingDataSettingsFunction() {}
65 // Sets a boolean value in the |selected_dict| with the |data_type| as a key,
66 // indicating whether the data type is both selected and permitted to be
67 // removed; and a value in the |permitted_dict| with the |data_type| as a
68 // key, indicating only whether the data type is permitted to be removed.
69 void SetDetails(base::DictionaryValue
* selected_dict
,
70 base::DictionaryValue
* permitted_dict
,
71 const char* data_type
,
75 // This serves as a base class from which the browsing data API removal
76 // functions will inherit. Each needs to be an observer of BrowsingDataRemover
77 // events, and each will handle those events in the same way (by calling the
78 // passed-in callback function).
80 // Each child class must implement GetRemovalMask(), which returns the bitmask
81 // of data types to remove.
82 class BrowsingDataRemoverFunction
: public ChromeAsyncExtensionFunction
,
83 public BrowsingDataRemover::Observer
{
85 // BrowsingDataRemover::Observer interface method.
86 virtual void OnBrowsingDataRemoverDone() OVERRIDE
;
89 virtual bool RunAsync() OVERRIDE
;
92 virtual ~BrowsingDataRemoverFunction() {}
94 // Children should override this method to provide the proper removal mask
95 // based on the API call they represent.
96 virtual int GetRemovalMask() = 0;
99 // Updates the removal bitmask according to whether removing plugin data is
101 void CheckRemovingPluginDataSupported(
102 scoped_refptr
<PluginPrefs
> plugin_prefs
);
104 // Parse the developer-provided |origin_types| object into an origin_set_mask
105 // that can be used with the BrowsingDataRemover.
106 int ParseOriginSetMask(const base::DictionaryValue
& options
);
108 // Called when we're ready to start removing data.
109 void StartRemoving();
111 base::Time remove_since_
;
113 int origin_set_mask_
;
116 class BrowsingDataRemoveAppcacheFunction
: public BrowsingDataRemoverFunction
{
118 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
119 BROWSINGDATA_REMOVEAPPCACHE
)
122 virtual ~BrowsingDataRemoveAppcacheFunction() {}
124 // BrowsingDataRemoverFunction:
125 virtual int GetRemovalMask() OVERRIDE
;
128 class BrowsingDataRemoveFunction
: public BrowsingDataRemoverFunction
{
130 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE
)
133 virtual ~BrowsingDataRemoveFunction() {}
135 // BrowsingDataRemoverFunction:
136 virtual int GetRemovalMask() OVERRIDE
;
139 class BrowsingDataRemoveCacheFunction
: public BrowsingDataRemoverFunction
{
141 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
142 BROWSINGDATA_REMOVECACHE
)
145 virtual ~BrowsingDataRemoveCacheFunction() {}
147 // BrowsingDataRemoverFunction:
148 virtual int GetRemovalMask() OVERRIDE
;
151 class BrowsingDataRemoveCookiesFunction
: public BrowsingDataRemoverFunction
{
153 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
154 BROWSINGDATA_REMOVECOOKIES
)
157 virtual ~BrowsingDataRemoveCookiesFunction() {}
159 // BrowsingDataRemoverFunction:
160 virtual int GetRemovalMask() OVERRIDE
;
163 class BrowsingDataRemoveDownloadsFunction
: public BrowsingDataRemoverFunction
{
165 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
166 BROWSINGDATA_REMOVEDOWNLOADS
)
169 virtual ~BrowsingDataRemoveDownloadsFunction() {}
171 // BrowsingDataRemoverFunction:
172 virtual int GetRemovalMask() OVERRIDE
;
175 class BrowsingDataRemoveFileSystemsFunction
176 : public BrowsingDataRemoverFunction
{
178 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
179 BROWSINGDATA_REMOVEFILESYSTEMS
)
182 virtual ~BrowsingDataRemoveFileSystemsFunction() {}
184 // BrowsingDataRemoverFunction:
185 virtual int GetRemovalMask() OVERRIDE
;
188 class BrowsingDataRemoveFormDataFunction
: public BrowsingDataRemoverFunction
{
190 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
191 BROWSINGDATA_REMOVEFORMDATA
)
194 virtual ~BrowsingDataRemoveFormDataFunction() {}
196 // BrowsingDataRemoverFunction:
197 virtual int GetRemovalMask() OVERRIDE
;
200 class BrowsingDataRemoveHistoryFunction
: public BrowsingDataRemoverFunction
{
202 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
203 BROWSINGDATA_REMOVEHISTORY
)
206 virtual ~BrowsingDataRemoveHistoryFunction() {}
208 // BrowsingDataRemoverFunction:
209 virtual int GetRemovalMask() OVERRIDE
;
212 class BrowsingDataRemoveIndexedDBFunction
: public BrowsingDataRemoverFunction
{
214 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
215 BROWSINGDATA_REMOVEINDEXEDDB
)
218 virtual ~BrowsingDataRemoveIndexedDBFunction() {}
220 // BrowsingDataRemoverFunction:
221 virtual int GetRemovalMask() OVERRIDE
;
224 class BrowsingDataRemoveLocalStorageFunction
225 : public BrowsingDataRemoverFunction
{
227 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
228 BROWSINGDATA_REMOVELOCALSTORAGE
)
231 virtual ~BrowsingDataRemoveLocalStorageFunction() {}
233 // BrowsingDataRemoverFunction:
234 virtual int GetRemovalMask() OVERRIDE
;
237 class BrowsingDataRemovePluginDataFunction
238 : public BrowsingDataRemoverFunction
{
240 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
241 BROWSINGDATA_REMOVEPLUGINDATA
)
244 virtual ~BrowsingDataRemovePluginDataFunction() {}
246 // BrowsingDataRemoverFunction:
247 virtual int GetRemovalMask() OVERRIDE
;
250 class BrowsingDataRemovePasswordsFunction
: public BrowsingDataRemoverFunction
{
252 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
253 BROWSINGDATA_REMOVEPASSWORDS
)
256 virtual ~BrowsingDataRemovePasswordsFunction() {}
258 // BrowsingDataRemoverFunction:
259 virtual int GetRemovalMask() OVERRIDE
;
262 class BrowsingDataRemoveWebSQLFunction
: public BrowsingDataRemoverFunction
{
264 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
265 BROWSINGDATA_REMOVEWEBSQL
)
268 virtual ~BrowsingDataRemoveWebSQLFunction() {}
270 // BrowsingDataRemoverFunction:
271 virtual int GetRemovalMask() OVERRIDE
;
274 #endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_