OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_SIMPLE_FEATURE_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_FEATURES_SIMPLE_FEATURE_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "base/values.h" |
| 12 #include "chrome/common/chrome_version_info.h" |
| 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/features/feature.h" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 class ComplexFeature; |
| 19 |
| 20 class SimpleFeature : public Feature { |
| 21 public: |
| 22 SimpleFeature(); |
| 23 SimpleFeature(const SimpleFeature& other); |
| 24 virtual ~SimpleFeature(); |
| 25 |
| 26 std::set<std::string>* whitelist() { return &whitelist_; } |
| 27 std::set<Extension::Type>* extension_types() { return &extension_types_; } |
| 28 |
| 29 // Parses the JSON representation of a feature into the fields of this object. |
| 30 // Unspecified values in the JSON are not modified in the object. This allows |
| 31 // us to implement inheritance by parsing one value after another. |
| 32 void Parse(const DictionaryValue* value); |
| 33 |
| 34 // Returns true if the feature contains the same values as another. |
| 35 bool Equals(const SimpleFeature& other) const; |
| 36 |
| 37 Location location() const { return location_; } |
| 38 void set_location(Location location) { location_ = location; } |
| 39 |
| 40 Platform platform() const { return platform_; } |
| 41 void set_platform(Platform platform) { platform_ = platform; } |
| 42 |
| 43 int min_manifest_version() const { return min_manifest_version_; } |
| 44 void set_min_manifest_version(int min_manifest_version) { |
| 45 min_manifest_version_ = min_manifest_version; |
| 46 } |
| 47 |
| 48 int max_manifest_version() const { return max_manifest_version_; } |
| 49 void set_max_manifest_version(int max_manifest_version) { |
| 50 max_manifest_version_ = max_manifest_version; |
| 51 } |
| 52 |
| 53 Availability IsAvailableToContext(const Extension* extension, |
| 54 Context context) const { |
| 55 return IsAvailableToContext(extension, context, GetCurrentPlatform()); |
| 56 } |
| 57 |
| 58 // extension::Feature: |
| 59 virtual Availability IsAvailableToManifest(const std::string& extension_id, |
| 60 Extension::Type type, |
| 61 Location location, |
| 62 int manifest_version, |
| 63 Platform platform) const OVERRIDE; |
| 64 |
| 65 virtual Availability IsAvailableToContext(const Extension* extension, |
| 66 Context context, |
| 67 Platform platform) const OVERRIDE; |
| 68 |
| 69 virtual std::string GetAvailabilityMessage( |
| 70 AvailabilityResult result, Extension::Type type) const OVERRIDE; |
| 71 |
| 72 virtual std::set<Context>* GetContexts() OVERRIDE; |
| 73 |
| 74 protected: |
| 75 Availability CreateAvailability(AvailabilityResult result) const; |
| 76 Availability CreateAvailability(AvailabilityResult result, |
| 77 Extension::Type type) const; |
| 78 |
| 79 private: |
| 80 // For clarity and consistency, we handle the default value of each of these |
| 81 // members the same way: it matches everything. It is up to the higher level |
| 82 // code that reads Features out of static data to validate that data and set |
| 83 // sensible defaults. |
| 84 std::set<std::string> whitelist_; |
| 85 std::set<Extension::Type> extension_types_; |
| 86 std::set<Context> contexts_; |
| 87 Location location_; // we only care about component/not-component now |
| 88 Platform platform_; // we only care about chromeos/not-chromeos now |
| 89 int min_manifest_version_; |
| 90 int max_manifest_version_; |
| 91 chrome::VersionInfo::Channel channel_; |
| 92 |
| 93 FRIEND_TEST_ALL_PREFIXES(ExtensionSimpleFeatureTest, Context); |
| 94 }; |
| 95 |
| 96 } // namespace extensions |
| 97 |
| 98 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_SIMPLE_FEATURE_H_ |
OLD | NEW |