Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: chrome/common/extensions/features/simple_feature.cc

Issue 12522004: Lazily load extension API schemas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/features/simple_feature.cc
diff --git a/chrome/common/extensions/features/simple_feature.cc b/chrome/common/extensions/features/simple_feature.cc
index eb73e0c7a6f9557e2ef4882ca1bdec2ca332aaaa..d1fcbc0642e15c7d6801715dd1815601d58d607a 100644
--- a/chrome/common/extensions/features/simple_feature.cc
+++ b/chrome/common/extensions/features/simple_feature.cc
@@ -135,6 +135,19 @@ void ParseEnumSet(const DictionaryValue* value,
}
}
+void ParseURLPatterns(const DictionaryValue* value,
+ const std::string& key,
+ URLPatternSet* set) {
+ const ListValue* matches = NULL;
+ if (value->GetList(key, &matches)) {
+ for (size_t i = 0; i < matches->GetSize(); ++i) {
+ std::string pattern;
+ DCHECK(matches->GetString(i, &pattern));
not at google - send to devlin 2013/03/22 18:13:48 heisenbug!
+ set->AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern));
+ }
+ }
+}
+
// Gets a human-readable name for the given extension type.
std::string GetDisplayTypeName(Manifest::Type type) {
switch (type) {
@@ -172,6 +185,7 @@ SimpleFeature::SimpleFeature(const SimpleFeature& other)
: whitelist_(other.whitelist_),
extension_types_(other.extension_types_),
contexts_(other.contexts_),
+ matches_(other.matches_),
location_(other.location_),
platform_(other.platform_),
min_manifest_version_(other.min_manifest_version_),
@@ -186,6 +200,7 @@ bool SimpleFeature::Equals(const SimpleFeature& other) const {
return whitelist_ == other.whitelist_ &&
extension_types_ == other.extension_types_ &&
contexts_ == other.contexts_ &&
+ matches_ == other.matches_ &&
location_ == other.location_ &&
platform_ == other.platform_ &&
min_manifest_version_ == other.min_manifest_version_ &&
@@ -194,6 +209,7 @@ bool SimpleFeature::Equals(const SimpleFeature& other) const {
}
void SimpleFeature::Parse(const DictionaryValue* value) {
+ ParseURLPatterns(value, "matches", &matches_);
ParseSet(value, "whitelist", &whitelist_);
ParseEnumSet<Manifest::Type>(value, "extension_types", &extension_types_,
g_mappings.Get().extension_types);
@@ -262,21 +278,30 @@ Feature::Availability SimpleFeature::IsAvailableToManifest(
Feature::Availability SimpleFeature::IsAvailableToContext(
const Extension* extension,
SimpleFeature::Context context,
+ const GURL& url,
SimpleFeature::Platform platform) const {
- Availability result = IsAvailableToManifest(
- extension->id(),
- extension->GetType(),
- ConvertLocation(extension->location()),
- extension->manifest_version(),
- platform);
- if (!result.is_available())
- return result;
+ if (extension) {
+ Availability result = IsAvailableToManifest(
+ extension->id(),
+ extension->GetType(),
+ ConvertLocation(extension->location()),
+ extension->manifest_version(),
+ platform);
+ if (!result.is_available())
+ return result;
+ }
if (!contexts_.empty() &&
contexts_.find(context) == contexts_.end()) {
not at google - send to devlin 2013/03/22 18:13:48 will this fit on 1 line?
cduvall 2013/03/22 20:26:45 Done.
- return CreateAvailability(INVALID_CONTEXT, extension->GetType());
+ if (extension)
+ return CreateAvailability(INVALID_CONTEXT, extension->GetType());
+ else
+ return CreateAvailability(INVALID_CONTEXT);
not at google - send to devlin 2013/03/22 18:13:48 nit: ternary
cduvall 2013/03/22 20:26:45 Done.
}
+ if (!matches_.is_empty() && !matches_.MatchesURL(url))
+ return CreateAvailability(INVALID_URL);
+
return CreateAvailability(IS_AVAILABLE);
}
@@ -289,6 +314,9 @@ std::string SimpleFeature::GetAvailabilityMessage(
return base::StringPrintf(
"'%s' is not allowed for specified extension ID.",
name().c_str());
+ case INVALID_URL:
+ return base::StringPrintf("'%s' is not allowed for this url.",
not at google - send to devlin 2013/03/22 18:13:48 yeah, thread the URL through to GetAvailabilityMes
cduvall 2013/03/22 20:26:45 Done.
+ name().c_str());
case INVALID_TYPE: {
std::string allowed_type_names;
// Turn the set of allowed types into a vector so that it's easier to

Powered by Google App Engine
This is Rietveld 408576698