browsing_data_api.h revision 010d83a9304c5a91596085d917d248abff47903a
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. 4 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. 8 9#ifndef CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_ 10#define CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_ 11 12#include <string> 13 14#include "chrome/browser/browsing_data/browsing_data_remover.h" 15#include "chrome/browser/extensions/chrome_extension_function.h" 16 17class PluginPrefs; 18 19namespace extension_browsing_data_api_constants { 20 21// Parameter name keys. 22extern const char kDataRemovalPermittedKey[]; 23extern const char kDataToRemoveKey[]; 24extern const char kOptionsKey[]; 25 26// Type keys. 27extern const char kAppCacheKey[]; 28extern const char kCacheKey[]; 29extern const char kCookiesKey[]; 30extern const char kDownloadsKey[]; 31extern const char kFileSystemsKey[]; 32extern const char kFormDataKey[]; 33extern const char kHistoryKey[]; 34extern const char kIndexedDBKey[]; 35extern const char kPluginDataKey[]; 36extern const char kLocalStorageKey[]; 37extern const char kPasswordsKey[]; 38extern const char kWebSQLKey[]; 39 40// Option keys. 41extern const char kExtensionsKey[]; 42extern const char kOriginTypesKey[]; 43extern const char kProtectedWebKey[]; 44extern const char kSinceKey[]; 45extern const char kUnprotectedWebKey[]; 46 47// Errors! 48extern const char kBadDataTypeDetails[]; 49extern const char kDeleteProhibitedError[]; 50extern const char kOneAtATimeError[]; 51 52} // namespace extension_browsing_data_api_constants 53 54class BrowsingDataSettingsFunction : public ChromeSyncExtensionFunction { 55 public: 56 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS) 57 58 // ExtensionFunction: 59 virtual bool RunSync() OVERRIDE; 60 61 protected: 62 virtual ~BrowsingDataSettingsFunction() {} 63 64 private: 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, 72 bool is_selected); 73}; 74 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). 79// 80// Each child class must implement GetRemovalMask(), which returns the bitmask 81// of data types to remove. 82class BrowsingDataRemoverFunction : public ChromeAsyncExtensionFunction, 83 public BrowsingDataRemover::Observer { 84 public: 85 // BrowsingDataRemover::Observer interface method. 86 virtual void OnBrowsingDataRemoverDone() OVERRIDE; 87 88 // ExtensionFunction: 89 virtual bool RunAsync() OVERRIDE; 90 91 protected: 92 virtual ~BrowsingDataRemoverFunction() {} 93 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; 97 98 private: 99 // Updates the removal bitmask according to whether removing plugin data is 100 // supported or not. 101 void CheckRemovingPluginDataSupported( 102 scoped_refptr<PluginPrefs> plugin_prefs); 103 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); 107 108 // Called when we're ready to start removing data. 109 void StartRemoving(); 110 111 base::Time remove_since_; 112 int removal_mask_; 113 int origin_set_mask_; 114}; 115 116class BrowsingDataRemoveAppcacheFunction : public BrowsingDataRemoverFunction { 117 public: 118 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache", 119 BROWSINGDATA_REMOVEAPPCACHE) 120 121 protected: 122 virtual ~BrowsingDataRemoveAppcacheFunction() {} 123 124 // BrowsingDataRemoverFunction: 125 virtual int GetRemovalMask() OVERRIDE; 126}; 127 128class BrowsingDataRemoveFunction : public BrowsingDataRemoverFunction { 129 public: 130 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE) 131 132 protected: 133 virtual ~BrowsingDataRemoveFunction() {} 134 135 // BrowsingDataRemoverFunction: 136 virtual int GetRemovalMask() OVERRIDE; 137}; 138 139class BrowsingDataRemoveCacheFunction : public BrowsingDataRemoverFunction { 140 public: 141 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache", 142 BROWSINGDATA_REMOVECACHE) 143 144 protected: 145 virtual ~BrowsingDataRemoveCacheFunction() {} 146 147 // BrowsingDataRemoverFunction: 148 virtual int GetRemovalMask() OVERRIDE; 149}; 150 151class BrowsingDataRemoveCookiesFunction : public BrowsingDataRemoverFunction { 152 public: 153 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies", 154 BROWSINGDATA_REMOVECOOKIES) 155 156 protected: 157 virtual ~BrowsingDataRemoveCookiesFunction() {} 158 159 // BrowsingDataRemoverFunction: 160 virtual int GetRemovalMask() OVERRIDE; 161}; 162 163class BrowsingDataRemoveDownloadsFunction : public BrowsingDataRemoverFunction { 164 public: 165 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads", 166 BROWSINGDATA_REMOVEDOWNLOADS) 167 168 protected: 169 virtual ~BrowsingDataRemoveDownloadsFunction() {} 170 171 // BrowsingDataRemoverFunction: 172 virtual int GetRemovalMask() OVERRIDE; 173}; 174 175class BrowsingDataRemoveFileSystemsFunction 176 : public BrowsingDataRemoverFunction { 177 public: 178 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems", 179 BROWSINGDATA_REMOVEFILESYSTEMS) 180 181 protected: 182 virtual ~BrowsingDataRemoveFileSystemsFunction() {} 183 184 // BrowsingDataRemoverFunction: 185 virtual int GetRemovalMask() OVERRIDE; 186}; 187 188class BrowsingDataRemoveFormDataFunction : public BrowsingDataRemoverFunction { 189 public: 190 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData", 191 BROWSINGDATA_REMOVEFORMDATA) 192 193 protected: 194 virtual ~BrowsingDataRemoveFormDataFunction() {} 195 196 // BrowsingDataRemoverFunction: 197 virtual int GetRemovalMask() OVERRIDE; 198}; 199 200class BrowsingDataRemoveHistoryFunction : public BrowsingDataRemoverFunction { 201 public: 202 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory", 203 BROWSINGDATA_REMOVEHISTORY) 204 205 protected: 206 virtual ~BrowsingDataRemoveHistoryFunction() {} 207 208 // BrowsingDataRemoverFunction: 209 virtual int GetRemovalMask() OVERRIDE; 210}; 211 212class BrowsingDataRemoveIndexedDBFunction : public BrowsingDataRemoverFunction { 213 public: 214 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB", 215 BROWSINGDATA_REMOVEINDEXEDDB) 216 217 protected: 218 virtual ~BrowsingDataRemoveIndexedDBFunction() {} 219 220 // BrowsingDataRemoverFunction: 221 virtual int GetRemovalMask() OVERRIDE; 222}; 223 224class BrowsingDataRemoveLocalStorageFunction 225 : public BrowsingDataRemoverFunction { 226 public: 227 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage", 228 BROWSINGDATA_REMOVELOCALSTORAGE) 229 230 protected: 231 virtual ~BrowsingDataRemoveLocalStorageFunction() {} 232 233 // BrowsingDataRemoverFunction: 234 virtual int GetRemovalMask() OVERRIDE; 235}; 236 237class BrowsingDataRemovePluginDataFunction 238 : public BrowsingDataRemoverFunction { 239 public: 240 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData", 241 BROWSINGDATA_REMOVEPLUGINDATA) 242 243 protected: 244 virtual ~BrowsingDataRemovePluginDataFunction() {} 245 246 // BrowsingDataRemoverFunction: 247 virtual int GetRemovalMask() OVERRIDE; 248}; 249 250class BrowsingDataRemovePasswordsFunction : public BrowsingDataRemoverFunction { 251 public: 252 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords", 253 BROWSINGDATA_REMOVEPASSWORDS) 254 255 protected: 256 virtual ~BrowsingDataRemovePasswordsFunction() {} 257 258 // BrowsingDataRemoverFunction: 259 virtual int GetRemovalMask() OVERRIDE; 260}; 261 262class BrowsingDataRemoveWebSQLFunction : public BrowsingDataRemoverFunction { 263 public: 264 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL", 265 BROWSINGDATA_REMOVEWEBSQL) 266 267 protected: 268 virtual ~BrowsingDataRemoveWebSQLFunction() {} 269 270 // BrowsingDataRemoverFunction: 271 virtual int GetRemovalMask() OVERRIDE; 272}; 273 274#endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_ 275