Chromium Code Reviews| 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; |
| +} |