| OLD | NEW |
| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 ms_since_epoch = 0; | 262 ms_since_epoch = 0; |
| 263 | 263 |
| 264 // base::Time takes a double that represents seconds since epoch. JavaScript | 264 // base::Time takes a double that represents seconds since epoch. JavaScript |
| 265 // gives developers milliseconds, so do a quick conversion before populating | 265 // gives developers milliseconds, so do a quick conversion before populating |
| 266 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time | 266 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time |
| 267 // object. So we need to do special handling here. | 267 // object. So we need to do special handling here. |
| 268 remove_since_ = (ms_since_epoch == 0) ? | 268 remove_since_ = (ms_since_epoch == 0) ? |
| 269 base::Time::UnixEpoch() : | 269 base::Time::UnixEpoch() : |
| 270 base::Time::FromDoubleT(ms_since_epoch / 1000.0); | 270 base::Time::FromDoubleT(ms_since_epoch / 1000.0); |
| 271 | 271 |
| 272 removal_mask_ = GetRemovalMask(); | 272 EXTENSION_FUNCTION_VALIDATE(GetRemovalMask(&removal_mask_)); |
| 273 if (bad_message()) | |
| 274 return false; | |
| 275 | 273 |
| 276 // Check for prohibited data types. | 274 // Check for prohibited data types. |
| 277 if (!IsRemovalPermitted(removal_mask_, GetProfile()->GetPrefs())) { | 275 if (!IsRemovalPermitted(removal_mask_, GetProfile()->GetPrefs())) { |
| 278 error_ = extension_browsing_data_api_constants::kDeleteProhibitedError; | 276 error_ = extension_browsing_data_api_constants::kDeleteProhibitedError; |
| 279 return false; | 277 return false; |
| 280 } | 278 } |
| 281 | 279 |
| 282 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) { | 280 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) { |
| 283 // If we're being asked to remove plugin data, check whether it's actually | 281 // If we're being asked to remove plugin data, check whether it's actually |
| 284 // supported. | 282 // supported. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (d->HasKey(extension_browsing_data_api_constants::kExtensionsKey)) { | 356 if (d->HasKey(extension_browsing_data_api_constants::kExtensionsKey)) { |
| 359 EXTENSION_FUNCTION_VALIDATE(d->GetBoolean( | 357 EXTENSION_FUNCTION_VALIDATE(d->GetBoolean( |
| 360 extension_browsing_data_api_constants::kExtensionsKey, &value)); | 358 extension_browsing_data_api_constants::kExtensionsKey, &value)); |
| 361 mask |= value ? BrowsingDataHelper::EXTENSION : 0; | 359 mask |= value ? BrowsingDataHelper::EXTENSION : 0; |
| 362 } | 360 } |
| 363 } | 361 } |
| 364 | 362 |
| 365 return mask; | 363 return mask; |
| 366 } | 364 } |
| 367 | 365 |
| 368 // Parses the |dataToRemove| argument to generate the removal mask. Sets | 366 // Parses the |dataToRemove| argument to generate the removal mask. |
| 369 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool | 367 // Returns false if parse was not successful, i.e. if 'dataToRemove' is not |
| 370 // method) if 'dataToRemove' is not present or any data-type keys don't have | 368 // present or any data-type keys don't have supported (boolean) values. |
| 371 // supported (boolean) values. | 369 bool BrowsingDataRemoveFunction::GetRemovalMask(int* removal_mask) { |
| 372 int BrowsingDataRemoveFunction::GetRemovalMask() { | |
| 373 base::DictionaryValue* data_to_remove; | 370 base::DictionaryValue* data_to_remove; |
| 374 if (!args_->GetDictionary(1, &data_to_remove)) { | 371 if (!args_->GetDictionary(1, &data_to_remove)) |
| 375 set_bad_message(true); | 372 return false; |
| 376 return 0; | |
| 377 } | |
| 378 | 373 |
| 379 int removal_mask = 0; | 374 *removal_mask = 0; |
| 380 | |
| 381 for (base::DictionaryValue::Iterator i(*data_to_remove); | 375 for (base::DictionaryValue::Iterator i(*data_to_remove); |
| 382 !i.IsAtEnd(); | 376 !i.IsAtEnd(); |
| 383 i.Advance()) { | 377 i.Advance()) { |
| 384 bool selected = false; | 378 bool selected = false; |
| 385 if (!i.value().GetAsBoolean(&selected)) { | 379 if (!i.value().GetAsBoolean(&selected)) |
| 386 set_bad_message(true); | 380 return false; |
| 387 return 0; | |
| 388 } | |
| 389 if (selected) | 381 if (selected) |
| 390 removal_mask |= MaskForKey(i.key().c_str()); | 382 *removal_mask |= MaskForKey(i.key().c_str()); |
| 391 } | 383 } |
| 392 | 384 |
| 393 return removal_mask; | 385 return true; |
| 394 } | 386 } |
| 395 | 387 |
| 396 int BrowsingDataRemoveAppcacheFunction::GetRemovalMask() { | 388 bool BrowsingDataRemoveAppcacheFunction::GetRemovalMask(int* removal_mask) { |
| 397 return BrowsingDataRemover::REMOVE_APPCACHE; | 389 *removal_mask = BrowsingDataRemover::REMOVE_APPCACHE; |
| 390 return true; |
| 398 } | 391 } |
| 399 | 392 |
| 400 int BrowsingDataRemoveCacheFunction::GetRemovalMask() { | 393 bool BrowsingDataRemoveCacheFunction::GetRemovalMask(int* removal_mask) { |
| 401 return BrowsingDataRemover::REMOVE_CACHE; | 394 *removal_mask = BrowsingDataRemover::REMOVE_CACHE; |
| 395 return true; |
| 402 } | 396 } |
| 403 | 397 |
| 404 int BrowsingDataRemoveCookiesFunction::GetRemovalMask() { | 398 bool BrowsingDataRemoveCookiesFunction::GetRemovalMask(int* removal_mask) { |
| 405 return BrowsingDataRemover::REMOVE_COOKIES | | 399 *removal_mask = BrowsingDataRemover::REMOVE_COOKIES | |
| 406 BrowsingDataRemover::REMOVE_CHANNEL_IDS; | 400 BrowsingDataRemover::REMOVE_CHANNEL_IDS; |
| 401 return true; |
| 407 } | 402 } |
| 408 | 403 |
| 409 int BrowsingDataRemoveDownloadsFunction::GetRemovalMask() { | 404 bool BrowsingDataRemoveDownloadsFunction::GetRemovalMask(int* removal_mask) { |
| 410 return BrowsingDataRemover::REMOVE_DOWNLOADS; | 405 *removal_mask = BrowsingDataRemover::REMOVE_DOWNLOADS; |
| 406 return true; |
| 411 } | 407 } |
| 412 | 408 |
| 413 int BrowsingDataRemoveFileSystemsFunction::GetRemovalMask() { | 409 bool BrowsingDataRemoveFileSystemsFunction::GetRemovalMask(int* removal_mask) { |
| 414 return BrowsingDataRemover::REMOVE_FILE_SYSTEMS; | 410 *removal_mask = BrowsingDataRemover::REMOVE_FILE_SYSTEMS; |
| 411 return true; |
| 415 } | 412 } |
| 416 | 413 |
| 417 int BrowsingDataRemoveFormDataFunction::GetRemovalMask() { | 414 bool BrowsingDataRemoveFormDataFunction::GetRemovalMask(int* removal_mask) { |
| 418 return BrowsingDataRemover::REMOVE_FORM_DATA; | 415 *removal_mask = BrowsingDataRemover::REMOVE_FORM_DATA; |
| 416 return true; |
| 419 } | 417 } |
| 420 | 418 |
| 421 int BrowsingDataRemoveHistoryFunction::GetRemovalMask() { | 419 bool BrowsingDataRemoveHistoryFunction::GetRemovalMask(int* removal_mask) { |
| 422 return BrowsingDataRemover::REMOVE_HISTORY; | 420 *removal_mask = BrowsingDataRemover::REMOVE_HISTORY; |
| 421 return true; |
| 423 } | 422 } |
| 424 | 423 |
| 425 int BrowsingDataRemoveIndexedDBFunction::GetRemovalMask() { | 424 bool BrowsingDataRemoveIndexedDBFunction::GetRemovalMask(int* removal_mask) { |
| 426 return BrowsingDataRemover::REMOVE_INDEXEDDB; | 425 *removal_mask = BrowsingDataRemover::REMOVE_INDEXEDDB; |
| 426 return true; |
| 427 } | 427 } |
| 428 | 428 |
| 429 int BrowsingDataRemoveLocalStorageFunction::GetRemovalMask() { | 429 bool BrowsingDataRemoveLocalStorageFunction::GetRemovalMask(int* removal_mask) { |
| 430 return BrowsingDataRemover::REMOVE_LOCAL_STORAGE; | 430 *removal_mask = BrowsingDataRemover::REMOVE_LOCAL_STORAGE; |
| 431 return true; |
| 431 } | 432 } |
| 432 | 433 |
| 433 int BrowsingDataRemovePluginDataFunction::GetRemovalMask() { | 434 bool BrowsingDataRemovePluginDataFunction::GetRemovalMask(int* removal_mask) { |
| 434 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 435 *removal_mask = BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
| 436 return true; |
| 435 } | 437 } |
| 436 | 438 |
| 437 int BrowsingDataRemovePasswordsFunction::GetRemovalMask() { | 439 bool BrowsingDataRemovePasswordsFunction::GetRemovalMask(int* removal_mask) { |
| 438 return BrowsingDataRemover::REMOVE_PASSWORDS; | 440 *removal_mask = BrowsingDataRemover::REMOVE_PASSWORDS; |
| 441 return true; |
| 439 } | 442 } |
| 440 | 443 |
| 441 int BrowsingDataRemoveServiceWorkersFunction::GetRemovalMask() { | 444 bool BrowsingDataRemoveServiceWorkersFunction::GetRemovalMask( |
| 442 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS; | 445 int* removal_mask) { |
| 446 *removal_mask = BrowsingDataRemover::REMOVE_SERVICE_WORKERS; |
| 447 return true; |
| 443 } | 448 } |
| 444 | 449 |
| 445 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() { | 450 bool BrowsingDataRemoveCacheStorageFunction::GetRemovalMask(int* removal_mask) { |
| 446 return BrowsingDataRemover::REMOVE_CACHE_STORAGE; | 451 *removal_mask = BrowsingDataRemover::REMOVE_CACHE_STORAGE; |
| 452 return true; |
| 447 } | 453 } |
| 448 | 454 |
| 449 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() { | 455 bool BrowsingDataRemoveWebSQLFunction::GetRemovalMask(int* removal_mask) { |
| 450 return BrowsingDataRemover::REMOVE_WEBSQL; | 456 *removal_mask = BrowsingDataRemover::REMOVE_WEBSQL; |
| 457 return true; |
| 451 } | 458 } |
| OLD | NEW |