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

Unified Diff: extensions/common/features/feature_provider.cc

Issue 2950353004: [Extensions Bindings] Check availability of custom API properties (Closed)
Patch Set: . Created 3 years, 6 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: extensions/common/features/feature_provider.cc
diff --git a/extensions/common/features/feature_provider.cc b/extensions/common/features/feature_provider.cc
index 5e5b14519e50e55c49f0ed5c6fbbaf2da213a24b..0d2f792a65dfb56a617e18dc90d4a500bd2304d0 100644
--- a/extensions/common/features/feature_provider.cc
+++ b/extensions/common/features/feature_provider.cc
@@ -140,12 +140,17 @@ Feature* FeatureProvider::GetParent(Feature* feature) const {
if (feature->no_parent())
return nullptr;
- std::vector<base::StringPiece> split = base::SplitStringPiece(
- feature->name(), ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- if (split.size() < 2)
- return nullptr;
- split.pop_back();
- return GetFeature(base::JoinString(split, "."));
+ base::StringPiece name = feature->name();
+ base::StringPiece::size_type pos = base::StringPiece::npos;
+ // Continue searching up the chain, so that foo.child.grandchild has a parent
+ // of foo (even if foo.child isn't explicitly defined).
+ while ((pos = name.rfind('.')) != base::StringPiece::npos) {
+ name = name.substr(0, pos);
+ Feature* feature = GetFeature(name.as_string());
+ if (feature)
+ return feature;
+ }
+ return nullptr;
}
// Children of a given API are named starting with parent.name()+".", which

Powered by Google App Engine
This is Rietveld 408576698