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

Unified Diff: chrome/common/extensions/url_pattern_set.cc

Issue 10809094: Context Menus now uses the JSON Schema Compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@json_functions_as_properties
Patch Set: * Created 8 years, 4 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/url_pattern_set.cc
diff --git a/chrome/common/extensions/url_pattern_set.cc b/chrome/common/extensions/url_pattern_set.cc
index 11390ac446311420e19000ecd7963feb7e43f1a8..f5e278761f1b24e966771479ae489b90d5f30291 100644
--- a/chrome/common/extensions/url_pattern_set.cc
+++ b/chrome/common/extensions/url_pattern_set.cc
@@ -175,6 +175,20 @@ scoped_ptr<base::ListValue> URLPatternSet::ToValue() const {
return value.Pass();
}
+bool URLPatternSet::Populate(const std::vector<std::string>& patterns,
+ int valid_schemes,
+ bool allow_file_access,
+ std::string* error) {
+ ClearPatterns();
+ for (size_t i = 0; i < patterns.size(); ++i) {
+ URLPattern pattern(valid_schemes);
+ if (!ParseURLPattern(pattern, patterns.at(i), allow_file_access, error))
+ return false;
+ AddPattern(pattern);
+ }
+ return true;
+}
+
bool URLPatternSet::Populate(const base::ListValue& value,
int valid_schemes,
bool allow_file_access,
@@ -185,20 +199,29 @@ bool URLPatternSet::Populate(const base::ListValue& value,
if (!value.GetString(i, &item))
return false;
URLPattern pattern(valid_schemes);
not at google - send to devlin 2012/08/06 01:55:45 nice, though also just convert this to a vector an
chebert 2012/08/06 22:43:06 Done.
- if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) {
- if (error) {
- *error = ExtensionErrorUtils::FormatErrorMessage(
- kInvalidURLPatternError, item);
- } else {
- LOG(ERROR) << "Invalid url pattern: " << item;
- }
+ if (!ParseURLPattern(pattern, item, allow_file_access, error))
return false;
- }
- if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) {
- pattern.SetValidSchemes(
- pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
- }
AddPattern(pattern);
}
return true;
}
+
+bool URLPatternSet::ParseURLPattern(URLPattern& pattern,
+ const std::string& item,
+ bool allow_file_access,
+ std::string* error) {
+ if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) {
+ if (error) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ kInvalidURLPatternError, item);
+ } else {
+ LOG(ERROR) << "Invalid url pattern: " << item;
+ }
+ return false;
+ }
+ if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) {
+ pattern.SetValidSchemes(
+ pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
+ }
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698