Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/extensions/api/browsing_data/browsing_data_api.cc

Issue 21050002: Move browsing data API functions registrations out of ExtensionFunctionRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Defines the Chrome Extensions BrowsingData API functions, which entail 5 // Defines the Chrome Extensions BrowsingData API functions, which entail
6 // clearing browsing data, and clearing the browser's cache (which, let's be 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. 7 // honest, are the same thing), as specified in the extension API JSON.
8 8
9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" 9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
10 10
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 base::DictionaryValue* selected_dict, 210 base::DictionaryValue* selected_dict,
211 base::DictionaryValue* permitted_dict, 211 base::DictionaryValue* permitted_dict,
212 const char* data_type, 212 const char* data_type,
213 bool is_selected) { 213 bool is_selected) {
214 bool is_permitted = IsRemovalPermitted(MaskForKey(data_type), 214 bool is_permitted = IsRemovalPermitted(MaskForKey(data_type),
215 profile()->GetPrefs()); 215 profile()->GetPrefs());
216 selected_dict->SetBoolean(data_type, is_selected && is_permitted); 216 selected_dict->SetBoolean(data_type, is_selected && is_permitted);
217 permitted_dict->SetBoolean(data_type, is_permitted); 217 permitted_dict->SetBoolean(data_type, is_permitted);
218 } 218 }
219 219
220 void BrowsingDataRemoveFunction::OnBrowsingDataRemoverDone() { 220 void BrowsingDataRemoverFunction::OnBrowsingDataRemoverDone() {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222 this->SendResponse(true); 222 this->SendResponse(true);
223 223
224 Release(); // Balanced in RunImpl. 224 Release(); // Balanced in RunImpl.
225 } 225 }
226 226
227 bool BrowsingDataRemoveFunction::RunImpl() { 227 bool BrowsingDataRemoverFunction::RunImpl() {
228 // If we don't have a profile, something's pretty wrong. 228 // If we don't have a profile, something's pretty wrong.
229 DCHECK(profile()); 229 DCHECK(profile());
230 230
231 // Grab the initial |options| parameter, and parse out the arguments. 231 // Grab the initial |options| parameter, and parse out the arguments.
232 base::DictionaryValue* options; 232 base::DictionaryValue* options;
233 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); 233 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options));
234 DCHECK(options); 234 DCHECK(options);
235 235
236 origin_set_mask_ = ParseOriginSetMask(*options); 236 origin_set_mask_ = ParseOriginSetMask(*options);
237 237
(...skipping 20 matching lines...) Expand all
258 error_ = extension_browsing_data_api_constants::kDeleteProhibitedError; 258 error_ = extension_browsing_data_api_constants::kDeleteProhibitedError;
259 return false; 259 return false;
260 } 260 }
261 261
262 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) { 262 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) {
263 // If we're being asked to remove plugin data, check whether it's actually 263 // If we're being asked to remove plugin data, check whether it's actually
264 // supported. 264 // supported.
265 BrowserThread::PostTask( 265 BrowserThread::PostTask(
266 BrowserThread::FILE, FROM_HERE, 266 BrowserThread::FILE, FROM_HERE,
267 base::Bind( 267 base::Bind(
268 &BrowsingDataRemoveFunction::CheckRemovingPluginDataSupported, 268 &BrowsingDataRemoverFunction::CheckRemovingPluginDataSupported,
269 this, 269 this,
270 PluginPrefs::GetForProfile(profile()))); 270 PluginPrefs::GetForProfile(profile())));
271 } else { 271 } else {
272 StartRemoving(); 272 StartRemoving();
273 } 273 }
274 274
275 // Will finish asynchronously. 275 // Will finish asynchronously.
276 return true; 276 return true;
277 } 277 }
278 278
279 void BrowsingDataRemoveFunction::CheckRemovingPluginDataSupported( 279 void BrowsingDataRemoverFunction::CheckRemovingPluginDataSupported(
280 scoped_refptr<PluginPrefs> plugin_prefs) { 280 scoped_refptr<PluginPrefs> plugin_prefs) {
281 if (!PluginDataRemoverHelper::IsSupported(plugin_prefs.get())) 281 if (!PluginDataRemoverHelper::IsSupported(plugin_prefs.get()))
282 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; 282 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
283 283
284 BrowserThread::PostTask( 284 BrowserThread::PostTask(
285 BrowserThread::UI, FROM_HERE, 285 BrowserThread::UI, FROM_HERE,
286 base::Bind(&BrowsingDataRemoveFunction::StartRemoving, this)); 286 base::Bind(&BrowsingDataRemoverFunction::StartRemoving, this));
287 } 287 }
288 288
289 void BrowsingDataRemoveFunction::StartRemoving() { 289 void BrowsingDataRemoverFunction::StartRemoving() {
290 if (BrowsingDataRemover::is_removing()) { 290 if (BrowsingDataRemover::is_removing()) {
291 error_ = extension_browsing_data_api_constants::kOneAtATimeError; 291 error_ = extension_browsing_data_api_constants::kOneAtATimeError;
292 SendResponse(false); 292 SendResponse(false);
293 return; 293 return;
294 } 294 }
295 295
296 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone) 296 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone)
297 AddRef(); 297 AddRef();
298 298
299 // Create a BrowsingDataRemover, set the current object as an observer (so 299 // Create a BrowsingDataRemover, set the current object as an observer (so
300 // that we're notified after removal) and call remove() with the arguments 300 // that we're notified after removal) and call remove() with the arguments
301 // we've generated above. We can use a raw pointer here, as the browsing data 301 // we've generated above. We can use a raw pointer here, as the browsing data
302 // remover is responsible for deleting itself once data removal is complete. 302 // remover is responsible for deleting itself once data removal is complete.
303 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForRange(profile(), 303 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForRange(profile(),
304 remove_since_, base::Time::Max()); 304 remove_since_, base::Time::Max());
305 remover->AddObserver(this); 305 remover->AddObserver(this);
306 remover->Remove(removal_mask_, origin_set_mask_); 306 remover->Remove(removal_mask_, origin_set_mask_);
307 } 307 }
308 308
309 int BrowsingDataRemoveFunction::ParseOriginSetMask( 309 int BrowsingDataRemoverFunction::ParseOriginSetMask(
310 const base::DictionaryValue& options) { 310 const base::DictionaryValue& options) {
311 // Parse the |options| dictionary to generate the origin set mask. Default to 311 // Parse the |options| dictionary to generate the origin set mask. Default to
312 // UNPROTECTED_WEB if the developer doesn't specify anything. 312 // UNPROTECTED_WEB if the developer doesn't specify anything.
313 int mask = BrowsingDataHelper::UNPROTECTED_WEB; 313 int mask = BrowsingDataHelper::UNPROTECTED_WEB;
314 314
315 const base::DictionaryValue* d = NULL; 315 const base::DictionaryValue* d = NULL;
316 if (options.HasKey(extension_browsing_data_api_constants::kOriginTypesKey)) { 316 if (options.HasKey(extension_browsing_data_api_constants::kOriginTypesKey)) {
317 EXTENSION_FUNCTION_VALIDATE(options.GetDictionary( 317 EXTENSION_FUNCTION_VALIDATE(options.GetDictionary(
318 extension_browsing_data_api_constants::kOriginTypesKey, &d)); 318 extension_browsing_data_api_constants::kOriginTypesKey, &d));
319 bool value; 319 bool value;
(...skipping 23 matching lines...) Expand all
343 } 343 }
344 } 344 }
345 345
346 return mask; 346 return mask;
347 } 347 }
348 348
349 // Parses the |dataToRemove| argument to generate the removal mask. Sets 349 // Parses the |dataToRemove| argument to generate the removal mask. Sets
350 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool 350 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool
351 // method) if 'dataToRemove' is not present or any data-type keys don't have 351 // method) if 'dataToRemove' is not present or any data-type keys don't have
352 // supported (boolean) values. 352 // supported (boolean) values.
353 int RemoveBrowsingDataFunction::GetRemovalMask() { 353 int BrowsingDataRemoveFunction::GetRemovalMask() {
354 base::DictionaryValue* data_to_remove; 354 base::DictionaryValue* data_to_remove;
355 if (!args_->GetDictionary(1, &data_to_remove)) { 355 if (!args_->GetDictionary(1, &data_to_remove)) {
356 bad_message_ = true; 356 bad_message_ = true;
357 return 0; 357 return 0;
358 } 358 }
359 359
360 int removal_mask = 0; 360 int removal_mask = 0;
361 361
362 for (base::DictionaryValue::Iterator i(*data_to_remove); 362 for (base::DictionaryValue::Iterator i(*data_to_remove);
363 !i.IsAtEnd(); 363 !i.IsAtEnd();
364 i.Advance()) { 364 i.Advance()) {
365 bool selected = false; 365 bool selected = false;
366 if (!i.value().GetAsBoolean(&selected)) { 366 if (!i.value().GetAsBoolean(&selected)) {
367 bad_message_ = true; 367 bad_message_ = true;
368 return 0; 368 return 0;
369 } 369 }
370 if (selected) 370 if (selected)
371 removal_mask |= MaskForKey(i.key().c_str()); 371 removal_mask |= MaskForKey(i.key().c_str());
372 } 372 }
373 373
374 return removal_mask; 374 return removal_mask;
375 } 375 }
376 376
377 int RemoveAppCacheFunction::GetRemovalMask() { 377 int BrowsingDataRemoveAppcacheFunction::GetRemovalMask() {
378 return BrowsingDataRemover::REMOVE_APPCACHE; 378 return BrowsingDataRemover::REMOVE_APPCACHE;
379 } 379 }
380 380
381 int RemoveCacheFunction::GetRemovalMask() { 381 int BrowsingDataRemoveCacheFunction::GetRemovalMask() {
382 return BrowsingDataRemover::REMOVE_CACHE; 382 return BrowsingDataRemover::REMOVE_CACHE;
383 } 383 }
384 384
385 int RemoveCookiesFunction::GetRemovalMask() { 385 int BrowsingDataRemoveCookiesFunction::GetRemovalMask() {
386 return BrowsingDataRemover::REMOVE_COOKIES | 386 return BrowsingDataRemover::REMOVE_COOKIES |
387 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS; 387 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS;
388 } 388 }
389 389
390 int RemoveDownloadsFunction::GetRemovalMask() { 390 int BrowsingDataRemoveDownloadsFunction::GetRemovalMask() {
391 return BrowsingDataRemover::REMOVE_DOWNLOADS; 391 return BrowsingDataRemover::REMOVE_DOWNLOADS;
392 } 392 }
393 393
394 int RemoveFileSystemsFunction::GetRemovalMask() { 394 int BrowsingDataRemoveFileSystemsFunction::GetRemovalMask() {
395 return BrowsingDataRemover::REMOVE_FILE_SYSTEMS; 395 return BrowsingDataRemover::REMOVE_FILE_SYSTEMS;
396 } 396 }
397 397
398 int RemoveFormDataFunction::GetRemovalMask() { 398 int BrowsingDataRemoveFormDataFunction::GetRemovalMask() {
399 return BrowsingDataRemover::REMOVE_FORM_DATA; 399 return BrowsingDataRemover::REMOVE_FORM_DATA;
400 } 400 }
401 401
402 int RemoveHistoryFunction::GetRemovalMask() { 402 int BrowsingDataRemoveHistoryFunction::GetRemovalMask() {
403 return BrowsingDataRemover::REMOVE_HISTORY; 403 return BrowsingDataRemover::REMOVE_HISTORY;
404 } 404 }
405 405
406 int RemoveIndexedDBFunction::GetRemovalMask() { 406 int BrowsingDataRemoveIndexedDBFunction::GetRemovalMask() {
407 return BrowsingDataRemover::REMOVE_INDEXEDDB; 407 return BrowsingDataRemover::REMOVE_INDEXEDDB;
408 } 408 }
409 409
410 int RemoveLocalStorageFunction::GetRemovalMask() { 410 int BrowsingDataRemoveLocalStorageFunction::GetRemovalMask() {
411 return BrowsingDataRemover::REMOVE_LOCAL_STORAGE; 411 return BrowsingDataRemover::REMOVE_LOCAL_STORAGE;
412 } 412 }
413 413
414 int RemovePluginDataFunction::GetRemovalMask() { 414 int BrowsingDataRemovePluginDataFunction::GetRemovalMask() {
415 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; 415 return BrowsingDataRemover::REMOVE_PLUGIN_DATA;
416 } 416 }
417 417
418 int RemovePasswordsFunction::GetRemovalMask() { 418 int BrowsingDataRemovePasswordsFunction::GetRemovalMask() {
419 return BrowsingDataRemover::REMOVE_PASSWORDS; 419 return BrowsingDataRemover::REMOVE_PASSWORDS;
420 } 420 }
421 421
422 int RemoveWebSQLFunction::GetRemovalMask() { 422 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() {
423 return BrowsingDataRemover::REMOVE_WEBSQL; 423 return BrowsingDataRemover::REMOVE_WEBSQL;
424 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698