| OLD | NEW |
| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/debug/alias.h" | 13 #include "base/debug/alias.h" |
| 14 #include "base/macros.h" |
| 14 #include "base/sha1.h" | 15 #include "base/sha1.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "extensions/common/extension_api.h" | 20 #include "extensions/common/extension_api.h" |
| 20 #include "extensions/common/features/feature_provider.h" | 21 #include "extensions/common/features/feature_provider.h" |
| 21 #include "extensions/common/switches.h" | 22 #include "extensions/common/switches.h" |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 if (IsIdInBlacklist(extension_id)) | 357 if (IsIdInBlacklist(extension_id)) |
| 357 return CreateAvailability(FOUND_IN_BLACKLIST, type); | 358 return CreateAvailability(FOUND_IN_BLACKLIST, type); |
| 358 | 359 |
| 359 // TODO(benwells): don't grant all component extensions. | 360 // TODO(benwells): don't grant all component extensions. |
| 360 // See http://crbug.com/370375 for more details. | 361 // See http://crbug.com/370375 for more details. |
| 361 // Component extensions can access any feature. | 362 // Component extensions can access any feature. |
| 362 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. | 363 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. |
| 363 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) | 364 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) |
| 364 return CreateAvailability(IS_AVAILABLE, type); | 365 return CreateAvailability(IS_AVAILABLE, type); |
| 365 | 366 |
| 366 if (!whitelist_.empty()) { | 367 if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) && |
| 367 if (!IsIdInWhitelist(extension_id)) { | 368 !IsWhitelistedByCommandLine(extension_id)) { |
| 368 // TODO(aa): This is gross. There should be a better way to test the | 369 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); |
| 369 // whitelist. | |
| 370 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 371 if (!command_line->HasSwitch(switches::kWhitelistedExtensionID)) | |
| 372 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); | |
| 373 | |
| 374 std::string whitelist_switch_value = | |
| 375 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 376 switches::kWhitelistedExtensionID); | |
| 377 if (extension_id != whitelist_switch_value) | |
| 378 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); | |
| 379 } | |
| 380 } | 370 } |
| 381 | 371 |
| 382 if (!MatchesManifestLocation(location)) | 372 if (!MatchesManifestLocation(location)) |
| 383 return CreateAvailability(INVALID_LOCATION, type); | 373 return CreateAvailability(INVALID_LOCATION, type); |
| 384 | 374 |
| 385 if (!platforms_.empty() && !ContainsValue(platforms_, platform)) | 375 if (!platforms_.empty() && !ContainsValue(platforms_, platform)) |
| 386 return CreateAvailability(INVALID_PLATFORM, type); | 376 return CreateAvailability(INVALID_PLATFORM, type); |
| 387 | 377 |
| 388 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) | 378 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) |
| 389 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); | 379 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 // static | 605 // static |
| 616 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { | 606 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { |
| 617 // Belt-and-suspenders philosophy here. We should be pretty confident by this | 607 // Belt-and-suspenders philosophy here. We should be pretty confident by this |
| 618 // point that we've validated the extension ID format, but in case something | 608 // point that we've validated the extension ID format, but in case something |
| 619 // slips through, we avoid a class of attack where creative ID manipulation | 609 // slips through, we avoid a class of attack where creative ID manipulation |
| 620 // leads to hash collisions. | 610 // leads to hash collisions. |
| 621 // 128 bits / 4 = 32 mpdecimal characters | 611 // 128 bits / 4 = 32 mpdecimal characters |
| 622 return (extension_id.length() == 32); | 612 return (extension_id.length() == 32); |
| 623 } | 613 } |
| 624 | 614 |
| 615 // static |
| 616 bool SimpleFeature::IsWhitelistedByCommandLine( |
| 617 const std::string& extension_id) { |
| 618 // A singleton copy of the --whitelisted-extension-id so that we don't need to |
| 619 // copy it from the CommandLine each time. |
| 620 CR_DEFINE_STATIC_LOCAL( |
| 621 std::string, whitelisted_extension_id, |
| 622 (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 623 switches::kWhitelistedExtensionID))); |
| 624 return !whitelisted_extension_id.empty() && |
| 625 whitelisted_extension_id == extension_id; |
| 626 } |
| 627 |
| 625 } // namespace extensions | 628 } // namespace extensions |
| OLD | NEW |