| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 int max_manifest_version() const { return max_manifest_version_; } | 96 int max_manifest_version() const { return max_manifest_version_; } |
| 97 void set_max_manifest_version(int max_manifest_version) { | 97 void set_max_manifest_version(int max_manifest_version) { |
| 98 max_manifest_version_ = max_manifest_version; | 98 max_manifest_version_ = max_manifest_version; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Parses the JSON representation of a feature into the fields of this object. | 101 // Parses the JSON representation of a feature into the fields of this object. |
| 102 // Unspecified values in the JSON are not modified in the object. This allows | 102 // Unspecified values in the JSON are not modified in the object. This allows |
| 103 // us to implement inheritance by parsing one value after another. | 103 // us to implement inheritance by parsing one value after another. |
| 104 void Parse(const DictionaryValue* value); | 104 virtual void Parse(const DictionaryValue* value); |
| 105 | 105 |
| 106 // Returns true if the feature contains the same values as another. | 106 // Returns true if the feature contains the same values as another. |
| 107 bool Equals(const Feature& other) const; | 107 bool Equals(const Feature& other) const; |
| 108 | 108 |
| 109 // Returns true if the Feature contains no specification. |
| 110 bool IsEmpty() const; |
| 111 |
| 109 // Returns true if the feature is available to be parsed into a new extension | 112 // Returns true if the feature is available to be parsed into a new extension |
| 110 // manifest. | 113 // manifest. |
| 111 Availability IsAvailableToManifest(const std::string& extension_id, | 114 Availability IsAvailableToManifest(const std::string& extension_id, |
| 112 Extension::Type type, | 115 Extension::Type type, |
| 113 Location location, | 116 Location location, |
| 114 int manifest_version) const { | 117 int manifest_version) const { |
| 115 return IsAvailableToManifest(extension_id, type, location, manifest_version, | 118 return IsAvailableToManifest(extension_id, type, location, manifest_version, |
| 116 GetCurrentPlatform()); | 119 GetCurrentPlatform()); |
| 117 } | 120 } |
| 118 Availability IsAvailableToManifest(const std::string& extension_id, | 121 Availability IsAvailableToManifest(const std::string& extension_id, |
| 119 Extension::Type type, | 122 Extension::Type type, |
| 120 Location location, | 123 Location location, |
| 121 int manifest_version, | 124 int manifest_version, |
| 122 Platform platform) const; | 125 Platform platform) const; |
| 123 | 126 |
| 124 // Returns true if the feature is available to be used in the specified | 127 // Returns true if the feature is available to be used in the specified |
| 125 // extension and context. | 128 // extension and context. |
| 126 Availability IsAvailableToContext(const Extension* extension, | 129 Availability IsAvailableToContext(const Extension* extension, |
| 127 Context context) const { | 130 Context context) const { |
| 128 return IsAvailableToContext(extension, context, GetCurrentPlatform()); | 131 return IsAvailableToContext(extension, context, GetCurrentPlatform()); |
| 129 } | 132 } |
| 130 virtual Availability IsAvailableToContext(const Extension* extension, | 133 virtual Availability IsAvailableToContext(const Extension* extension, |
| 131 Context context, | 134 Context context, |
| 132 Platform platform) const; | 135 Platform platform) const; |
| 133 | 136 |
| 134 // Returns an error message for an Availability code. | 137 // Returns an error message for an Availability code. |
| 135 std::string GetErrorMessage(Availability result); | 138 std::string GetErrorMessage(Availability result); |
| 136 | 139 |
| 140 protected: |
| 141 static void ParseSet(const DictionaryValue* value, |
| 142 const std::string& property, |
| 143 std::set<std::string>* set); |
| 144 |
| 137 private: | 145 private: |
| 138 std::string name_; | 146 std::string name_; |
| 139 | 147 |
| 140 // For clarify and consistency, we handle the default value of each of these | 148 // For clarify and consistency, we handle the default value of each of these |
| 141 // members the same way: it matches everything. It is up to the higher level | 149 // members the same way: it matches everything. It is up to the higher level |
| 142 // code that reads Features out of static data to validate that data and set | 150 // code that reads Features out of static data to validate that data and set |
| 143 // sensible defaults. | 151 // sensible defaults. |
| 144 std::set<std::string> whitelist_; | 152 std::set<std::string> whitelist_; |
| 145 std::set<Extension::Type> extension_types_; | 153 std::set<Extension::Type> extension_types_; |
| 146 std::set<Context> contexts_; | 154 std::set<Context> contexts_; |
| 147 Location location_; // we only care about component/not-component now | 155 Location location_; // we only care about component/not-component now |
| 148 Platform platform_; // we only care about chromeos/not-chromeos now | 156 Platform platform_; // we only care about chromeos/not-chromeos now |
| 149 int min_manifest_version_; | 157 int min_manifest_version_; |
| 150 int max_manifest_version_; | 158 int max_manifest_version_; |
| 151 }; | 159 }; |
| 152 | 160 |
| 153 } // namespace extensions | 161 } // namespace extensions |
| 154 | 162 |
| 155 #endif // CHROME_COMMON_EXTENSIONS_FEATURE_H_ | 163 #endif // CHROME_COMMON_EXTENSIONS_FEATURE_H_ |
| OLD | NEW |