| 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 <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 241 } |
| 242 return display_name_list; | 242 return display_name_list; |
| 243 } | 243 } |
| 244 | 244 |
| 245 std::string HashExtensionId(const std::string& extension_id) { | 245 std::string HashExtensionId(const std::string& extension_id) { |
| 246 const std::string id_hash = base::SHA1HashString(extension_id); | 246 const std::string id_hash = base::SHA1HashString(extension_id); |
| 247 DCHECK(id_hash.length() == base::kSHA1Length); | 247 DCHECK(id_hash.length() == base::kSHA1Length); |
| 248 return base::HexEncode(id_hash.c_str(), id_hash.length()); | 248 return base::HexEncode(id_hash.c_str(), id_hash.length()); |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool IsCommandLineSwitchEnabled(const std::string& switch_name) { |
| 252 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 253 if (command_line->HasSwitch(switch_name + "=1")) |
| 254 return true; |
| 255 if (command_line->HasSwitch(std::string("enable-") + switch_name)) |
| 256 return true; |
| 257 return false; |
| 258 } |
| 259 |
| 251 } // namespace | 260 } // namespace |
| 252 | 261 |
| 253 SimpleFeature::SimpleFeature() | 262 SimpleFeature::SimpleFeature() |
| 254 : location_(UNSPECIFIED_LOCATION), | 263 : location_(UNSPECIFIED_LOCATION), |
| 255 min_manifest_version_(0), | 264 min_manifest_version_(0), |
| 256 max_manifest_version_(0), | 265 max_manifest_version_(0), |
| 257 has_parent_(false), | |
| 258 component_extensions_auto_granted_(true) {} | 266 component_extensions_auto_granted_(true) {} |
| 259 | 267 |
| 260 SimpleFeature::~SimpleFeature() {} | 268 SimpleFeature::~SimpleFeature() {} |
| 261 | 269 |
| 262 bool SimpleFeature::HasDependencies() { | 270 bool SimpleFeature::HasDependencies() { |
| 263 return !dependencies_.empty(); | 271 return !dependencies_.empty(); |
| 264 } | 272 } |
| 265 | 273 |
| 266 void SimpleFeature::AddFilter(scoped_ptr<SimpleFeatureFilter> filter) { | 274 void SimpleFeature::AddFilter(scoped_ptr<SimpleFeatureFilter> filter) { |
| 267 filters_.push_back(make_linked_ptr(filter.release())); | 275 filters_.push_back(make_linked_ptr(filter.release())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 279 ParseEnum<Location>(value, "location", &location_, | 287 ParseEnum<Location>(value, "location", &location_, |
| 280 g_mappings.Get().locations); | 288 g_mappings.Get().locations); |
| 281 ParseEnumSet<Platform>(value, "platforms", &platforms_, | 289 ParseEnumSet<Platform>(value, "platforms", &platforms_, |
| 282 g_mappings.Get().platforms); | 290 g_mappings.Get().platforms); |
| 283 value->GetInteger("min_manifest_version", &min_manifest_version_); | 291 value->GetInteger("min_manifest_version", &min_manifest_version_); |
| 284 value->GetInteger("max_manifest_version", &max_manifest_version_); | 292 value->GetInteger("max_manifest_version", &max_manifest_version_); |
| 285 | 293 |
| 286 no_parent_ = false; | 294 no_parent_ = false; |
| 287 value->GetBoolean("noparent", &no_parent_); | 295 value->GetBoolean("noparent", &no_parent_); |
| 288 | 296 |
| 289 component_extensions_auto_granted_ = true; | |
| 290 value->GetBoolean("component_extensions_auto_granted", | 297 value->GetBoolean("component_extensions_auto_granted", |
| 291 &component_extensions_auto_granted_); | 298 &component_extensions_auto_granted_); |
| 292 | 299 |
| 300 value->GetString("command_line_switch", &command_line_switch_); |
| 301 |
| 293 // NOTE: ideally we'd sanity check that "matches" can be specified if and | 302 // NOTE: ideally we'd sanity check that "matches" can be specified if and |
| 294 // only if there's a "web_page" or "webui" context, but without | 303 // only if there's a "web_page" or "webui" context, but without |
| 295 // (Simple)Features being aware of their own heirarchy this is impossible. | 304 // (Simple)Features being aware of their own heirarchy this is impossible. |
| 296 // | 305 // |
| 297 // For example, we might have feature "foo" available to "web_page" context | 306 // For example, we might have feature "foo" available to "web_page" context |
| 298 // and "matches" google.com/*. Then a sub-feature "foo.bar" might override | 307 // and "matches" google.com/*. Then a sub-feature "foo.bar" might override |
| 299 // "matches" to be chromium.org/*. That sub-feature doesn't need to specify | 308 // "matches" to be chromium.org/*. That sub-feature doesn't need to specify |
| 300 // "web_page" context because it's inherited, but we don't know that here. | 309 // "web_page" context because it's inherited, but we don't know that here. |
| 301 | 310 |
| 302 for (FilterList::iterator filter_iter = filters_.begin(); | 311 for (FilterList::iterator filter_iter = filters_.begin(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (!platforms_.empty() && | 369 if (!platforms_.empty() && |
| 361 platforms_.find(platform) == platforms_.end()) | 370 platforms_.find(platform) == platforms_.end()) |
| 362 return CreateAvailability(INVALID_PLATFORM, type); | 371 return CreateAvailability(INVALID_PLATFORM, type); |
| 363 | 372 |
| 364 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) | 373 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) |
| 365 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); | 374 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); |
| 366 | 375 |
| 367 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) | 376 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) |
| 368 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); | 377 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); |
| 369 | 378 |
| 379 if (!command_line_switch_.empty() && |
| 380 !IsCommandLineSwitchEnabled(command_line_switch_)) { |
| 381 return CreateAvailability(MISSING_COMMAND_LINE_SWITCH, type); |
| 382 } |
| 383 |
| 370 for (FilterList::const_iterator filter_iter = filters_.begin(); | 384 for (FilterList::const_iterator filter_iter = filters_.begin(); |
| 371 filter_iter != filters_.end(); | 385 filter_iter != filters_.end(); |
| 372 ++filter_iter) { | 386 ++filter_iter) { |
| 373 Availability availability = (*filter_iter)->IsAvailableToManifest( | 387 Availability availability = (*filter_iter)->IsAvailableToManifest( |
| 374 extension_id, type, location, manifest_version, platform); | 388 extension_id, type, location, manifest_version, platform); |
| 375 if (!availability.is_available()) | 389 if (!availability.is_available()) |
| 376 return availability; | 390 return availability; |
| 377 } | 391 } |
| 378 | 392 |
| 379 return CheckDependencies(base::Bind(&IsAvailableToManifestForBind, | 393 return CheckDependencies(base::Bind(&IsAvailableToManifestForBind, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 name().c_str(), | 488 name().c_str(), |
| 475 max_manifest_version_); | 489 max_manifest_version_); |
| 476 case NOT_PRESENT: | 490 case NOT_PRESENT: |
| 477 return base::StringPrintf( | 491 return base::StringPrintf( |
| 478 "'%s' requires a different Feature that is not present.", | 492 "'%s' requires a different Feature that is not present.", |
| 479 name().c_str()); | 493 name().c_str()); |
| 480 case UNSUPPORTED_CHANNEL: | 494 case UNSUPPORTED_CHANNEL: |
| 481 return base::StringPrintf( | 495 return base::StringPrintf( |
| 482 "'%s' is unsupported in this version of the platform.", | 496 "'%s' is unsupported in this version of the platform.", |
| 483 name().c_str()); | 497 name().c_str()); |
| 498 case MISSING_COMMAND_LINE_SWITCH: |
| 499 return base::StringPrintf( |
| 500 "'%s' requires the '%s' command line switch to be enabled.", |
| 501 name().c_str(), command_line_switch_.c_str()); |
| 484 } | 502 } |
| 485 | 503 |
| 486 NOTREACHED(); | 504 NOTREACHED(); |
| 487 return std::string(); | 505 return std::string(); |
| 488 } | 506 } |
| 489 | 507 |
| 490 Feature::Availability SimpleFeature::CreateAvailability( | 508 Feature::Availability SimpleFeature::CreateAvailability( |
| 491 AvailabilityResult result) const { | 509 AvailabilityResult result) const { |
| 492 return Availability( | 510 return Availability( |
| 493 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), | 511 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if (!dependency) | 590 if (!dependency) |
| 573 return CreateAvailability(NOT_PRESENT); | 591 return CreateAvailability(NOT_PRESENT); |
| 574 Availability dependency_availability = checker.Run(dependency); | 592 Availability dependency_availability = checker.Run(dependency); |
| 575 if (!dependency_availability.is_available()) | 593 if (!dependency_availability.is_available()) |
| 576 return dependency_availability; | 594 return dependency_availability; |
| 577 } | 595 } |
| 578 return CreateAvailability(IS_AVAILABLE); | 596 return CreateAvailability(IS_AVAILABLE); |
| 579 } | 597 } |
| 580 | 598 |
| 581 } // namespace extensions | 599 } // namespace extensions |
| OLD | NEW |