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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 } | 127 } |
| 128 | 128 |
| 129 std::string GetDisplayName(FeatureSessionType session_type) { | 129 std::string GetDisplayName(FeatureSessionType session_type) { |
| 130 switch (session_type) { | 130 switch (session_type) { |
| 131 case FeatureSessionType::INITIAL: | 131 case FeatureSessionType::INITIAL: |
| 132 return "user-less"; | 132 return "user-less"; |
| 133 case FeatureSessionType::UNKNOWN: | 133 case FeatureSessionType::UNKNOWN: |
| 134 return "unknown"; | 134 return "unknown"; |
| 135 case FeatureSessionType::KIOSK: | 135 case FeatureSessionType::KIOSK: |
| 136 return "kiosk app"; | 136 return "kiosk app"; |
| 137 case FeatureSessionType::AUTOLAUNCHED_KIOSK: | |
| 138 return "auto-launched kiosk app"; | |
| 137 case FeatureSessionType::REGULAR: | 139 case FeatureSessionType::REGULAR: |
| 138 return "regular user"; | 140 return "regular user"; |
| 139 } | 141 } |
| 140 return ""; | 142 return ""; |
| 141 } | 143 } |
| 142 | 144 |
| 143 // Gets a human-readable list of the display names (pluralized, comma separated | 145 // Gets a human-readable list of the display names (pluralized, comma separated |
| 144 // with the "and" in the correct place) for each of |enum_types|. | 146 // with the "and" in the correct place) for each of |enum_types|. |
| 145 template <typename EnumType> | 147 template <typename EnumType> |
| 146 std::string ListDisplayNames(const std::vector<EnumType>& enum_types) { | 148 std::string ListDisplayNames(const std::vector<EnumType>& enum_types) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); | 254 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); |
| 253 | 255 |
| 254 if (!command_line_switch_.empty() && | 256 if (!command_line_switch_.empty() && |
| 255 !IsCommandLineSwitchEnabled(command_line_switch_)) { | 257 !IsCommandLineSwitchEnabled(command_line_switch_)) { |
| 256 return CreateAvailability(MISSING_COMMAND_LINE_SWITCH, type); | 258 return CreateAvailability(MISSING_COMMAND_LINE_SWITCH, type); |
| 257 } | 259 } |
| 258 | 260 |
| 259 if (channel_ && *channel_ < GetCurrentChannel()) | 261 if (channel_ && *channel_ < GetCurrentChannel()) |
| 260 return CreateAvailability(UNSUPPORTED_CHANNEL, *channel_); | 262 return CreateAvailability(UNSUPPORTED_CHANNEL, *channel_); |
| 261 | 263 |
| 262 FeatureSessionType session = GetCurrentFeatureSessionType(); | 264 FeatureSessionType session_type = GetCurrentFeatureSessionType(); |
| 263 if (!session_types_.empty() && | 265 if (!MatchesSessionTypes(session_type)) |
| 264 !base::ContainsValue(session_types_, session)) { | 266 return CreateAvailability(INVALID_SESSION_TYPE, session_type); |
| 265 return CreateAvailability(INVALID_SESSION_TYPE, session); | |
| 266 } | |
| 267 | 267 |
| 268 return CheckDependencies(base::Bind(&IsAvailableToManifestForBind, | 268 return CheckDependencies(base::Bind(&IsAvailableToManifestForBind, |
| 269 extension_id, | 269 extension_id, |
| 270 type, | 270 type, |
| 271 location, | 271 location, |
| 272 manifest_version, | 272 manifest_version, |
| 273 platform)); | 273 platform)); |
| 274 } | 274 } |
| 275 | 275 |
| 276 Feature::Availability SimpleFeature::IsAvailableToContext( | 276 Feature::Availability SimpleFeature::IsAvailableToContext( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 296 return CreateAvailability(INVALID_CONTEXT, context); | 296 return CreateAvailability(INVALID_CONTEXT, context); |
| 297 | 297 |
| 298 // TODO(kalman): Consider checking |matches_| regardless of context type. | 298 // TODO(kalman): Consider checking |matches_| regardless of context type. |
| 299 // Fewer surprises, and if the feature configuration wants to isolate | 299 // Fewer surprises, and if the feature configuration wants to isolate |
| 300 // "matches" from say "blessed_extension" then they can use complex features. | 300 // "matches" from say "blessed_extension" then they can use complex features. |
| 301 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) && | 301 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) && |
| 302 !matches_.MatchesURL(url)) { | 302 !matches_.MatchesURL(url)) { |
| 303 return CreateAvailability(INVALID_URL, url); | 303 return CreateAvailability(INVALID_URL, url); |
| 304 } | 304 } |
| 305 | 305 |
| 306 FeatureSessionType session = GetCurrentFeatureSessionType(); | 306 FeatureSessionType session_type = GetCurrentFeatureSessionType(); |
| 307 if (!session_types_.empty() && | 307 if (!MatchesSessionTypes(session_type)) { |
| 308 !base::ContainsValue(session_types_, session)) { | 308 return CreateAvailability(INVALID_SESSION_TYPE, session_type); |
| 309 return CreateAvailability(INVALID_SESSION_TYPE, session); | |
| 310 } | 309 } |
| 311 | 310 |
| 312 // TODO(kalman): Assert that if the context was a webpage or WebUI context | 311 // TODO(kalman): Assert that if the context was a webpage or WebUI context |
| 313 // then at some point a "matches" restriction was checked. | 312 // then at some point a "matches" restriction was checked. |
| 314 return CheckDependencies(base::Bind(&IsAvailableToContextForBind, extension, | 313 return CheckDependencies(base::Bind(&IsAvailableToContextForBind, extension, |
| 315 context, url, platform)); | 314 context, url, platform)); |
| 316 } | 315 } |
| 317 | 316 |
| 318 std::string SimpleFeature::GetAvailabilityMessage( | 317 std::string SimpleFeature::GetAvailabilityMessage( |
| 319 AvailabilityResult result, | 318 AvailabilityResult result, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 case SimpleFeature::EXTERNAL_COMPONENT_LOCATION: | 489 case SimpleFeature::EXTERNAL_COMPONENT_LOCATION: |
| 491 return manifest_location == Manifest::EXTERNAL_COMPONENT; | 490 return manifest_location == Manifest::EXTERNAL_COMPONENT; |
| 492 case SimpleFeature::POLICY_LOCATION: | 491 case SimpleFeature::POLICY_LOCATION: |
| 493 return manifest_location == Manifest::EXTERNAL_POLICY || | 492 return manifest_location == Manifest::EXTERNAL_POLICY || |
| 494 manifest_location == Manifest::EXTERNAL_POLICY_DOWNLOAD; | 493 manifest_location == Manifest::EXTERNAL_POLICY_DOWNLOAD; |
| 495 } | 494 } |
| 496 NOTREACHED(); | 495 NOTREACHED(); |
| 497 return false; | 496 return false; |
| 498 } | 497 } |
| 499 | 498 |
| 499 bool SimpleFeature::MatchesSessionTypes(FeatureSessionType session_type) const { | |
| 500 if (session_types_.empty()) | |
| 501 return true; | |
| 502 | |
| 503 if (!base::ContainsValue(session_types_, session_type)) { | |
| 504 // AUTOLAUNCHED_KIOSK session type is subset of KIOSK - accept auto-lauched | |
| 505 // kiosk session if kiosk session is allowed. This is only exception to | |
| 506 // rejecting session type that is not present in |session_types_| | |
| 507 return session_type == FeatureSessionType::AUTOLAUNCHED_KIOSK && | |
|
Devlin
2016/12/29 17:15:37
I kind of wonder if this is better done at compile
tbarzic
2016/12/29 20:29:58
Yeah, that would work,too.
I find this approach sl
| |
| 508 base::ContainsValue(session_types_, FeatureSessionType::KIOSK); | |
| 509 } | |
| 510 | |
| 511 return true; | |
| 512 } | |
| 513 | |
| 500 Feature::Availability SimpleFeature::CheckDependencies( | 514 Feature::Availability SimpleFeature::CheckDependencies( |
| 501 const base::Callback<Availability(const Feature*)>& checker) const { | 515 const base::Callback<Availability(const Feature*)>& checker) const { |
| 502 for (const auto& dep_name : dependencies_) { | 516 for (const auto& dep_name : dependencies_) { |
| 503 Feature* dependency = | 517 Feature* dependency = |
| 504 ExtensionAPI::GetSharedInstance()->GetFeatureDependency(dep_name); | 518 ExtensionAPI::GetSharedInstance()->GetFeatureDependency(dep_name); |
| 505 if (!dependency) | 519 if (!dependency) |
| 506 return CreateAvailability(NOT_PRESENT); | 520 return CreateAvailability(NOT_PRESENT); |
| 507 Availability dependency_availability = checker.Run(dependency); | 521 Availability dependency_availability = checker.Run(dependency); |
| 508 if (!dependency_availability.is_available()) | 522 if (!dependency_availability.is_available()) |
| 509 return dependency_availability; | 523 return dependency_availability; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 void SimpleFeature::set_platforms(std::initializer_list<Platform> platforms) { | 574 void SimpleFeature::set_platforms(std::initializer_list<Platform> platforms) { |
| 561 platforms_ = platforms; | 575 platforms_ = platforms; |
| 562 } | 576 } |
| 563 | 577 |
| 564 void SimpleFeature::set_whitelist( | 578 void SimpleFeature::set_whitelist( |
| 565 std::initializer_list<const char* const> whitelist) { | 579 std::initializer_list<const char* const> whitelist) { |
| 566 whitelist_.assign(whitelist.begin(), whitelist.end()); | 580 whitelist_.assign(whitelist.begin(), whitelist.end()); |
| 567 } | 581 } |
| 568 | 582 |
| 569 } // namespace extensions | 583 } // namespace extensions |
| OLD | NEW |