Chromium Code Reviews| 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 #include "chrome/common/extensions/features/simple_feature.h" | 5 #include "chrome/common/extensions/features/simple_feature.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 ParseEnum(*iter, &enum_value, mapping); | 134 ParseEnum(*iter, &enum_value, mapping); |
| 135 enum_set->insert(enum_value); | 135 enum_set->insert(enum_value); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ParseURLPatterns(const DictionaryValue* value, | 139 void ParseURLPatterns(const DictionaryValue* value, |
| 140 const std::string& key, | 140 const std::string& key, |
| 141 URLPatternSet* set) { | 141 URLPatternSet* set) { |
| 142 const ListValue* matches = NULL; | 142 const ListValue* matches = NULL; |
| 143 if (value->GetList(key, &matches)) { | 143 if (value->GetList(key, &matches)) { |
| 144 set->ClearPatterns(); | |
| 144 for (size_t i = 0; i < matches->GetSize(); ++i) { | 145 for (size_t i = 0; i < matches->GetSize(); ++i) { |
| 145 std::string pattern; | 146 std::string pattern; |
| 146 CHECK(matches->GetString(i, &pattern)); | 147 CHECK(matches->GetString(i, &pattern)); |
| 147 set->AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern)); | 148 set->AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern)); |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 // Gets a human-readable name for the given extension type. | 153 // Gets a human-readable name for the given extension type. |
| 153 std::string GetDisplayTypeName(Manifest::Type type) { | 154 std::string GetDisplayTypeName(Manifest::Type type) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 180 return base::HexEncode(id_hash.c_str(), id_hash.length()); | 181 return base::HexEncode(id_hash.c_str(), id_hash.length()); |
| 181 } | 182 } |
| 182 | 183 |
| 183 } // namespace | 184 } // namespace |
| 184 | 185 |
| 185 SimpleFeature::SimpleFeature() | 186 SimpleFeature::SimpleFeature() |
| 186 : location_(UNSPECIFIED_LOCATION), | 187 : location_(UNSPECIFIED_LOCATION), |
| 187 platform_(UNSPECIFIED_PLATFORM), | 188 platform_(UNSPECIFIED_PLATFORM), |
| 188 min_manifest_version_(0), | 189 min_manifest_version_(0), |
| 189 max_manifest_version_(0), | 190 max_manifest_version_(0), |
| 190 channel_(VersionInfo::CHANNEL_UNKNOWN) { | 191 channel_(VersionInfo::CHANNEL_UNKNOWN), |
| 192 has_parent_(false) { | |
| 191 } | 193 } |
| 192 | 194 |
| 193 SimpleFeature::SimpleFeature(const SimpleFeature& other) | 195 SimpleFeature::SimpleFeature(const SimpleFeature& other) |
| 194 : whitelist_(other.whitelist_), | 196 : whitelist_(other.whitelist_), |
| 195 extension_types_(other.extension_types_), | 197 extension_types_(other.extension_types_), |
| 196 contexts_(other.contexts_), | 198 contexts_(other.contexts_), |
| 197 matches_(other.matches_), | 199 matches_(other.matches_), |
| 198 location_(other.location_), | 200 location_(other.location_), |
| 199 platform_(other.platform_), | 201 platform_(other.platform_), |
| 200 min_manifest_version_(other.min_manifest_version_), | 202 min_manifest_version_(other.min_manifest_version_), |
| 201 max_manifest_version_(other.max_manifest_version_), | 203 max_manifest_version_(other.max_manifest_version_), |
| 202 channel_(other.channel_) { | 204 channel_(other.channel_), |
| 205 has_parent_(other.has_parent_) { | |
| 203 } | 206 } |
| 204 | 207 |
| 205 SimpleFeature::~SimpleFeature() { | 208 SimpleFeature::~SimpleFeature() { |
| 206 } | 209 } |
| 207 | 210 |
| 208 bool SimpleFeature::Equals(const SimpleFeature& other) const { | 211 bool SimpleFeature::Equals(const SimpleFeature& other) const { |
| 209 return whitelist_ == other.whitelist_ && | 212 return whitelist_ == other.whitelist_ && |
| 210 extension_types_ == other.extension_types_ && | 213 extension_types_ == other.extension_types_ && |
| 211 contexts_ == other.contexts_ && | 214 contexts_ == other.contexts_ && |
| 212 matches_ == other.matches_ && | 215 matches_ == other.matches_ && |
| 213 location_ == other.location_ && | 216 location_ == other.location_ && |
| 214 platform_ == other.platform_ && | 217 platform_ == other.platform_ && |
| 215 min_manifest_version_ == other.min_manifest_version_ && | 218 min_manifest_version_ == other.min_manifest_version_ && |
| 216 max_manifest_version_ == other.max_manifest_version_ && | 219 max_manifest_version_ == other.max_manifest_version_ && |
| 217 channel_ == other.channel_; | 220 channel_ == other.channel_ && |
| 221 has_parent_ == other.has_parent_; | |
| 218 } | 222 } |
| 219 | 223 |
| 220 std::string SimpleFeature::Parse(const DictionaryValue* value) { | 224 std::string SimpleFeature::Parse(const DictionaryValue* value) { |
| 221 ParseURLPatterns(value, "matches", &matches_); | 225 ParseURLPatterns(value, "matches", &matches_); |
| 222 ParseSet(value, "whitelist", &whitelist_); | 226 ParseSet(value, "whitelist", &whitelist_); |
| 223 ParseSet(value, "dependencies", &dependencies_); | 227 ParseSet(value, "dependencies", &dependencies_); |
| 224 ParseEnumSet<Manifest::Type>(value, "extension_types", &extension_types_, | 228 ParseEnumSet<Manifest::Type>(value, "extension_types", &extension_types_, |
| 225 g_mappings.Get().extension_types); | 229 g_mappings.Get().extension_types); |
| 226 ParseEnumSet<Context>(value, "contexts", &contexts_, | 230 ParseEnumSet<Context>(value, "contexts", &contexts_, |
| 227 g_mappings.Get().contexts); | 231 g_mappings.Get().contexts); |
| 228 ParseEnum<Location>(value, "location", &location_, | 232 ParseEnum<Location>(value, "location", &location_, |
| 229 g_mappings.Get().locations); | 233 g_mappings.Get().locations); |
| 230 ParseEnum<Platform>(value, "platform", &platform_, | 234 ParseEnum<Platform>(value, "platform", &platform_, |
| 231 g_mappings.Get().platforms); | 235 g_mappings.Get().platforms); |
| 232 value->GetInteger("min_manifest_version", &min_manifest_version_); | 236 value->GetInteger("min_manifest_version", &min_manifest_version_); |
| 233 value->GetInteger("max_manifest_version", &max_manifest_version_); | 237 value->GetInteger("max_manifest_version", &max_manifest_version_); |
| 234 ParseEnum<VersionInfo::Channel>( | 238 ParseEnum<VersionInfo::Channel>( |
| 235 value, "channel", &channel_, | 239 value, "channel", &channel_, |
| 236 g_mappings.Get().channels); | 240 g_mappings.Get().channels); |
| 237 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { | 241 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { |
| 238 return name() + ": Allowing web_page contexts requires supplying a value " + | 242 return name() + ": Allowing web_page contexts requires supplying a value " + |
| 239 "for matches."; | 243 "for matches."; |
| 240 } | 244 } |
| 245 has_parent_ = value->HasKey("parent"); | |
| 241 return std::string(); | 246 return std::string(); |
| 242 } | 247 } |
| 243 | 248 |
| 244 Feature::Availability SimpleFeature::IsAvailableToManifest( | 249 Feature::Availability SimpleFeature::IsAvailableToManifest( |
| 245 const std::string& extension_id, | 250 const std::string& extension_id, |
| 246 Manifest::Type type, | 251 Manifest::Type type, |
| 247 Location location, | 252 Location location, |
| 248 int manifest_version, | 253 int manifest_version, |
| 249 Platform platform) const { | 254 Platform platform) const { |
| 250 // Component extensions can access any feature. | 255 // Component extensions can access any feature. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 281 | 286 |
| 282 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) | 287 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) |
| 283 return CreateAvailability(INVALID_PLATFORM, type); | 288 return CreateAvailability(INVALID_PLATFORM, type); |
| 284 | 289 |
| 285 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) | 290 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) |
| 286 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); | 291 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); |
| 287 | 292 |
| 288 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) | 293 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) |
| 289 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); | 294 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); |
| 290 | 295 |
| 291 if (channel_ < Feature::GetCurrentChannel()) | 296 if (dependencies_.empty() && channel_ < Feature::GetCurrentChannel()) |
|
not at google - send to devlin
2013/05/24 19:09:18
why this change? if we're merging in our parent's
cduvall
2013/05/30 00:50:51
This is different than the parent features. This i
not at google - send to devlin
2013/05/30 16:38:51
Oh ok. I think I made a comment like this earlier
cduvall
2013/06/12 01:22:19
Done.
| |
| 292 return CreateAvailability(UNSUPPORTED_CHANNEL, type); | 297 return CreateAvailability(UNSUPPORTED_CHANNEL, type); |
| 293 | 298 |
| 294 return CreateAvailability(IS_AVAILABLE, type); | 299 return CreateAvailability(IS_AVAILABLE, type); |
| 295 } | 300 } |
| 296 | 301 |
| 297 Feature::Availability SimpleFeature::IsAvailableToContext( | 302 Feature::Availability SimpleFeature::IsAvailableToContext( |
| 298 const Extension* extension, | 303 const Extension* extension, |
| 299 SimpleFeature::Context context, | 304 SimpleFeature::Context context, |
| 300 const GURL& url, | 305 const GURL& url, |
| 301 SimpleFeature::Platform platform) const { | 306 SimpleFeature::Platform platform) const { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 | 421 |
| 417 std::set<Feature::Context>* SimpleFeature::GetContexts() { | 422 std::set<Feature::Context>* SimpleFeature::GetContexts() { |
| 418 return &contexts_; | 423 return &contexts_; |
| 419 } | 424 } |
| 420 | 425 |
| 421 bool SimpleFeature::IsInternal() const { | 426 bool SimpleFeature::IsInternal() const { |
| 422 NOTREACHED(); | 427 NOTREACHED(); |
| 423 return false; | 428 return false; |
| 424 } | 429 } |
| 425 | 430 |
| 431 bool SimpleFeature::HasParent() const { | |
| 432 return has_parent_; | |
| 433 } | |
| 434 | |
| 426 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { | 435 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { |
| 427 // Belt-and-suspenders philosophy here. We should be pretty confident by this | 436 // Belt-and-suspenders philosophy here. We should be pretty confident by this |
| 428 // point that we've validated the extension ID format, but in case something | 437 // point that we've validated the extension ID format, but in case something |
| 429 // slips through, we avoid a class of attack where creative ID manipulation | 438 // slips through, we avoid a class of attack where creative ID manipulation |
| 430 // leads to hash collisions. | 439 // leads to hash collisions. |
| 431 if (extension_id.length() != 32) // 128 bits / 4 = 32 mpdecimal characters | 440 if (extension_id.length() != 32) // 128 bits / 4 = 32 mpdecimal characters |
| 432 return false; | 441 return false; |
| 433 | 442 |
| 434 if (whitelist_.find(extension_id) != whitelist_.end() || | 443 if (whitelist_.find(extension_id) != whitelist_.end() || |
| 435 whitelist_.find(HashExtensionId(extension_id)) != whitelist_.end()) | 444 whitelist_.find(HashExtensionId(extension_id)) != whitelist_.end()) |
| 436 return true; | 445 return true; |
| 437 | 446 |
| 438 return false; | 447 return false; |
| 439 } | 448 } |
| 440 | 449 |
| 441 } // namespace extensions | 450 } // namespace extensions |
| OLD | NEW |