diff options
author | kalman <kalman@chromium.org> | 2014-12-14 19:59:09 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-15 03:59:33 +0000 |
commit | 64210328fe91376da6cf6a21ac16db72efa6118a (patch) | |
tree | 7ff1c62a09228eb7215c2bf66f2229e8a098f638 /extensions/common/features | |
parent | 60e5f1185e04c0bcb43f82b2e224de2ad463abee (diff) | |
download | chromium_src-64210328fe91376da6cf6a21ac16db72efa6118a.zip chromium_src-64210328fe91376da6cf6a21ac16db72efa6118a.tar.gz chromium_src-64210328fe91376da6cf6a21ac16db72efa6118a.tar.bz2 |
Add the basic infrastructure for the Behavior feature type: BehaviorFeature and
_behavior_features.json. Arbitrarily use it to implement the allow-in-incognito
whitelist.
BUG=440194
R=rockot@chromium.org
Review URL: https://codereview.chromium.org/789383002
Cr-Commit-Position: refs/heads/master@{#308311}
Diffstat (limited to 'extensions/common/features')
-rw-r--r-- | extensions/common/features/behavior_feature.cc | 12 | ||||
-rw-r--r-- | extensions/common/features/behavior_feature.h | 27 | ||||
-rw-r--r-- | extensions/common/features/feature_provider.cc | 6 | ||||
-rw-r--r-- | extensions/common/features/feature_provider.h | 1 | ||||
-rw-r--r-- | extensions/common/features/simple_feature.cc | 5 | ||||
-rw-r--r-- | extensions/common/features/simple_feature.h | 4 | ||||
-rw-r--r-- | extensions/common/features/simple_feature_unittest.cc | 11 |
7 files changed, 63 insertions, 3 deletions
diff --git a/extensions/common/features/behavior_feature.cc b/extensions/common/features/behavior_feature.cc new file mode 100644 index 0000000..15b93f0 --- /dev/null +++ b/extensions/common/features/behavior_feature.cc @@ -0,0 +1,12 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/common/features/behavior_feature.h" + +namespace extensions { + +const char* BehaviorFeature::kWhitelistedForIncognito = + "whitelisted_for_incognito"; + +} // namespace extensions diff --git a/extensions/common/features/behavior_feature.h b/extensions/common/features/behavior_feature.h new file mode 100644 index 0000000..c09c69d --- /dev/null +++ b/extensions/common/features/behavior_feature.h @@ -0,0 +1,27 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_COMMON_FEATURES_BEHAVIOR_FEATURE_H_ +#define EXTENSIONS_COMMON_FEATURES_BEHAVIOR_FEATURE_H_ + +#include <string> + +#include "extensions/common/features/simple_feature.h" + +namespace extensions { + +// Implementation of the features in _behavior_features.json. +// +// For now, this is just constants + a vacuous implementation of SimpleFeature, +// for consistency with the other Feature types. One day we may add some +// additional functionality. One day we may also generate the feature names. +class BehaviorFeature : public SimpleFeature { + public: + // Constants corresponding to keys in _behavior_features.json. + static const char* kWhitelistedForIncognito; +}; + +} // namespace extensions + +#endif // EXTENSIONS_COMMON_FEATURES_BEHAVIOR_FEATURE_H_ diff --git a/extensions/common/features/feature_provider.cc b/extensions/common/features/feature_provider.cc index 1923836..ba8794f7 100644 --- a/extensions/common/features/feature_provider.cc +++ b/extensions/common/features/feature_provider.cc @@ -34,6 +34,8 @@ class Static { make_linked_ptr(client->CreateFeatureProvider("manifest").release()); feature_providers_["permission"] = make_linked_ptr(client->CreateFeatureProvider("permission").release()); + feature_providers_["behavior"] = + make_linked_ptr(client->CreateFeatureProvider("behavior").release()); } typedef std::map<std::string, linked_ptr<FeatureProvider> > @@ -66,4 +68,8 @@ const FeatureProvider* FeatureProvider::GetPermissionFeatures() { return GetByName("permission"); } +const FeatureProvider* FeatureProvider::GetBehaviorFeatures() { + return GetByName("behavior"); +} + } // namespace extensions diff --git a/extensions/common/features/feature_provider.h b/extensions/common/features/feature_provider.h index 887cb22..a45326f 100644 --- a/extensions/common/features/feature_provider.h +++ b/extensions/common/features/feature_provider.h @@ -37,6 +37,7 @@ class FeatureProvider { static const FeatureProvider* GetAPIFeatures(); static const FeatureProvider* GetManifestFeatures(); static const FeatureProvider* GetPermissionFeatures(); + static const FeatureProvider* GetBehaviorFeatures(); }; } // namespace extensions diff --git a/extensions/common/features/simple_feature.cc b/extensions/common/features/simple_feature.cc index c472ae8..2219ace 100644 --- a/extensions/common/features/simple_feature.cc +++ b/extensions/common/features/simple_feature.cc @@ -59,6 +59,8 @@ struct Mappings { contexts["webui"] = Feature::WEBUI_CONTEXT; locations["component"] = SimpleFeature::COMPONENT_LOCATION; + locations["external_component"] = + SimpleFeature::EXTERNAL_COMPONENT_LOCATION; locations["policy"] = SimpleFeature::POLICY_LOCATION; platforms["chromeos"] = Feature::CHROMEOS_PLATFORM; @@ -570,8 +572,9 @@ bool SimpleFeature::MatchesManifestLocation( case SimpleFeature::UNSPECIFIED_LOCATION: return true; case SimpleFeature::COMPONENT_LOCATION: - // TODO(kalman/asargent): Should this include EXTERNAL_COMPONENT too? return manifest_location == Manifest::COMPONENT; + case SimpleFeature::EXTERNAL_COMPONENT_LOCATION: + return manifest_location == Manifest::EXTERNAL_COMPONENT; case SimpleFeature::POLICY_LOCATION: return manifest_location == Manifest::EXTERNAL_POLICY || manifest_location == Manifest::EXTERNAL_POLICY_DOWNLOAD; diff --git a/extensions/common/features/simple_feature.h b/extensions/common/features/simple_feature.h index 27213de..dadf7a6 100644 --- a/extensions/common/features/simple_feature.h +++ b/extensions/common/features/simple_feature.h @@ -27,8 +27,7 @@ class SimpleFeature : public Feature { ~SimpleFeature() override; // Similar to Manifest::Location, these are the classes of locations - // supported in feature files; "component" implies - // COMPONENT/EXTERNAL_COMPONENT manifest location types, etc. + // supported in feature files. // // This is only public for testing. Production code should never access it, // nor should it really have any reason to access the SimpleFeature class @@ -36,6 +35,7 @@ class SimpleFeature : public Feature { enum Location { UNSPECIFIED_LOCATION, COMPONENT_LOCATION, + EXTERNAL_COMPONENT_LOCATION, POLICY_LOCATION, }; diff --git a/extensions/common/features/simple_feature_unittest.cc b/extensions/common/features/simple_feature_unittest.cc index 9f723fa..dce5740 100644 --- a/extensions/common/features/simple_feature_unittest.cc +++ b/extensions/common/features/simple_feature_unittest.cc @@ -380,6 +380,8 @@ TEST(SimpleFeatureTest, Location) { // Component extensions can access any location. EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, Manifest::COMPONENT)); + EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, + Manifest::COMPONENT)); EXPECT_TRUE( LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, @@ -391,6 +393,8 @@ TEST(SimpleFeatureTest, Location) { EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, Manifest::UNPACKED)); EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, + Manifest::EXTERNAL_COMPONENT)); + EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, Manifest::EXTERNAL_PREF_DOWNLOAD)); EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, Manifest::EXTERNAL_POLICY)); @@ -405,11 +409,18 @@ TEST(SimpleFeatureTest, Location) { // Non-policy (except component) extensions cannot access policy. EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION, + Manifest::EXTERNAL_COMPONENT)); + EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::INVALID_LOCATION)); EXPECT_FALSE( LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::UNPACKED)); EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::EXTERNAL_PREF_DOWNLOAD)); + + // External component extensions can access the "external_component" + // location. + EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, + Manifest::EXTERNAL_COMPONENT)); } TEST(SimpleFeatureTest, Platform) { |