| 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/url_pattern_set.h" | 5 #include "extensions/common/url_pattern_set.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/common/extensions/extension_error_utils.h" | |
| 14 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "extensions/common/extension_error_utils.h" |
| 15 #include "extensions/common/url_pattern.h" | 15 #include "extensions/common/url_pattern.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 namespace extensions { |
| 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; | 22 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; |
| 21 | 23 |
| 22 } // namespace | 24 } // namespace |
| 23 | 25 |
| 24 // static | 26 // static |
| 25 void URLPatternSet::CreateDifference(const URLPatternSet& set1, | 27 void URLPatternSet::CreateDifference(const URLPatternSet& set1, |
| 26 const URLPatternSet& set2, | 28 const URLPatternSet& set2, |
| 27 URLPatternSet* out) { | 29 URLPatternSet* out) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 179 |
| 178 bool URLPatternSet::Populate(const std::vector<std::string>& patterns, | 180 bool URLPatternSet::Populate(const std::vector<std::string>& patterns, |
| 179 int valid_schemes, | 181 int valid_schemes, |
| 180 bool allow_file_access, | 182 bool allow_file_access, |
| 181 std::string* error) { | 183 std::string* error) { |
| 182 ClearPatterns(); | 184 ClearPatterns(); |
| 183 for (size_t i = 0; i < patterns.size(); ++i) { | 185 for (size_t i = 0; i < patterns.size(); ++i) { |
| 184 URLPattern pattern(valid_schemes); | 186 URLPattern pattern(valid_schemes); |
| 185 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { | 187 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { |
| 186 if (error) { | 188 if (error) { |
| 187 *error = ExtensionErrorUtils::FormatErrorMessage( | 189 *error = ErrorUtils::FormatErrorMessage(kInvalidURLPatternError, |
| 188 kInvalidURLPatternError, patterns[i]); | 190 patterns[i]); |
| 189 } else { | 191 } else { |
| 190 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; | 192 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; |
| 191 } | 193 } |
| 192 return false; | 194 return false; |
| 193 } | 195 } |
| 194 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | 196 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { |
| 195 pattern.SetValidSchemes( | 197 pattern.SetValidSchemes( |
| 196 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 198 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 197 } | 199 } |
| 198 AddPattern(pattern); | 200 AddPattern(pattern); |
| 199 } | 201 } |
| 200 return true; | 202 return true; |
| 201 } | 203 } |
| 202 | 204 |
| 203 bool URLPatternSet::Populate(const base::ListValue& value, | 205 bool URLPatternSet::Populate(const base::ListValue& value, |
| 204 int valid_schemes, | 206 int valid_schemes, |
| 205 bool allow_file_access, | 207 bool allow_file_access, |
| 206 std::string* error) { | 208 std::string* error) { |
| 207 std::vector<std::string> patterns; | 209 std::vector<std::string> patterns; |
| 208 for (size_t i = 0; i < value.GetSize(); ++i) { | 210 for (size_t i = 0; i < value.GetSize(); ++i) { |
| 209 std::string item; | 211 std::string item; |
| 210 if (!value.GetString(i, &item)) | 212 if (!value.GetString(i, &item)) |
| 211 return false; | 213 return false; |
| 212 patterns.push_back(item); | 214 patterns.push_back(item); |
| 213 } | 215 } |
| 214 return Populate(patterns, valid_schemes, allow_file_access, error); | 216 return Populate(patterns, valid_schemes, allow_file_access, error); |
| 215 } | 217 } |
| 218 |
| 219 } // namespace extensions |
| OLD | NEW |