OLD | NEW |
---|---|
1 // Copyright (c) 2011 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_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 bool URLPattern::operator==(const URLPattern& other) const { | 131 bool URLPattern::operator==(const URLPattern& other) const { |
132 return GetAsString() == other.GetAsString(); | 132 return GetAsString() == other.GetAsString(); |
133 } | 133 } |
134 | 134 |
135 URLPattern::ParseResult URLPattern::Parse(const std::string& pattern, | 135 URLPattern::ParseResult URLPattern::Parse(const std::string& pattern, |
136 ParseOption strictness) { | 136 ParseOption strictness) { |
137 spec_.clear(); | 137 spec_.clear(); |
138 | 138 |
139 // Special case pattern to match every valid URL. | 139 // Special case pattern to match every valid URL. |
140 if (pattern == kAllUrlsPattern) { | 140 if (pattern == kAllUrlsPattern) { |
141 match_all_urls_ = true; | 141 SetMatchAllURLs(true); |
142 match_subdomains_ = true; | |
143 scheme_ = "*"; | |
144 host_.clear(); | |
145 SetPath("/*"); | |
146 return PARSE_SUCCESS; | 142 return PARSE_SUCCESS; |
147 } | 143 } |
148 | 144 |
149 // Parse out the scheme. | 145 // Parse out the scheme. |
150 size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator); | 146 size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator); |
151 bool has_standard_scheme_separator = true; | 147 bool has_standard_scheme_separator = true; |
152 | 148 |
153 // Some urls also use ':' alone as the scheme separator. | 149 // Some urls also use ':' alone as the scheme separator. |
154 if (scheme_end_pos == std::string::npos) { | 150 if (scheme_end_pos == std::string::npos) { |
155 scheme_end_pos = pattern.find(':'); | 151 scheme_end_pos = pattern.find(':'); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } | 246 } |
251 | 247 |
252 void URLPattern::SetHost(const std::string& host) { | 248 void URLPattern::SetHost(const std::string& host) { |
253 spec_.clear(); | 249 spec_.clear(); |
254 host_ = host; | 250 host_ = host; |
255 } | 251 } |
256 | 252 |
257 void URLPattern::SetMatchAllURLs(bool val) { | 253 void URLPattern::SetMatchAllURLs(bool val) { |
258 spec_.clear(); | 254 spec_.clear(); |
259 match_all_urls_ = val; | 255 match_all_urls_ = val; |
256 | |
257 if (val) { | |
258 match_subdomains_ = true; | |
259 scheme_ = "*"; | |
260 host_.clear(); | |
261 SetPath("/*"); | |
262 } | |
260 } | 263 } |
jstritar
2011/10/10 20:23:24
This was the real bug- the <all_urls> URLPatterns
Matt Perry
2011/10/10 23:22:39
Hmm.. I think the real bug is that the caller didn
jstritar
2011/10/11 15:13:38
Ah, I see... you're supposed to always call Parse.
| |
261 | 264 |
262 void URLPattern::SetMatchSubdomains(bool val) { | 265 void URLPattern::SetMatchSubdomains(bool val) { |
263 spec_.clear(); | 266 spec_.clear(); |
264 match_subdomains_ = val; | 267 match_subdomains_ = val; |
265 } | 268 } |
266 | 269 |
267 bool URLPattern::SetScheme(const std::string& scheme) { | 270 bool URLPattern::SetScheme(const std::string& scheme) { |
268 spec_.clear(); | 271 spec_.clear(); |
269 scheme_ = scheme; | 272 scheme_ = scheme; |
270 if (scheme_ == "*") { | 273 if (scheme_ == "*") { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 } | 493 } |
491 | 494 |
492 return result; | 495 return result; |
493 } | 496 } |
494 | 497 |
495 // static | 498 // static |
496 const char* URLPattern::GetParseResultString( | 499 const char* URLPattern::GetParseResultString( |
497 URLPattern::ParseResult parse_result) { | 500 URLPattern::ParseResult parse_result) { |
498 return kParseResultMessages[parse_result]; | 501 return kParseResultMessages[parse_result]; |
499 } | 502 } |
OLD | NEW |