1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Defines the Chrome Extensions BrowsingData API functions, which entail
// clearing browsing data, and clearing the browser's cache (which, let's be
// honest, are the same thing), as specified in the extension API JSON.
#ifndef CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
#include <string>
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "components/browsing_data/core/browsing_data_utils.h"
#include "components/signin/core/browser/account_reconcilor.h"
#include "content/public/browser/browsing_data_remover.h"
class PluginPrefs;
class PrefService;
namespace extension_browsing_data_api_constants {
// Parameter name keys.
extern const char kDataRemovalPermittedKey[];
extern const char kDataToRemoveKey[];
extern const char kOptionsKey[];
// Type keys.
extern const char kAppCacheKey[];
extern const char kCacheKey[];
extern const char kCookiesKey[];
extern const char kDownloadsKey[];
extern const char kFileSystemsKey[];
extern const char kFormDataKey[];
extern const char kHistoryKey[];
extern const char kIndexedDBKey[];
extern const char kPluginDataKey[];
extern const char kLocalStorageKey[];
extern const char kPasswordsKey[];
extern const char kServiceWorkersKey[];
extern const char kCacheStorageKey[];
extern const char kWebSQLKey[];
// Option keys.
extern const char kExtensionsKey[];
extern const char kOriginTypesKey[];
extern const char kProtectedWebKey[];
extern const char kSinceKey[];
extern const char kUnprotectedWebKey[];
// Errors!
extern const char kBadDataTypeDetails[];
extern const char kDeleteProhibitedError[];
} // namespace extension_browsing_data_api_constants
class BrowsingDataSettingsFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS)
// ExtensionFunction:
ResponseAction Run() override;
protected:
~BrowsingDataSettingsFunction() override {}
private:
// Sets a boolean value in the |selected_dict| with the |data_type| as a key,
// indicating whether the data type is both selected and permitted to be
// removed; and a value in the |permitted_dict| with the |data_type| as a
// key, indicating only whether the data type is permitted to be removed.
void SetDetails(base::DictionaryValue* selected_dict,
base::DictionaryValue* permitted_dict,
const char* data_type,
bool is_selected);
// Returns whether |data_type| is currently selected for deletion on |tab|.
bool isDataTypeSelected(browsing_data::BrowsingDataType data_type,
browsing_data::ClearBrowsingDataTab tab);
PrefService* prefs_ = nullptr;
};
// This serves as a base class from which the browsing data API removal
// functions will inherit. Each needs to be an observer of BrowsingDataRemover
// events, and each will handle those events in the same way (by calling the
// passed-in callback function).
//
// Each child class must implement GetRemovalMask(), which returns the bitmask
// of data types to remove.
class BrowsingDataRemoverFunction
: public ChromeAsyncExtensionFunction,
public content::BrowsingDataRemover::Observer {
public:
BrowsingDataRemoverFunction();
// BrowsingDataRemover::Observer interface method.
void OnBrowsingDataRemoverDone() override;
// ExtensionFunction:
bool RunAsync() override;
protected:
~BrowsingDataRemoverFunction() override;
private:
// Children should override this method to provide the proper removal mask
// based on the API call they represent.
// Returns whether or not removal mask retrieval was successful.
// |removal_mask| is populated with the result, if successful.
virtual bool GetRemovalMask(int* removal_mask) = 0;
// Returns true if the data removal is allowed to pause Sync. Returns true by
// default. Subclasses can override it to return false and prevent Sync from
// being paused. This is important when synced data is being removed, and
// pausing Sync would prevent the data from being deleted on the server.
virtual bool IsPauseSyncAllowed();
// Updates the removal bitmask according to whether removing plugin data is
// supported or not.
void CheckRemovingPluginDataSupported(
scoped_refptr<PluginPrefs> plugin_prefs);
// Parse the developer-provided |origin_types| object into |origin_type_mask|
// that can be used with the BrowsingDataRemover.
// Returns true if parsing was successful.
bool ParseOriginTypeMask(const base::DictionaryValue& options,
int* origin_type_mask);
// Called when we're ready to start removing data.
void StartRemoving();
base::Time remove_since_;
int removal_mask_;
int origin_type_mask_;
ScopedObserver<content::BrowsingDataRemover,
content::BrowsingDataRemover::Observer>
observer_;
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion>
synced_data_deletion_;
};
class BrowsingDataRemoveAppcacheFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
BROWSINGDATA_REMOVEAPPCACHE)
protected:
~BrowsingDataRemoveAppcacheFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE)
protected:
~BrowsingDataRemoveFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
bool IsPauseSyncAllowed() override;
};
class BrowsingDataRemoveCacheFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
BROWSINGDATA_REMOVECACHE)
protected:
~BrowsingDataRemoveCacheFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveCookiesFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
BROWSINGDATA_REMOVECOOKIES)
protected:
~BrowsingDataRemoveCookiesFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveDownloadsFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
BROWSINGDATA_REMOVEDOWNLOADS)
protected:
~BrowsingDataRemoveDownloadsFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveFileSystemsFunction
: public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
BROWSINGDATA_REMOVEFILESYSTEMS)
protected:
~BrowsingDataRemoveFileSystemsFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveFormDataFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
BROWSINGDATA_REMOVEFORMDATA)
protected:
~BrowsingDataRemoveFormDataFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveHistoryFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
BROWSINGDATA_REMOVEHISTORY)
protected:
~BrowsingDataRemoveHistoryFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveIndexedDBFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
BROWSINGDATA_REMOVEINDEXEDDB)
protected:
~BrowsingDataRemoveIndexedDBFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveLocalStorageFunction
: public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
BROWSINGDATA_REMOVELOCALSTORAGE)
protected:
~BrowsingDataRemoveLocalStorageFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemovePluginDataFunction
: public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
BROWSINGDATA_REMOVEPLUGINDATA)
protected:
~BrowsingDataRemovePluginDataFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemovePasswordsFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
BROWSINGDATA_REMOVEPASSWORDS)
protected:
~BrowsingDataRemovePasswordsFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveServiceWorkersFunction
: public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeServiceWorkers",
BROWSINGDATA_REMOVESERVICEWORKERS)
protected:
~BrowsingDataRemoveServiceWorkersFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveCacheStorageFunction
: public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeCacheStorage",
BROWSINGDATA_REMOVECACHESTORAGE)
protected:
~BrowsingDataRemoveCacheStorageFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
class BrowsingDataRemoveWebSQLFunction : public BrowsingDataRemoverFunction {
public:
DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
BROWSINGDATA_REMOVEWEBSQL)
protected:
~BrowsingDataRemoveWebSQLFunction() override {}
// BrowsingDataRemoverFunction:
bool GetRemovalMask(int* removal_mask) override;
};
#endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
|