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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 value->GetInteger("min_manifest_version", &min_manifest_version_); | 280 value->GetInteger("min_manifest_version", &min_manifest_version_); |
281 value->GetInteger("max_manifest_version", &max_manifest_version_); | 281 value->GetInteger("max_manifest_version", &max_manifest_version_); |
282 | 282 |
283 no_parent_ = false; | 283 no_parent_ = false; |
284 value->GetBoolean("noparent", &no_parent_); | 284 value->GetBoolean("noparent", &no_parent_); |
285 | 285 |
286 component_extensions_auto_granted_ = true; | 286 component_extensions_auto_granted_ = true; |
287 value->GetBoolean("component_extensions_auto_granted", | 287 value->GetBoolean("component_extensions_auto_granted", |
288 &component_extensions_auto_granted_); | 288 &component_extensions_auto_granted_); |
289 | 289 |
290 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { | 290 // NOTE: ideally we'd sanity check that "matches" can be specified if and |
291 return name() + ": Allowing web_page contexts requires supplying a value " + | 291 // only if there's a "web_page" context, but without (Simple)Features being |
292 "for matches."; | 292 // aware of their own heirarchy this is impossible. |
293 } | 293 // |
| 294 // For example, we might have feature "foo" available to "web_page" context |
| 295 // and "matches" google.com/*. Then a sub-feature "foo.bar" might override |
| 296 // "matches" to be chromium.org/*. That sub-feature doesn't need to specify |
| 297 // "web_page" context because it's inherited, but we don't know that here. |
294 | 298 |
295 for (FilterList::iterator filter_iter = filters_.begin(); | 299 for (FilterList::iterator filter_iter = filters_.begin(); |
296 filter_iter != filters_.end(); | 300 filter_iter != filters_.end(); |
297 ++filter_iter) { | 301 ++filter_iter) { |
298 std::string result = (*filter_iter)->Parse(value); | 302 std::string result = (*filter_iter)->Parse(value); |
299 if (!result.empty()) { | 303 if (!result.empty()) { |
300 return result; | 304 return result; |
301 } | 305 } |
302 } | 306 } |
303 | 307 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 extension->location(), | 392 extension->location(), |
389 extension->manifest_version(), | 393 extension->manifest_version(), |
390 platform); | 394 platform); |
391 if (!result.is_available()) | 395 if (!result.is_available()) |
392 return result; | 396 return result; |
393 } | 397 } |
394 | 398 |
395 if (!contexts_.empty() && contexts_.find(context) == contexts_.end()) | 399 if (!contexts_.empty() && contexts_.find(context) == contexts_.end()) |
396 return CreateAvailability(INVALID_CONTEXT, context); | 400 return CreateAvailability(INVALID_CONTEXT, context); |
397 | 401 |
398 if (!matches_.is_empty() && !matches_.MatchesURL(url)) | 402 if (context == WEB_PAGE_CONTEXT && !matches_.MatchesURL(url)) |
399 return CreateAvailability(INVALID_URL, url); | 403 return CreateAvailability(INVALID_URL, url); |
400 | 404 |
401 for (FilterList::const_iterator filter_iter = filters_.begin(); | 405 for (FilterList::const_iterator filter_iter = filters_.begin(); |
402 filter_iter != filters_.end(); | 406 filter_iter != filters_.end(); |
403 ++filter_iter) { | 407 ++filter_iter) { |
404 Availability availability = | 408 Availability availability = |
405 (*filter_iter)->IsAvailableToContext(extension, context, url, platform); | 409 (*filter_iter)->IsAvailableToContext(extension, context, url, platform); |
406 if (!availability.is_available()) | 410 if (!availability.is_available()) |
407 return availability; | 411 return availability; |
408 } | 412 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 499 } |
496 | 500 |
497 Feature::Availability SimpleFeature::CreateAvailability( | 501 Feature::Availability SimpleFeature::CreateAvailability( |
498 AvailabilityResult result, | 502 AvailabilityResult result, |
499 Context context) const { | 503 Context context) const { |
500 return Availability( | 504 return Availability( |
501 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), | 505 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), |
502 context)); | 506 context)); |
503 } | 507 } |
504 | 508 |
505 std::set<Feature::Context>* SimpleFeature::GetContexts() { | |
506 return &contexts_; | |
507 } | |
508 | |
509 bool SimpleFeature::IsInternal() const { | 509 bool SimpleFeature::IsInternal() const { |
510 return false; | 510 return false; |
511 } | 511 } |
512 | 512 |
513 bool SimpleFeature::IsBlockedInServiceWorker() const { return false; } | 513 bool SimpleFeature::IsBlockedInServiceWorker() const { return false; } |
514 | 514 |
515 bool SimpleFeature::IsIdInBlacklist(const std::string& extension_id) const { | 515 bool SimpleFeature::IsIdInBlacklist(const std::string& extension_id) const { |
516 return IsIdInList(extension_id, blacklist_); | 516 return IsIdInList(extension_id, blacklist_); |
517 } | 517 } |
518 | 518 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 if (!dependency) | 564 if (!dependency) |
565 return CreateAvailability(NOT_PRESENT); | 565 return CreateAvailability(NOT_PRESENT); |
566 Availability dependency_availability = checker.Run(dependency); | 566 Availability dependency_availability = checker.Run(dependency); |
567 if (!dependency_availability.is_available()) | 567 if (!dependency_availability.is_available()) |
568 return dependency_availability; | 568 return dependency_availability; |
569 } | 569 } |
570 return CreateAvailability(IS_AVAILABLE); | 570 return CreateAvailability(IS_AVAILABLE); |
571 } | 571 } |
572 | 572 |
573 } // namespace extensions | 573 } // namespace extensions |
OLD | NEW |