| 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_FEATURE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 friend class Feature; | 76 friend class Feature; |
| 77 | 77 |
| 78 // Instances should be created via Feature::CreateAvailability. | 78 // Instances should be created via Feature::CreateAvailability. |
| 79 Availability(AvailabilityResult result, const std::string& message) | 79 Availability(AvailabilityResult result, const std::string& message) |
| 80 : result_(result), message_(message) { } | 80 : result_(result), message_(message) { } |
| 81 | 81 |
| 82 const AvailabilityResult result_; | 82 const AvailabilityResult result_; |
| 83 const std::string message_; | 83 const std::string message_; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 Feature(); | 86 Feature() {} |
| 87 Feature(const Feature& other); | 87 virtual ~Feature() {} |
| 88 virtual ~Feature(); | 88 |
| 89 const std::string& name() const { return name_; } |
| 90 void set_name(const std::string& name) { name_ = name; } |
| 89 | 91 |
| 90 // Gets the current channel as seen by the Feature system. | 92 // Gets the current channel as seen by the Feature system. |
| 91 static chrome::VersionInfo::Channel GetCurrentChannel(); | 93 static chrome::VersionInfo::Channel GetCurrentChannel(); |
| 92 | 94 |
| 93 // Sets the current channel as seen by the Feature system. In the browser | 95 // Sets the current channel as seen by the Feature system. In the browser |
| 94 // process this should be chrome::VersionInfo::GetChannel(), and in the | 96 // process this should be chrome::VersionInfo::GetChannel(), and in the |
| 95 // renderer this will need to come from an IPC. | 97 // renderer this will need to come from an IPC. |
| 96 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); | 98 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); |
| 97 | 99 |
| 98 // Gets the default channel as seen by the Feature system. | 100 // Gets the default channel as seen by the Feature system. |
| 99 static chrome::VersionInfo::Channel GetDefaultChannel(); | 101 static chrome::VersionInfo::Channel GetDefaultChannel(); |
| 100 | 102 |
| 101 // Scoped channel setter. Use for tests. | 103 // Scoped channel setter. Use for tests. |
| 102 class ScopedCurrentChannel { | 104 class ScopedCurrentChannel { |
| 103 public: | 105 public: |
| 104 explicit ScopedCurrentChannel(chrome::VersionInfo::Channel channel) | 106 explicit ScopedCurrentChannel(chrome::VersionInfo::Channel channel) |
| 105 : original_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { | 107 : original_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 106 original_channel_ = GetCurrentChannel(); | 108 original_channel_ = GetCurrentChannel(); |
| 107 SetCurrentChannel(channel); | 109 SetCurrentChannel(channel); |
| 108 } | 110 } |
| 109 | 111 |
| 110 ~ScopedCurrentChannel() { | 112 ~ScopedCurrentChannel() { |
| 111 SetCurrentChannel(original_channel_); | 113 SetCurrentChannel(original_channel_); |
| 112 } | 114 } |
| 113 | 115 |
| 114 private: | 116 private: |
| 115 chrome::VersionInfo::Channel original_channel_; | 117 chrome::VersionInfo::Channel original_channel_; |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 const std::string& name() const { return name_; } | |
| 119 void set_name(const std::string& name) { name_ = name; } | |
| 120 | |
| 121 // Gets the platform the code is currently running on. | 120 // Gets the platform the code is currently running on. |
| 122 static Platform GetCurrentPlatform(); | 121 static Platform GetCurrentPlatform(); |
| 123 | 122 |
| 124 // Gets the Feature::Location value for the specified Extension::Location. | 123 // Gets the Feature::Location value for the specified Extension::Location. |
| 125 static Location ConvertLocation(Extension::Location extension_location); | 124 static Location ConvertLocation(Extension::Location extension_location); |
| 126 | 125 |
| 127 std::set<std::string>* whitelist() { return &whitelist_; } | |
| 128 std::set<Extension::Type>* extension_types() { return &extension_types_; } | |
| 129 std::set<Context>* contexts() { return &contexts_; } | |
| 130 | |
| 131 Location location() const { return location_; } | |
| 132 void set_location(Location location) { location_ = location; } | |
| 133 | |
| 134 Platform platform() const { return platform_; } | |
| 135 void set_platform(Platform platform) { platform_ = platform; } | |
| 136 | |
| 137 int min_manifest_version() const { return min_manifest_version_; } | |
| 138 void set_min_manifest_version(int min_manifest_version) { | |
| 139 min_manifest_version_ = min_manifest_version; | |
| 140 } | |
| 141 | |
| 142 int max_manifest_version() const { return max_manifest_version_; } | |
| 143 void set_max_manifest_version(int max_manifest_version) { | |
| 144 max_manifest_version_ = max_manifest_version; | |
| 145 } | |
| 146 | |
| 147 // Parses the JSON representation of a feature into the fields of this object. | |
| 148 // Unspecified values in the JSON are not modified in the object. This allows | |
| 149 // us to implement inheritance by parsing one value after another. | |
| 150 void Parse(const DictionaryValue* value); | |
| 151 | |
| 152 // Returns true if the feature contains the same values as another. | |
| 153 bool Equals(const Feature& other) const; | |
| 154 | 126 |
| 155 // Returns true if the feature is available to be parsed into a new extension | 127 // Returns true if the feature is available to be parsed into a new extension |
| 156 // manifest. | 128 // manifest. |
| 157 Availability IsAvailableToManifest(const std::string& extension_id, | 129 Availability IsAvailableToManifest(const std::string& extension_id, |
| 158 Extension::Type type, | 130 Extension::Type type, |
| 159 Location location, | 131 Location location, |
| 160 int manifest_version) const { | 132 int manifest_version) const { |
| 161 return IsAvailableToManifest(extension_id, type, location, manifest_version, | 133 return IsAvailableToManifest(extension_id, type, location, manifest_version, |
| 162 GetCurrentPlatform()); | 134 GetCurrentPlatform()); |
| 163 } | 135 } |
| 164 Availability IsAvailableToManifest(const std::string& extension_id, | 136 virtual Availability IsAvailableToManifest(const std::string& extension_id, |
| 165 Extension::Type type, | 137 Extension::Type type, |
| 166 Location location, | 138 Location location, |
| 167 int manifest_version, | 139 int manifest_version, |
| 168 Platform platform) const; | 140 Platform platform) const = 0; |
| 169 | 141 |
| 170 // Returns true if the feature is available to be used in the specified | 142 // Returns true if the feature is available to be used in the specified |
| 171 // extension and context. | 143 // extension and context. |
| 172 Availability IsAvailableToContext(const Extension* extension, | 144 Availability IsAvailableToContext(const Extension* extension, |
| 173 Context context) const { | 145 Context context) const { |
| 174 return IsAvailableToContext(extension, context, GetCurrentPlatform()); | 146 return IsAvailableToContext(extension, context, GetCurrentPlatform()); |
| 175 } | 147 } |
| 176 virtual Availability IsAvailableToContext(const Extension* extension, | 148 virtual Availability IsAvailableToContext(const Extension* extension, |
| 177 Context context, | 149 Context context, |
| 178 Platform platform) const; | 150 Platform platform) const = 0; |
| 179 | 151 |
| 180 protected: | 152 protected: |
| 181 Availability CreateAvailability(AvailabilityResult result) const; | 153 Availability CreateAvailability(AvailabilityResult result) const; |
| 182 Availability CreateAvailability(AvailabilityResult result, | 154 Availability CreateAvailability(AvailabilityResult result, |
| 183 Extension::Type type) const; | 155 Extension::Type type) const; |
| 184 | 156 |
| 185 private: | 157 virtual std::string GetAvailabilityMessage( |
| 186 std::string GetAvailabilityMessage( | 158 AvailabilityResult result, Extension::Type type) const = 0; |
| 187 AvailabilityResult result, Extension::Type type) const; | |
| 188 | 159 |
| 189 std::string name_; | 160 std::string name_; |
| 190 | |
| 191 // For clarify and consistency, we handle the default value of each of these | |
| 192 // members the same way: it matches everything. It is up to the higher level | |
| 193 // code that reads Features out of static data to validate that data and set | |
| 194 // sensible defaults. | |
| 195 std::set<std::string> whitelist_; | |
| 196 std::set<Extension::Type> extension_types_; | |
| 197 std::set<Context> contexts_; | |
| 198 Location location_; // we only care about component/not-component now | |
| 199 Platform platform_; // we only care about chromeos/not-chromeos now | |
| 200 int min_manifest_version_; | |
| 201 int max_manifest_version_; | |
| 202 chrome::VersionInfo::Channel channel_; | |
| 203 }; | 161 }; |
| 204 | 162 |
| 205 } // namespace extensions | 163 } // namespace extensions |
| 206 | 164 |
| 207 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 165 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
| OLD | NEW |