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

Side by Side Diff: extensions/common/features/simple_feature.cc

Issue 2236443003: extensions: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't add braces Created 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "extensions/common/features/simple_feature.h" 5 #include "extensions/common/features/simple_feature.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 Manifest::Location location, 392 Manifest::Location location,
393 int manifest_version, 393 int manifest_version,
394 Platform platform) const { 394 Platform platform) const {
395 // Check extension type first to avoid granting platform app permissions 395 // Check extension type first to avoid granting platform app permissions
396 // to component extensions. 396 // to component extensions.
397 // HACK(kalman): user script -> extension. Solve this in a more generic way 397 // HACK(kalman): user script -> extension. Solve this in a more generic way
398 // when we compile feature files. 398 // when we compile feature files.
399 Manifest::Type type_to_check = (type == Manifest::TYPE_USER_SCRIPT) ? 399 Manifest::Type type_to_check = (type == Manifest::TYPE_USER_SCRIPT) ?
400 Manifest::TYPE_EXTENSION : type; 400 Manifest::TYPE_EXTENSION : type;
401 if (!extension_types_.empty() && 401 if (!extension_types_.empty() &&
402 !ContainsValue(extension_types_, type_to_check)) { 402 !base::ContainsValue(extension_types_, type_to_check)) {
403 return CreateAvailability(INVALID_TYPE, type); 403 return CreateAvailability(INVALID_TYPE, type);
404 } 404 }
405 405
406 if (IsIdInBlacklist(extension_id)) 406 if (IsIdInBlacklist(extension_id))
407 return CreateAvailability(FOUND_IN_BLACKLIST, type); 407 return CreateAvailability(FOUND_IN_BLACKLIST, type);
408 408
409 // TODO(benwells): don't grant all component extensions. 409 // TODO(benwells): don't grant all component extensions.
410 // See http://crbug.com/370375 for more details. 410 // See http://crbug.com/370375 for more details.
411 // Component extensions can access any feature. 411 // Component extensions can access any feature.
412 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. 412 // NOTE: Deliberately does not match EXTERNAL_COMPONENT.
413 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) 413 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT)
414 return CreateAvailability(IS_AVAILABLE, type); 414 return CreateAvailability(IS_AVAILABLE, type);
415 415
416 if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) && 416 if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) &&
417 !IsWhitelistedForTest(extension_id)) { 417 !IsWhitelistedForTest(extension_id)) {
418 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); 418 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type);
419 } 419 }
420 420
421 if (!MatchesManifestLocation(location)) 421 if (!MatchesManifestLocation(location))
422 return CreateAvailability(INVALID_LOCATION, type); 422 return CreateAvailability(INVALID_LOCATION, type);
423 423
424 if (!platforms_.empty() && !ContainsValue(platforms_, platform)) 424 if (!platforms_.empty() && !base::ContainsValue(platforms_, platform))
425 return CreateAvailability(INVALID_PLATFORM, type); 425 return CreateAvailability(INVALID_PLATFORM, type);
426 426
427 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) 427 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
428 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); 428 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type);
429 429
430 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) 430 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_)
431 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); 431 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type);
432 432
433 if (!command_line_switch_.empty() && 433 if (!command_line_switch_.empty() &&
434 !IsCommandLineSwitchEnabled(command_line_switch_)) { 434 !IsCommandLineSwitchEnabled(command_line_switch_)) {
(...skipping 23 matching lines...) Expand all
458 extension->manifest_version(), 458 extension->manifest_version(),
459 platform); 459 platform);
460 if (!result.is_available()) 460 if (!result.is_available())
461 return result; 461 return result;
462 } 462 }
463 463
464 // TODO(lazyboy): This isn't quite right for Extension Service Worker 464 // TODO(lazyboy): This isn't quite right for Extension Service Worker
465 // extension API calls, since there's no guarantee that the extension is 465 // extension API calls, since there's no guarantee that the extension is
466 // "active" in current renderer process when the API permission check is 466 // "active" in current renderer process when the API permission check is
467 // done. 467 // done.
468 if (!contexts_.empty() && !ContainsValue(contexts_, context)) 468 if (!contexts_.empty() && !base::ContainsValue(contexts_, context))
469 return CreateAvailability(INVALID_CONTEXT, context); 469 return CreateAvailability(INVALID_CONTEXT, context);
470 470
471 // TODO(kalman): Consider checking |matches_| regardless of context type. 471 // TODO(kalman): Consider checking |matches_| regardless of context type.
472 // Fewer surprises, and if the feature configuration wants to isolate 472 // Fewer surprises, and if the feature configuration wants to isolate
473 // "matches" from say "blessed_extension" then they can use complex features. 473 // "matches" from say "blessed_extension" then they can use complex features.
474 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) && 474 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) &&
475 !matches_.MatchesURL(url)) { 475 !matches_.MatchesURL(url)) {
476 return CreateAvailability(INVALID_URL, url); 476 return CreateAvailability(INVALID_URL, url);
477 } 477 }
478 478
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 return ((std::find(start, end, extension_id) != end) || 615 return ((std::find(start, end, extension_id) != end) ||
616 (std::find(start, end, HashedIdInHex(extension_id)) != end)); 616 (std::find(start, end, HashedIdInHex(extension_id)) != end));
617 } 617 }
618 618
619 // static 619 // static
620 bool SimpleFeature::IsIdInList(const std::string& extension_id, 620 bool SimpleFeature::IsIdInList(const std::string& extension_id,
621 const std::vector<std::string>& list) { 621 const std::vector<std::string>& list) {
622 if (!IsValidExtensionId(extension_id)) 622 if (!IsValidExtensionId(extension_id))
623 return false; 623 return false;
624 624
625 return (ContainsValue(list, extension_id) || 625 return (base::ContainsValue(list, extension_id) ||
626 ContainsValue(list, HashedIdInHex(extension_id))); 626 base::ContainsValue(list, HashedIdInHex(extension_id)));
627 } 627 }
628 628
629 bool SimpleFeature::MatchesManifestLocation( 629 bool SimpleFeature::MatchesManifestLocation(
630 Manifest::Location manifest_location) const { 630 Manifest::Location manifest_location) const {
631 switch (location_) { 631 switch (location_) {
632 case SimpleFeature::UNSPECIFIED_LOCATION: 632 case SimpleFeature::UNSPECIFIED_LOCATION:
633 return true; 633 return true;
634 case SimpleFeature::COMPONENT_LOCATION: 634 case SimpleFeature::COMPONENT_LOCATION:
635 return manifest_location == Manifest::COMPONENT; 635 return manifest_location == Manifest::COMPONENT;
636 case SimpleFeature::EXTERNAL_COMPONENT_LOCATION: 636 case SimpleFeature::EXTERNAL_COMPONENT_LOCATION:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 void SimpleFeature::set_platforms(std::initializer_list<Platform> platforms) { 701 void SimpleFeature::set_platforms(std::initializer_list<Platform> platforms) {
702 platforms_ = platforms; 702 platforms_ = platforms;
703 } 703 }
704 704
705 void SimpleFeature::set_whitelist( 705 void SimpleFeature::set_whitelist(
706 std::initializer_list<const char* const> whitelist) { 706 std::initializer_list<const char* const> whitelist) {
707 whitelist_.assign(whitelist.begin(), whitelist.end()); 707 whitelist_.assign(whitelist.begin(), whitelist.end());
708 } 708 }
709 709
710 } // namespace extensions 710 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/base_feature_provider_unittest.cc ('k') | extensions/common/features/simple_feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698