| Index: extensions/common/features/simple_feature.cc
|
| diff --git a/extensions/common/features/simple_feature.cc b/extensions/common/features/simple_feature.cc
|
| index c7c66f4848004bbc023685a8d160606a59568811..3cbe1c159f3bc4ab4c05820b24c7425ab278c380 100644
|
| --- a/extensions/common/features/simple_feature.cc
|
| +++ b/extensions/common/features/simple_feature.cc
|
| @@ -210,6 +210,19 @@ std::string GetDisplayName(version_info::Channel channel) {
|
| return "";
|
| }
|
|
|
| +std::string GetSessionTypeDisplayName(Feature::SessionType session_type) {
|
| + switch (session_type) {
|
| + case Feature::SESSION_TYPE_UNSPECIFIED:
|
| + return "unspecified";
|
| + case Feature::SESSION_TYPE_KIOSK:
|
| + return "kiosk app";
|
| + case Feature::SESSION_TYPE_REGULAR:
|
| + return "regular user";
|
| + default:
|
| + return "";
|
| + }
|
| +}
|
| +
|
| // Gets a human-readable list of the display names (pluralized, comma separated
|
| // with the "and" in the correct place) for each of |enum_types|.
|
| template <typename EnumType>
|
| @@ -300,6 +313,9 @@ struct SimpleFeature::Mappings {
|
| channels["dev"] = version_info::Channel::DEV;
|
| channels["beta"] = version_info::Channel::BETA;
|
| channels["stable"] = version_info::Channel::STABLE;
|
| +
|
| + session_types["regular"] = Feature::SESSION_TYPE_REGULAR;
|
| + session_types["kiosk"] = Feature::SESSION_TYPE_KIOSK;
|
| }
|
|
|
| std::map<std::string, Manifest::Type> extension_types;
|
| @@ -307,6 +323,7 @@ struct SimpleFeature::Mappings {
|
| std::map<std::string, SimpleFeature::Location> locations;
|
| std::map<std::string, Feature::Platform> platforms;
|
| std::map<std::string, version_info::Channel> channels;
|
| + std::map<std::string, Feature::SessionType> session_types;
|
| };
|
|
|
| SimpleFeature::SimpleFeature()
|
| @@ -342,6 +359,9 @@ void SimpleFeature::Parse(const base::DictionaryValue* dictionary) {
|
| } else if (key == "contexts") {
|
| ParseEnumVector<Context>(value, &contexts_,
|
| mappings.Get().contexts);
|
| + } else if (key == "session_types") {
|
| + ParseEnumVector<SessionType>(value, &session_types_,
|
| + mappings.Get().session_types);
|
| } else if (key == "location") {
|
| ParseEnum<Location>(value, &location_, mappings.Get().locations);
|
| } else if (key == "platforms") {
|
| @@ -480,6 +500,11 @@ Feature::Availability SimpleFeature::IsAvailableToContext(
|
| return CreateAvailability(INVALID_URL, url);
|
| }
|
|
|
| + if (!session_types_.empty() &&
|
| + !base::ContainsValue(session_types_, session_type)) {
|
| + return CreateAvailability(INVALID_SESSION_TYPE, session_type);
|
| + }
|
| +
|
| // TODO(kalman): Assert that if the context was a webpage or WebUI context
|
| // then at some point a "matches" restriction was checked.
|
| return CheckDependencies(base::Bind(&IsAvailableToContextForBind, extension,
|
| @@ -491,7 +516,8 @@ std::string SimpleFeature::GetAvailabilityMessage(
|
| Manifest::Type type,
|
| const GURL& url,
|
| Context context,
|
| - version_info::Channel channel) const {
|
| + version_info::Channel channel,
|
| + SessionType session_type) const {
|
| switch (result) {
|
| case IS_AVAILABLE:
|
| return std::string();
|
| @@ -535,6 +561,10 @@ std::string SimpleFeature::GetAvailabilityMessage(
|
| "'%s' requires manifest version of %d or lower.",
|
| name().c_str(),
|
| max_manifest_version_);
|
| + case INVALID_SESSION_TYPE:
|
| + return base::StringPrintf(
|
| + "'%s' is not allowed in %s session", name().c_str(),
|
| + GetSessionTypeDisplayName(session_type).c_str());
|
| case NOT_PRESENT:
|
| return base::StringPrintf(
|
| "'%s' requires a different Feature that is not present.",
|
| @@ -557,25 +587,26 @@ std::string SimpleFeature::GetAvailabilityMessage(
|
| Feature::Availability SimpleFeature::CreateAvailability(
|
| AvailabilityResult result) const {
|
| return Availability(
|
| - result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(),
|
| - UNSPECIFIED_CONTEXT,
|
| - version_info::Channel::UNKNOWN));
|
| + result, GetAvailabilityMessage(
|
| + result, Manifest::TYPE_UNKNOWN, GURL(), UNSPECIFIED_CONTEXT,
|
| + version_info::Channel::UNKNOWN, SESSION_TYPE_UNSPECIFIED));
|
| }
|
|
|
| Feature::Availability SimpleFeature::CreateAvailability(
|
| AvailabilityResult result, Manifest::Type type) const {
|
| return Availability(
|
| result, GetAvailabilityMessage(result, type, GURL(), UNSPECIFIED_CONTEXT,
|
| - version_info::Channel::UNKNOWN));
|
| + version_info::Channel::UNKNOWN,
|
| + SESSION_TYPE_UNSPECIFIED));
|
| }
|
|
|
| Feature::Availability SimpleFeature::CreateAvailability(
|
| AvailabilityResult result,
|
| const GURL& url) const {
|
| return Availability(
|
| - result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, url,
|
| - UNSPECIFIED_CONTEXT,
|
| - version_info::Channel::UNKNOWN));
|
| + result, GetAvailabilityMessage(
|
| + result, Manifest::TYPE_UNKNOWN, url, UNSPECIFIED_CONTEXT,
|
| + version_info::Channel::UNKNOWN, SESSION_TYPE_UNSPECIFIED));
|
| }
|
|
|
| Feature::Availability SimpleFeature::CreateAvailability(
|
| @@ -583,7 +614,8 @@ Feature::Availability SimpleFeature::CreateAvailability(
|
| Context context) const {
|
| return Availability(
|
| result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(),
|
| - context, version_info::Channel::UNKNOWN));
|
| + context, version_info::Channel::UNKNOWN,
|
| + SESSION_TYPE_UNSPECIFIED));
|
| }
|
|
|
| Feature::Availability SimpleFeature::CreateAvailability(
|
| @@ -591,7 +623,17 @@ Feature::Availability SimpleFeature::CreateAvailability(
|
| version_info::Channel channel) const {
|
| return Availability(
|
| result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(),
|
| - UNSPECIFIED_CONTEXT, channel));
|
| + UNSPECIFIED_CONTEXT, channel,
|
| + SESSION_TYPE_UNSPECIFIED));
|
| +}
|
| +
|
| +Feature::Availability SimpleFeature::CreateAvailability(
|
| + AvailabilityResult result,
|
| + SessionType session_type) const {
|
| + return Availability(
|
| + result, GetAvailabilityMessage(
|
| + result, Manifest::TYPE_UNKNOWN, GURL(), UNSPECIFIED_CONTEXT,
|
| + version_info::Channel::UNKNOWN, session_type));
|
| }
|
|
|
| bool SimpleFeature::IsInternal() const {
|
| @@ -695,6 +737,11 @@ void SimpleFeature::set_extension_types(
|
| extension_types_ = types;
|
| }
|
|
|
| +void SimpleFeature::set_session_types(
|
| + std::initializer_list<SessionType> types) {
|
| + session_types_ = types;
|
| +}
|
| +
|
| void SimpleFeature::set_matches(
|
| std::initializer_list<const char* const> matches) {
|
| matches_.ClearPatterns();
|
|
|