Chromium Code Reviews| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 216 |
| 216 bool IsCommandLineSwitchEnabled(const std::string& switch_name) { | 217 bool IsCommandLineSwitchEnabled(const std::string& switch_name) { |
| 217 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 218 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 218 if (command_line->HasSwitch(switch_name + "=1")) | 219 if (command_line->HasSwitch(switch_name + "=1")) |
| 219 return true; | 220 return true; |
| 220 if (command_line->HasSwitch(std::string("enable-") + switch_name)) | 221 if (command_line->HasSwitch(std::string("enable-") + switch_name)) |
| 221 return true; | 222 return true; |
| 222 return false; | 223 return false; |
| 223 } | 224 } |
| 224 | 225 |
| 226 bool IsWhitelistedByCommandLine(const std::string& extension_id) { | |
| 227 // A singleton copy of the --whitelisted-extension-id so that we don't need to | |
| 228 // copy it from the CommandLine each time. | |
| 229 CR_DEFINE_STATIC_LOCAL( | |
| 230 std::string, whitelisted_extension_id, | |
| 231 (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
|
not at google - send to devlin
2015/03/31 17:16:05
why are the parens around the base::CommandLine...
jackhou1
2015/03/31 21:53:41
The macro is just:
#define CR_DEFINE_STATIC_LOCAL(
not at google - send to devlin
2015/03/31 22:10:04
Well, that's silly. Macros are supposed to put par
jackhou1
2015/03/31 22:19:18
Yeah probably, looks like it was originally copied
| |
| 232 switches::kWhitelistedExtensionID))); | |
| 233 return !whitelisted_extension_id.empty() && | |
| 234 whitelisted_extension_id == extension_id; | |
| 235 } | |
| 236 | |
| 225 } // namespace | 237 } // namespace |
| 226 | 238 |
| 227 struct SimpleFeature::Mappings { | 239 struct SimpleFeature::Mappings { |
| 228 Mappings() { | 240 Mappings() { |
| 229 extension_types["extension"] = Manifest::TYPE_EXTENSION; | 241 extension_types["extension"] = Manifest::TYPE_EXTENSION; |
| 230 extension_types["theme"] = Manifest::TYPE_THEME; | 242 extension_types["theme"] = Manifest::TYPE_THEME; |
| 231 extension_types["legacy_packaged_app"] = Manifest::TYPE_LEGACY_PACKAGED_APP; | 243 extension_types["legacy_packaged_app"] = Manifest::TYPE_LEGACY_PACKAGED_APP; |
| 232 extension_types["hosted_app"] = Manifest::TYPE_HOSTED_APP; | 244 extension_types["hosted_app"] = Manifest::TYPE_HOSTED_APP; |
| 233 extension_types["platform_app"] = Manifest::TYPE_PLATFORM_APP; | 245 extension_types["platform_app"] = Manifest::TYPE_PLATFORM_APP; |
| 234 extension_types["shared_module"] = Manifest::TYPE_SHARED_MODULE; | 246 extension_types["shared_module"] = Manifest::TYPE_SHARED_MODULE; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 if (IsIdInBlacklist(extension_id)) | 368 if (IsIdInBlacklist(extension_id)) |
| 357 return CreateAvailability(FOUND_IN_BLACKLIST, type); | 369 return CreateAvailability(FOUND_IN_BLACKLIST, type); |
| 358 | 370 |
| 359 // TODO(benwells): don't grant all component extensions. | 371 // TODO(benwells): don't grant all component extensions. |
| 360 // See http://crbug.com/370375 for more details. | 372 // See http://crbug.com/370375 for more details. |
| 361 // Component extensions can access any feature. | 373 // Component extensions can access any feature. |
| 362 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. | 374 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. |
| 363 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) | 375 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) |
| 364 return CreateAvailability(IS_AVAILABLE, type); | 376 return CreateAvailability(IS_AVAILABLE, type); |
| 365 | 377 |
| 366 if (!whitelist_.empty()) { | 378 if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) && |
| 367 if (!IsIdInWhitelist(extension_id)) { | 379 !IsWhitelistedByCommandLine(extension_id)) { |
| 368 // TODO(aa): This is gross. There should be a better way to test the | 380 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 } | 381 } |
| 381 | 382 |
| 382 if (!MatchesManifestLocation(location)) | 383 if (!MatchesManifestLocation(location)) |
| 383 return CreateAvailability(INVALID_LOCATION, type); | 384 return CreateAvailability(INVALID_LOCATION, type); |
| 384 | 385 |
| 385 if (!platforms_.empty() && !ContainsValue(platforms_, platform)) | 386 if (!platforms_.empty() && !ContainsValue(platforms_, platform)) |
| 386 return CreateAvailability(INVALID_PLATFORM, type); | 387 return CreateAvailability(INVALID_PLATFORM, type); |
| 387 | 388 |
| 388 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) | 389 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) |
| 389 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); | 390 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { | 617 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { |
| 617 // Belt-and-suspenders philosophy here. We should be pretty confident by this | 618 // 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 | 619 // 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 | 620 // slips through, we avoid a class of attack where creative ID manipulation |
| 620 // leads to hash collisions. | 621 // leads to hash collisions. |
| 621 // 128 bits / 4 = 32 mpdecimal characters | 622 // 128 bits / 4 = 32 mpdecimal characters |
| 622 return (extension_id.length() == 32); | 623 return (extension_id.length() == 32); |
| 623 } | 624 } |
| 624 | 625 |
| 625 } // namespace extensions | 626 } // namespace extensions |
| OLD | NEW |