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_FEATURE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_FEATURE_H_ |
6 #define CHROME_COMMON_EXTENSIONS_FEATURE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_FEATURE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 23 matching lines...) Expand all Loading... |
34 UNSPECIFIED_LOCATION, | 34 UNSPECIFIED_LOCATION, |
35 COMPONENT_LOCATION | 35 COMPONENT_LOCATION |
36 }; | 36 }; |
37 | 37 |
38 // The platforms the feature is supported in. | 38 // The platforms the feature is supported in. |
39 enum Platform { | 39 enum Platform { |
40 UNSPECIFIED_PLATFORM, | 40 UNSPECIFIED_PLATFORM, |
41 CHROMEOS_PLATFORM | 41 CHROMEOS_PLATFORM |
42 }; | 42 }; |
43 | 43 |
| 44 // Whether a feature is available in a given situation or not, and if not, |
| 45 // why not. |
| 46 enum Availability { |
| 47 IS_AVAILABLE, |
| 48 NOT_FOUND_IN_WHITELIST, |
| 49 INVALID_TYPE, |
| 50 INVALID_CONTEXT, |
| 51 INVALID_LOCATION, |
| 52 INVALID_PLATFORM, |
| 53 INVALID_MIN_MANIFEST_VERSION, |
| 54 INVALID_MAX_MANIFEST_VERSION |
| 55 }; |
| 56 |
44 Feature(); | 57 Feature(); |
45 ~Feature(); | 58 ~Feature(); |
46 | 59 |
47 // Parses a feature from its JSON representation. | 60 // Parses a feature from its JSON representation. |
48 static scoped_ptr<Feature> Parse(const DictionaryValue* value); | 61 static scoped_ptr<Feature> Parse(const DictionaryValue* value); |
49 | 62 |
50 // Gets the platform the code is currently running on. | 63 // Gets the platform the code is currently running on. |
51 static Platform GetCurrentPlatform(); | 64 static Platform GetCurrentPlatform(); |
52 | 65 |
53 // Gets the Feature::Location value for the specified Extension::Location. | 66 // Gets the Feature::Location value for the specified Extension::Location. |
(...skipping 14 matching lines...) Expand all Loading... |
68 min_manifest_version_ = min_manifest_version; | 81 min_manifest_version_ = min_manifest_version; |
69 } | 82 } |
70 | 83 |
71 int max_manifest_version() const { return max_manifest_version_; } | 84 int max_manifest_version() const { return max_manifest_version_; } |
72 void set_max_manifest_version(int max_manifest_version) { | 85 void set_max_manifest_version(int max_manifest_version) { |
73 max_manifest_version_ = max_manifest_version; | 86 max_manifest_version_ = max_manifest_version; |
74 } | 87 } |
75 | 88 |
76 // Returns true if the feature is available to the specified extension. Use | 89 // Returns true if the feature is available to the specified extension. Use |
77 // this overload for features that are not associated with a specific context. | 90 // this overload for features that are not associated with a specific context. |
78 bool IsAvailable(const Extension* extension) { | 91 Availability IsAvailable(const Extension* extension) { |
79 return IsAvailable(extension, UNSPECIFIED_CONTEXT); | 92 return IsAvailable(extension, UNSPECIFIED_CONTEXT); |
80 } | 93 } |
81 | 94 |
82 // Returns true if the feature is available to the specified extension, in the | 95 // Returns true if the feature is available to the specified extension, in the |
83 // specified context type. | 96 // specified context type. |
84 bool IsAvailable(const Extension* extension, Context context) { | 97 Availability IsAvailable(const Extension* extension, Context context) { |
85 return IsAvailable(extension->id(), extension->GetType(), | 98 return IsAvailable(extension->id(), extension->GetType(), |
86 ConvertLocation(extension->location()), context, | 99 ConvertLocation(extension->location()), context, |
87 GetCurrentPlatform(), | 100 GetCurrentPlatform(), |
88 extension->manifest_version()); | 101 extension->manifest_version()); |
89 } | 102 } |
90 | 103 |
91 // Returns true if the feature is available to extensions with the specified | 104 // Returns true if the feature is available to extensions with the specified |
92 // properties. Use this overload for features that are not associated with a | 105 // properties. Use this overload for features that are not associated with a |
93 // specific context, and when a full Extension object is not available. | 106 // specific context, and when a full Extension object is not available. |
94 bool IsAvailable(const std::string& extension_id, Extension::Type type, | 107 Availability IsAvailable(const std::string& extension_id, |
95 Location location, int manifest_version) { | 108 Extension::Type type, Location location, |
| 109 int manifest_version) { |
96 return IsAvailable(extension_id, type, location, UNSPECIFIED_CONTEXT, | 110 return IsAvailable(extension_id, type, location, UNSPECIFIED_CONTEXT, |
97 GetCurrentPlatform(), manifest_version); | 111 GetCurrentPlatform(), manifest_version); |
98 } | 112 } |
99 | 113 |
100 // Returns true if the feature is available to extensions with the specified | 114 // Returns true if the feature is available to extensions with the specified |
101 // properties, in the specified context type, and on the specified platform. | 115 // properties, in the specified context type, and on the specified platform. |
102 // This overload is mainly used for testing. | 116 // This overload is mainly used for testing. |
103 bool IsAvailable(const std::string& extension_id, Extension::Type type, | 117 Availability IsAvailable(const std::string& extension_id, |
104 Location location, Context context, | 118 Extension::Type type, Location location, |
105 Platform platform, int manifest_version); | 119 Context context, Platform platform, |
| 120 int manifest_version); |
| 121 |
| 122 // Returns an error message for an Availability code. |
| 123 std::string GetErrorMessage(Availability result); |
106 | 124 |
107 private: | 125 private: |
108 // For clarify and consistency, we handle the default value of each of these | 126 // For clarify and consistency, we handle the default value of each of these |
109 // members the same way: it matches everything. It is up to the higher level | 127 // members the same way: it matches everything. It is up to the higher level |
110 // code that reads Features out of static data to validate that data and set | 128 // code that reads Features out of static data to validate that data and set |
111 // sensible defaults. | 129 // sensible defaults. |
112 std::set<std::string> whitelist_; | 130 std::set<std::string> whitelist_; |
113 std::set<Extension::Type> extension_types_; | 131 std::set<Extension::Type> extension_types_; |
114 std::set<Context> contexts_; | 132 std::set<Context> contexts_; |
115 Location location_; // we only care about component/not-component now | 133 Location location_; // we only care about component/not-component now |
116 Platform platform_; // we only care about chromeos/not-chromeos now | 134 Platform platform_; // we only care about chromeos/not-chromeos now |
117 int min_manifest_version_; | 135 int min_manifest_version_; |
118 int max_manifest_version_; | 136 int max_manifest_version_; |
119 | 137 |
120 DISALLOW_COPY_AND_ASSIGN(Feature); | 138 DISALLOW_COPY_AND_ASSIGN(Feature); |
121 }; | 139 }; |
122 | 140 |
123 } // namespace extensions | 141 } // namespace extensions |
124 | 142 |
125 #endif // CHROME_COMMON_EXTENSIONS_FEATURE_H_ | 143 #endif // CHROME_COMMON_EXTENSIONS_FEATURE_H_ |
OLD | NEW |