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

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

Issue 2360073002: [Extensions] Isolate ExtensionFunction results_ and error_ (Closed)
Patch Set: lazyboy's Created 4 years, 2 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 // base::Time takes a double that represents seconds since epoch. JavaScript 266 // base::Time takes a double that represents seconds since epoch. JavaScript
267 // gives developers milliseconds, so do a quick conversion before populating 267 // gives developers milliseconds, so do a quick conversion before populating
268 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time 268 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time
269 // object. So we need to do special handling here. 269 // object. So we need to do special handling here.
270 remove_since_ = (ms_since_epoch == 0) ? 270 remove_since_ = (ms_since_epoch == 0) ?
271 base::Time::UnixEpoch() : 271 base::Time::UnixEpoch() :
272 base::Time::FromDoubleT(ms_since_epoch / 1000.0); 272 base::Time::FromDoubleT(ms_since_epoch / 1000.0);
273 273
274 removal_mask_ = GetRemovalMask(); 274 removal_mask_ = GetRemovalMask();
275 if (bad_message_) 275 if (bad_message())
276 return false; 276 return false;
277 277
278 // Check for prohibited data types. 278 // Check for prohibited data types.
279 if (!IsRemovalPermitted(removal_mask_, GetProfile()->GetPrefs())) { 279 if (!IsRemovalPermitted(removal_mask_, GetProfile()->GetPrefs())) {
280 error_ = extension_browsing_data_api_constants::kDeleteProhibitedError; 280 error_ = extension_browsing_data_api_constants::kDeleteProhibitedError;
281 return false; 281 return false;
282 } 282 }
283 283
284 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) { 284 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) {
285 // If we're being asked to remove plugin data, check whether it's actually 285 // If we're being asked to remove plugin data, check whether it's actually
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return mask; 374 return mask;
375 } 375 }
376 376
377 // Parses the |dataToRemove| argument to generate the removal mask. Sets 377 // Parses the |dataToRemove| argument to generate the removal mask. Sets
378 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool 378 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool
379 // method) if 'dataToRemove' is not present or any data-type keys don't have 379 // method) if 'dataToRemove' is not present or any data-type keys don't have
380 // supported (boolean) values. 380 // supported (boolean) values.
381 int BrowsingDataRemoveFunction::GetRemovalMask() { 381 int BrowsingDataRemoveFunction::GetRemovalMask() {
382 base::DictionaryValue* data_to_remove; 382 base::DictionaryValue* data_to_remove;
383 if (!args_->GetDictionary(1, &data_to_remove)) { 383 if (!args_->GetDictionary(1, &data_to_remove)) {
384 bad_message_ = true; 384 set_bad_message(true);
385 return 0; 385 return 0;
386 } 386 }
387 387
388 int removal_mask = 0; 388 int removal_mask = 0;
389 389
390 for (base::DictionaryValue::Iterator i(*data_to_remove); 390 for (base::DictionaryValue::Iterator i(*data_to_remove);
391 !i.IsAtEnd(); 391 !i.IsAtEnd();
392 i.Advance()) { 392 i.Advance()) {
393 bool selected = false; 393 bool selected = false;
394 if (!i.value().GetAsBoolean(&selected)) { 394 if (!i.value().GetAsBoolean(&selected)) {
395 bad_message_ = true; 395 set_bad_message(true);
396 return 0; 396 return 0;
397 } 397 }
398 if (selected) 398 if (selected)
399 removal_mask |= MaskForKey(i.key().c_str()); 399 removal_mask |= MaskForKey(i.key().c_str());
400 } 400 }
401 401
402 return removal_mask; 402 return removal_mask;
403 } 403 }
404 404
405 int BrowsingDataRemoveAppcacheFunction::GetRemovalMask() { 405 int BrowsingDataRemoveAppcacheFunction::GetRemovalMask() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS; 451 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS;
452 } 452 }
453 453
454 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() { 454 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() {
455 return BrowsingDataRemover::REMOVE_CACHE_STORAGE; 455 return BrowsingDataRemover::REMOVE_CACHE_STORAGE;
456 } 456 }
457 457
458 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() { 458 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() {
459 return BrowsingDataRemover::REMOVE_WEBSQL; 459 return BrowsingDataRemover::REMOVE_WEBSQL;
460 } 460 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698