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 "extensions/common/url_pattern.h" | 5 #include "extensions/common/url_pattern.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <ostream> | 9 #include <ostream> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/pattern.h" | 12 #include "base/strings/pattern.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_piece.h" | |
15 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
18 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
19 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
22 #include "url/url_util.h" | 21 #include "url/url_util.h" |
23 | 22 |
24 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; | 23 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 239 |
241 if (host_end_pos == base::StringPiece::npos) | 240 if (host_end_pos == base::StringPiece::npos) |
242 return PARSE_ERROR_EMPTY_PATH; | 241 return PARSE_ERROR_EMPTY_PATH; |
243 | 242 |
244 // TODO(devlin): This whole series is expensive. Luckily we don't do it | 243 // TODO(devlin): This whole series is expensive. Luckily we don't do it |
245 // *too* often, but it could be optimized. | 244 // *too* often, but it could be optimized. |
246 pattern.substr(host_start_pos, host_end_pos - host_start_pos) | 245 pattern.substr(host_start_pos, host_end_pos - host_start_pos) |
247 .CopyToString(&host_); | 246 .CopyToString(&host_); |
248 | 247 |
249 // The first component can optionally be '*' to match all subdomains. | 248 // The first component can optionally be '*' to match all subdomains. |
250 std::vector<std::string> host_components = base::SplitString( | 249 std::vector<base::StringPiece> host_components = base::SplitStringPiece( |
251 host_, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 250 host_, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
252 | 251 |
253 // Could be empty if the host only consists of whitespace characters. | 252 // Could be empty if the host only consists of whitespace characters. |
254 if (host_components.empty() || | 253 if (host_components.empty() || |
255 (host_components.size() == 1 && host_components[0].empty())) | 254 (host_components.size() == 1 && host_components[0].empty())) |
256 return PARSE_ERROR_EMPTY_HOST; | 255 return PARSE_ERROR_EMPTY_HOST; |
257 | 256 |
258 if (host_components[0] == "*") { | 257 if (host_components[0] == "*") { |
259 match_subdomains_ = true; | 258 match_subdomains_ = true; |
260 host_components.erase(host_components.begin(), | 259 host_components.erase(host_components.begin(), |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 } | 622 } |
624 | 623 |
625 return result; | 624 return result; |
626 } | 625 } |
627 | 626 |
628 // static | 627 // static |
629 const char* URLPattern::GetParseResultString( | 628 const char* URLPattern::GetParseResultString( |
630 URLPattern::ParseResult parse_result) { | 629 URLPattern::ParseResult parse_result) { |
631 return kParseResultMessages[parse_result]; | 630 return kParseResultMessages[parse_result]; |
632 } | 631 } |
OLD | NEW |