| 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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const std::string& extension_id, | 38 const std::string& extension_id, |
| 39 Manifest::Type type, | 39 Manifest::Type type, |
| 40 Manifest::Location location, | 40 Manifest::Location location, |
| 41 int manifest_version, | 41 int manifest_version, |
| 42 Feature::Platform platform, | 42 Feature::Platform platform, |
| 43 const Feature* feature) { | 43 const Feature* feature) { |
| 44 return feature->IsAvailableToManifest( | 44 return feature->IsAvailableToManifest( |
| 45 extension_id, type, location, manifest_version, platform); | 45 extension_id, type, location, manifest_version, platform); |
| 46 } | 46 } |
| 47 | 47 |
| 48 Feature::Availability IsAvailableToContextForBind(const Extension* extension, | 48 Feature::Availability IsAvailableToContextForBind( |
| 49 Feature::Context context, | 49 const Extension* extension, |
| 50 const GURL& url, | 50 Feature::Context context, |
| 51 Feature::Platform platform, | 51 Feature::SessionType session_type, |
| 52 const Feature* feature) { | 52 const GURL& url, |
| 53 return feature->IsAvailableToContext(extension, context, url, platform); | 53 Feature::Platform platform, |
| 54 const Feature* feature) { |
| 55 return feature->IsAvailableToContext(extension, context, session_type, url, |
| 56 platform); |
| 54 } | 57 } |
| 55 | 58 |
| 56 // TODO(aa): Can we replace all this manual parsing with JSON schema stuff? | 59 // TODO(aa): Can we replace all this manual parsing with JSON schema stuff? |
| 57 | 60 |
| 58 void ParseVector(const base::Value* value, | 61 void ParseVector(const base::Value* value, |
| 59 std::vector<std::string>* vector) { | 62 std::vector<std::string>* vector) { |
| 60 const base::ListValue* list_value = NULL; | 63 const base::ListValue* list_value = NULL; |
| 61 if (!value->GetAsList(&list_value)) | 64 if (!value->GetAsList(&list_value)) |
| 62 return; | 65 return; |
| 63 | 66 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return CheckDependencies(base::Bind(&IsAvailableToManifestForBind, | 444 return CheckDependencies(base::Bind(&IsAvailableToManifestForBind, |
| 442 extension_id, | 445 extension_id, |
| 443 type, | 446 type, |
| 444 location, | 447 location, |
| 445 manifest_version, | 448 manifest_version, |
| 446 platform)); | 449 platform)); |
| 447 } | 450 } |
| 448 | 451 |
| 449 Feature::Availability SimpleFeature::IsAvailableToContext( | 452 Feature::Availability SimpleFeature::IsAvailableToContext( |
| 450 const Extension* extension, | 453 const Extension* extension, |
| 451 SimpleFeature::Context context, | 454 Feature::Context context, |
| 455 Feature::SessionType session_type, |
| 452 const GURL& url, | 456 const GURL& url, |
| 453 SimpleFeature::Platform platform) const { | 457 SimpleFeature::Platform platform) const { |
| 454 if (extension) { | 458 if (extension) { |
| 455 Availability result = IsAvailableToManifest(extension->id(), | 459 Availability result = IsAvailableToManifest(extension->id(), |
| 456 extension->GetType(), | 460 extension->GetType(), |
| 457 extension->location(), | 461 extension->location(), |
| 458 extension->manifest_version(), | 462 extension->manifest_version(), |
| 459 platform); | 463 platform); |
| 460 if (!result.is_available()) | 464 if (!result.is_available()) |
| 461 return result; | 465 return result; |
| 462 } | 466 } |
| 463 | 467 |
| 464 // TODO(lazyboy): This isn't quite right for Extension Service Worker | 468 // TODO(lazyboy): This isn't quite right for Extension Service Worker |
| 465 // extension API calls, since there's no guarantee that the extension is | 469 // extension API calls, since there's no guarantee that the extension is |
| 466 // "active" in current renderer process when the API permission check is | 470 // "active" in current renderer process when the API permission check is |
| 467 // done. | 471 // done. |
| 468 if (!contexts_.empty() && !base::ContainsValue(contexts_, context)) | 472 if (!contexts_.empty() && !base::ContainsValue(contexts_, context)) |
| 469 return CreateAvailability(INVALID_CONTEXT, context); | 473 return CreateAvailability(INVALID_CONTEXT, context); |
| 470 | 474 |
| 471 // TODO(kalman): Consider checking |matches_| regardless of context type. | 475 // TODO(kalman): Consider checking |matches_| regardless of context type. |
| 472 // Fewer surprises, and if the feature configuration wants to isolate | 476 // Fewer surprises, and if the feature configuration wants to isolate |
| 473 // "matches" from say "blessed_extension" then they can use complex features. | 477 // "matches" from say "blessed_extension" then they can use complex features. |
| 474 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) && | 478 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) && |
| 475 !matches_.MatchesURL(url)) { | 479 !matches_.MatchesURL(url)) { |
| 476 return CreateAvailability(INVALID_URL, url); | 480 return CreateAvailability(INVALID_URL, url); |
| 477 } | 481 } |
| 478 | 482 |
| 479 // TODO(kalman): Assert that if the context was a webpage or WebUI context | 483 // TODO(kalman): Assert that if the context was a webpage or WebUI context |
| 480 // then at some point a "matches" restriction was checked. | 484 // then at some point a "matches" restriction was checked. |
| 481 return CheckDependencies(base::Bind( | 485 return CheckDependencies(base::Bind(&IsAvailableToContextForBind, extension, |
| 482 &IsAvailableToContextForBind, extension, context, url, platform)); | 486 context, session_type, url, platform)); |
| 483 } | 487 } |
| 484 | 488 |
| 485 std::string SimpleFeature::GetAvailabilityMessage( | 489 std::string SimpleFeature::GetAvailabilityMessage( |
| 486 AvailabilityResult result, | 490 AvailabilityResult result, |
| 487 Manifest::Type type, | 491 Manifest::Type type, |
| 488 const GURL& url, | 492 const GURL& url, |
| 489 Context context, | 493 Context context, |
| 490 version_info::Channel channel) const { | 494 version_info::Channel channel) const { |
| 491 switch (result) { | 495 switch (result) { |
| 492 case IS_AVAILABLE: | 496 case IS_AVAILABLE: |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 void SimpleFeature::set_platforms(std::initializer_list<Platform> platforms) { | 705 void SimpleFeature::set_platforms(std::initializer_list<Platform> platforms) { |
| 702 platforms_ = platforms; | 706 platforms_ = platforms; |
| 703 } | 707 } |
| 704 | 708 |
| 705 void SimpleFeature::set_whitelist( | 709 void SimpleFeature::set_whitelist( |
| 706 std::initializer_list<const char* const> whitelist) { | 710 std::initializer_list<const char* const> whitelist) { |
| 707 whitelist_.assign(whitelist.begin(), whitelist.end()); | 711 whitelist_.assign(whitelist.begin(), whitelist.end()); |
| 708 } | 712 } |
| 709 | 713 |
| 710 } // namespace extensions | 714 } // namespace extensions |
| OLD | NEW |