| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 bool BrowsingDataRemoverFunction::RunAsync() { | 247 bool BrowsingDataRemoverFunction::RunAsync() { |
| 248 // If we don't have a profile, something's pretty wrong. | 248 // If we don't have a profile, something's pretty wrong. |
| 249 DCHECK(GetProfile()); | 249 DCHECK(GetProfile()); |
| 250 | 250 |
| 251 // Grab the initial |options| parameter, and parse out the arguments. | 251 // Grab the initial |options| parameter, and parse out the arguments. |
| 252 base::DictionaryValue* options; | 252 base::DictionaryValue* options; |
| 253 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); | 253 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); |
| 254 DCHECK(options); | 254 DCHECK(options); |
| 255 | 255 |
| 256 origin_type_mask_ = ParseOriginTypeMask(*options); | 256 EXTENSION_FUNCTION_VALIDATE( |
| 257 ParseOriginTypeMask(*options, &origin_type_mask_)); |
| 257 | 258 |
| 258 // If |ms_since_epoch| isn't set, default it to 0. | 259 // If |ms_since_epoch| isn't set, default it to 0. |
| 259 double ms_since_epoch; | 260 double ms_since_epoch; |
| 260 if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey, | 261 if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey, |
| 261 &ms_since_epoch)) | 262 &ms_since_epoch)) |
| 262 ms_since_epoch = 0; | 263 ms_since_epoch = 0; |
| 263 | 264 |
| 264 // base::Time takes a double that represents seconds since epoch. JavaScript | 265 // base::Time takes a double that represents seconds since epoch. JavaScript |
| 265 // gives developers milliseconds, so do a quick conversion before populating | 266 // gives developers milliseconds, so do a quick conversion before populating |
| 266 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time | 267 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // Create a BrowsingDataRemover, set the current object as an observer (so | 317 // Create a BrowsingDataRemover, set the current object as an observer (so |
| 317 // that we're notified after removal) and call remove() with the arguments | 318 // that we're notified after removal) and call remove() with the arguments |
| 318 // we've generated above. We can use a raw pointer here, as the browsing data | 319 // we've generated above. We can use a raw pointer here, as the browsing data |
| 319 // remover is responsible for deleting itself once data removal is complete. | 320 // remover is responsible for deleting itself once data removal is complete. |
| 320 observer_.Add(remover); | 321 observer_.Add(remover); |
| 321 remover->RemoveAndReply( | 322 remover->RemoveAndReply( |
| 322 remove_since_, base::Time::Max(), | 323 remove_since_, base::Time::Max(), |
| 323 removal_mask_, origin_type_mask_, this); | 324 removal_mask_, origin_type_mask_, this); |
| 324 } | 325 } |
| 325 | 326 |
| 326 int BrowsingDataRemoverFunction::ParseOriginTypeMask( | 327 bool BrowsingDataRemoverFunction::ParseOriginTypeMask( |
| 327 const base::DictionaryValue& options) { | 328 const base::DictionaryValue& options, |
| 329 int* origin_type_mask) { |
| 328 // Parse the |options| dictionary to generate the origin set mask. Default to | 330 // Parse the |options| dictionary to generate the origin set mask. Default to |
| 329 // UNPROTECTED_WEB if the developer doesn't specify anything. | 331 // UNPROTECTED_WEB if the developer doesn't specify anything. |
| 330 int mask = BrowsingDataHelper::UNPROTECTED_WEB; | 332 *origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB; |
| 331 | 333 |
| 332 const base::DictionaryValue* d = NULL; | 334 const base::DictionaryValue* d = NULL; |
| 333 if (options.HasKey(extension_browsing_data_api_constants::kOriginTypesKey)) { | 335 if (options.HasKey(extension_browsing_data_api_constants::kOriginTypesKey)) { |
| 334 EXTENSION_FUNCTION_VALIDATE(options.GetDictionary( | 336 if (!options.GetDictionary( |
| 335 extension_browsing_data_api_constants::kOriginTypesKey, &d)); | 337 extension_browsing_data_api_constants::kOriginTypesKey, &d)) { |
| 338 return false; |
| 339 } |
| 336 bool value; | 340 bool value; |
| 337 | 341 |
| 338 // The developer specified something! Reset to 0 and parse the dictionary. | 342 // The developer specified something! Reset to 0 and parse the dictionary. |
| 339 mask = 0; | 343 *origin_type_mask = 0; |
| 340 | 344 |
| 341 // Unprotected web. | 345 // Unprotected web. |
| 342 if (d->HasKey(extension_browsing_data_api_constants::kUnprotectedWebKey)) { | 346 if (d->HasKey(extension_browsing_data_api_constants::kUnprotectedWebKey)) { |
| 343 EXTENSION_FUNCTION_VALIDATE(d->GetBoolean( | 347 if (!d->GetBoolean( |
| 344 extension_browsing_data_api_constants::kUnprotectedWebKey, &value)); | 348 extension_browsing_data_api_constants::kUnprotectedWebKey, |
| 345 mask |= value ? BrowsingDataHelper::UNPROTECTED_WEB : 0; | 349 &value)) { |
| 350 return false; |
| 351 } |
| 352 *origin_type_mask |= value ? BrowsingDataHelper::UNPROTECTED_WEB : 0; |
| 346 } | 353 } |
| 347 | 354 |
| 348 // Protected web. | 355 // Protected web. |
| 349 if (d->HasKey(extension_browsing_data_api_constants::kProtectedWebKey)) { | 356 if (d->HasKey(extension_browsing_data_api_constants::kProtectedWebKey)) { |
| 350 EXTENSION_FUNCTION_VALIDATE(d->GetBoolean( | 357 if (!d->GetBoolean( |
| 351 extension_browsing_data_api_constants::kProtectedWebKey, &value)); | 358 extension_browsing_data_api_constants::kProtectedWebKey, |
| 352 mask |= value ? BrowsingDataHelper::PROTECTED_WEB : 0; | 359 &value)) { |
| 360 return false; |
| 361 } |
| 362 *origin_type_mask |= value ? BrowsingDataHelper::PROTECTED_WEB : 0; |
| 353 } | 363 } |
| 354 | 364 |
| 355 // Extensions. | 365 // Extensions. |
| 356 if (d->HasKey(extension_browsing_data_api_constants::kExtensionsKey)) { | 366 if (d->HasKey(extension_browsing_data_api_constants::kExtensionsKey)) { |
| 357 EXTENSION_FUNCTION_VALIDATE(d->GetBoolean( | 367 if (!d->GetBoolean(extension_browsing_data_api_constants::kExtensionsKey, |
| 358 extension_browsing_data_api_constants::kExtensionsKey, &value)); | 368 &value)) { |
| 359 mask |= value ? BrowsingDataHelper::EXTENSION : 0; | 369 return false; |
| 370 } |
| 371 *origin_type_mask |= value ? BrowsingDataHelper::EXTENSION : 0; |
| 360 } | 372 } |
| 361 } | 373 } |
| 362 | 374 |
| 363 return mask; | 375 return true; |
| 364 } | 376 } |
| 365 | 377 |
| 366 // Parses the |dataToRemove| argument to generate the removal mask. | 378 // Parses the |dataToRemove| argument to generate the removal mask. |
| 367 // Returns false if parse was not successful, i.e. if 'dataToRemove' is not | 379 // Returns false if parse was not successful, i.e. if 'dataToRemove' is not |
| 368 // present or any data-type keys don't have supported (boolean) values. | 380 // present or any data-type keys don't have supported (boolean) values. |
| 369 bool BrowsingDataRemoveFunction::GetRemovalMask(int* removal_mask) { | 381 bool BrowsingDataRemoveFunction::GetRemovalMask(int* removal_mask) { |
| 370 base::DictionaryValue* data_to_remove; | 382 base::DictionaryValue* data_to_remove; |
| 371 if (!args_->GetDictionary(1, &data_to_remove)) | 383 if (!args_->GetDictionary(1, &data_to_remove)) |
| 372 return false; | 384 return false; |
| 373 | 385 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 461 |
| 450 bool BrowsingDataRemoveCacheStorageFunction::GetRemovalMask(int* removal_mask) { | 462 bool BrowsingDataRemoveCacheStorageFunction::GetRemovalMask(int* removal_mask) { |
| 451 *removal_mask = BrowsingDataRemover::REMOVE_CACHE_STORAGE; | 463 *removal_mask = BrowsingDataRemover::REMOVE_CACHE_STORAGE; |
| 452 return true; | 464 return true; |
| 453 } | 465 } |
| 454 | 466 |
| 455 bool BrowsingDataRemoveWebSQLFunction::GetRemovalMask(int* removal_mask) { | 467 bool BrowsingDataRemoveWebSQLFunction::GetRemovalMask(int* removal_mask) { |
| 456 *removal_mask = BrowsingDataRemover::REMOVE_WEBSQL; | 468 *removal_mask = BrowsingDataRemover::REMOVE_WEBSQL; |
| 457 return true; | 469 return true; |
| 458 } | 470 } |
| OLD | NEW |