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