| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return "legacy packaged app"; | 161 return "legacy packaged app"; |
| 162 case Manifest::TYPE_PLATFORM_APP: | 162 case Manifest::TYPE_PLATFORM_APP: |
| 163 return "packaged app"; | 163 return "packaged app"; |
| 164 case Manifest::TYPE_THEME: | 164 case Manifest::TYPE_THEME: |
| 165 return "theme"; | 165 return "theme"; |
| 166 case Manifest::TYPE_USER_SCRIPT: | 166 case Manifest::TYPE_USER_SCRIPT: |
| 167 return "user script"; | 167 return "user script"; |
| 168 } | 168 } |
| 169 | 169 |
| 170 NOTREACHED(); | 170 NOTREACHED(); |
| 171 return ""; | 171 return std::string(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace | 174 } // namespace |
| 175 | 175 |
| 176 SimpleFeature::SimpleFeature() | 176 SimpleFeature::SimpleFeature() |
| 177 : location_(UNSPECIFIED_LOCATION), | 177 : location_(UNSPECIFIED_LOCATION), |
| 178 platform_(UNSPECIFIED_PLATFORM), | 178 platform_(UNSPECIFIED_PLATFORM), |
| 179 min_manifest_version_(0), | 179 min_manifest_version_(0), |
| 180 max_manifest_version_(0), | 180 max_manifest_version_(0), |
| 181 channel_(VersionInfo::CHANNEL_UNKNOWN) { | 181 channel_(VersionInfo::CHANNEL_UNKNOWN) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 g_mappings.Get().platforms); | 222 g_mappings.Get().platforms); |
| 223 value->GetInteger("min_manifest_version", &min_manifest_version_); | 223 value->GetInteger("min_manifest_version", &min_manifest_version_); |
| 224 value->GetInteger("max_manifest_version", &max_manifest_version_); | 224 value->GetInteger("max_manifest_version", &max_manifest_version_); |
| 225 ParseEnum<VersionInfo::Channel>( | 225 ParseEnum<VersionInfo::Channel>( |
| 226 value, "channel", &channel_, | 226 value, "channel", &channel_, |
| 227 g_mappings.Get().channels); | 227 g_mappings.Get().channels); |
| 228 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { | 228 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { |
| 229 return name() + ": Allowing web_page contexts requires supplying a value " + | 229 return name() + ": Allowing web_page contexts requires supplying a value " + |
| 230 "for matches."; | 230 "for matches."; |
| 231 } | 231 } |
| 232 return ""; | 232 return std::string(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 Feature::Availability SimpleFeature::IsAvailableToManifest( | 235 Feature::Availability SimpleFeature::IsAvailableToManifest( |
| 236 const std::string& extension_id, | 236 const std::string& extension_id, |
| 237 Manifest::Type type, | 237 Manifest::Type type, |
| 238 Location location, | 238 Location location, |
| 239 int manifest_version, | 239 int manifest_version, |
| 240 Platform platform) const { | 240 Platform platform) const { |
| 241 // Component extensions can access any feature. | 241 // Component extensions can access any feature. |
| 242 if (location == COMPONENT_LOCATION) | 242 if (location == COMPONENT_LOCATION) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (!matches_.is_empty() && !matches_.MatchesURL(url)) | 306 if (!matches_.is_empty() && !matches_.MatchesURL(url)) |
| 307 return CreateAvailability(INVALID_URL, url); | 307 return CreateAvailability(INVALID_URL, url); |
| 308 | 308 |
| 309 return CreateAvailability(IS_AVAILABLE); | 309 return CreateAvailability(IS_AVAILABLE); |
| 310 } | 310 } |
| 311 | 311 |
| 312 std::string SimpleFeature::GetAvailabilityMessage( | 312 std::string SimpleFeature::GetAvailabilityMessage( |
| 313 AvailabilityResult result, Manifest::Type type, const GURL& url) const { | 313 AvailabilityResult result, Manifest::Type type, const GURL& url) const { |
| 314 switch (result) { | 314 switch (result) { |
| 315 case IS_AVAILABLE: | 315 case IS_AVAILABLE: |
| 316 return ""; | 316 return std::string(); |
| 317 case NOT_FOUND_IN_WHITELIST: | 317 case NOT_FOUND_IN_WHITELIST: |
| 318 return base::StringPrintf( | 318 return base::StringPrintf( |
| 319 "'%s' is not allowed for specified extension ID.", | 319 "'%s' is not allowed for specified extension ID.", |
| 320 name().c_str()); | 320 name().c_str()); |
| 321 case INVALID_URL: | 321 case INVALID_URL: |
| 322 CHECK(url.is_valid()); | 322 CHECK(url.is_valid()); |
| 323 return base::StringPrintf("'%s' is not allowed on %s.", | 323 return base::StringPrintf("'%s' is not allowed on %s.", |
| 324 name().c_str(), url.spec().c_str()); | 324 name().c_str(), url.spec().c_str()); |
| 325 case INVALID_TYPE: { | 325 case INVALID_TYPE: { |
| 326 std::string allowed_type_names; | 326 std::string allowed_type_names; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 case UNSUPPORTED_CHANNEL: | 374 case UNSUPPORTED_CHANNEL: |
| 375 return base::StringPrintf( | 375 return base::StringPrintf( |
| 376 "'%s' requires Google Chrome %s channel or newer, and this is the " | 376 "'%s' requires Google Chrome %s channel or newer, and this is the " |
| 377 "%s channel.", | 377 "%s channel.", |
| 378 name().c_str(), | 378 name().c_str(), |
| 379 GetChannelName(channel_).c_str(), | 379 GetChannelName(channel_).c_str(), |
| 380 GetChannelName(GetCurrentChannel()).c_str()); | 380 GetChannelName(GetCurrentChannel()).c_str()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 NOTREACHED(); | 383 NOTREACHED(); |
| 384 return ""; | 384 return std::string(); |
| 385 } | 385 } |
| 386 | 386 |
| 387 Feature::Availability SimpleFeature::CreateAvailability( | 387 Feature::Availability SimpleFeature::CreateAvailability( |
| 388 AvailabilityResult result) const { | 388 AvailabilityResult result) const { |
| 389 return Availability( | 389 return Availability( |
| 390 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL())); | 390 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL())); |
| 391 } | 391 } |
| 392 | 392 |
| 393 Feature::Availability SimpleFeature::CreateAvailability( | 393 Feature::Availability SimpleFeature::CreateAvailability( |
| 394 AvailabilityResult result, Manifest::Type type) const { | 394 AvailabilityResult result, Manifest::Type type) const { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 DCHECK(id_hash.length() == base::kSHA1Length); | 437 DCHECK(id_hash.length() == base::kSHA1Length); |
| 438 const std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(), | 438 const std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(), |
| 439 id_hash.length()); | 439 id_hash.length()); |
| 440 if (whitelist_.find(hexencoded_id_hash) != whitelist_.end()) | 440 if (whitelist_.find(hexencoded_id_hash) != whitelist_.end()) |
| 441 return true; | 441 return true; |
| 442 | 442 |
| 443 return false; | 443 return false; |
| 444 } | 444 } |
| 445 | 445 |
| 446 } // namespace extensions | 446 } // namespace extensions |
| OLD | NEW |