OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/common/extensions/url_pattern.h" |
6 | 6 |
7 #include "base/string_piece.h" | 7 #include "base/string_piece.h" |
8 #include "base/string_split.h" | 8 #include "base/string_split.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 if (!MatchesHost(test)) | 223 if (!MatchesHost(test)) |
224 return false; | 224 return false; |
225 | 225 |
226 if (!MatchesPath(test.PathForRequest())) | 226 if (!MatchesPath(test.PathForRequest())) |
227 return false; | 227 return false; |
228 | 228 |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
232 bool URLPattern::MatchesScheme(const std::string& test) const { | 232 bool URLPattern::MatchesScheme(const std::string& test) const { |
233 if (scheme_ == "*") | 233 if (!IsValidScheme(test)) |
234 return IsValidScheme(test); | 234 return false; |
235 | 235 |
236 return test == scheme_; | 236 return scheme_ == "*" || test == scheme_; |
237 } | 237 } |
238 | 238 |
239 bool URLPattern::MatchesHost(const std::string& host) const { | 239 bool URLPattern::MatchesHost(const std::string& host) const { |
240 std::string test(chrome::kHttpScheme); | 240 std::string test(chrome::kHttpScheme); |
241 test += chrome::kStandardSchemeSeparator; | 241 test += chrome::kStandardSchemeSeparator; |
242 test += host; | 242 test += host; |
243 test += "/"; | 243 test += "/"; |
244 return MatchesHost(GURL(test)); | 244 return MatchesHost(GURL(test)); |
245 } | 245 } |
246 | 246 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && | 326 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && |
327 !other.MatchesPath(path_.substr(0, path_.size() - 1))) | 327 !other.MatchesPath(path_.substr(0, path_.size() - 1))) |
328 return false; | 328 return false; |
329 | 329 |
330 return true; | 330 return true; |
331 } | 331 } |
332 | 332 |
333 std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const { | 333 std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const { |
334 std::vector<URLPattern> result; | 334 std::vector<URLPattern> result; |
335 | 335 |
336 if (scheme_ != "*" && !match_all_urls_) { | 336 if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) { |
337 result.push_back(*this); | 337 result.push_back(*this); |
338 return result; | 338 return result; |
339 } | 339 } |
340 | 340 |
341 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { | 341 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { |
342 if (MatchesScheme(kValidSchemes[i])) { | 342 if (MatchesScheme(kValidSchemes[i])) { |
343 URLPattern temp = *this; | 343 URLPattern temp = *this; |
344 temp.SetScheme(kValidSchemes[i]); | 344 temp.SetScheme(kValidSchemes[i]); |
345 temp.set_match_all_urls(false); | 345 temp.set_match_all_urls(false); |
346 result.push_back(temp); | 346 result.push_back(temp); |
347 } | 347 } |
348 } | 348 } |
349 | 349 |
350 return result; | 350 return result; |
351 } | 351 } |
352 | 352 |
353 // static | 353 // static |
354 const char* URLPattern::GetParseResultString( | 354 const char* URLPattern::GetParseResultString( |
355 URLPattern::ParseResult parse_result) { | 355 URLPattern::ParseResult parse_result) { |
356 return kParseResultMessages[parse_result]; | 356 return kParseResultMessages[parse_result]; |
357 } | 357 } |
OLD | NEW |