| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "googleurl/src/gurl.h" |
| 10 | 11 |
| 11 // TODO(aa): Consider adding chrome-extension? What about more obscure ones | 12 // TODO(aa): Consider adding chrome-extension? What about more obscure ones |
| 12 // like data: and javascript: ? | 13 // like data: and javascript: ? |
| 13 // Note: keep this array in sync with kValidSchemeMasks. | 14 // Note: keep this array in sync with kValidSchemeMasks. |
| 14 static const char* kValidSchemes[] = { | 15 static const char* kValidSchemes[] = { |
| 15 chrome::kHttpScheme, | 16 chrome::kHttpScheme, |
| 16 chrome::kHttpsScheme, | 17 chrome::kHttpsScheme, |
| 17 chrome::kFileScheme, | 18 chrome::kFileScheme, |
| 18 chrome::kFtpScheme, | 19 chrome::kFtpScheme, |
| 19 chrome::kChromeUIScheme, | 20 chrome::kChromeUIScheme, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 41 : valid_schemes_(valid_schemes), match_all_urls_(false), | 42 : valid_schemes_(valid_schemes), match_all_urls_(false), |
| 42 match_subdomains_(false) {} | 43 match_subdomains_(false) {} |
| 43 | 44 |
| 44 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) | 45 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) |
| 45 : valid_schemes_(valid_schemes), match_all_urls_(false), | 46 : valid_schemes_(valid_schemes), match_all_urls_(false), |
| 46 match_subdomains_(false) { | 47 match_subdomains_(false) { |
| 47 if (!Parse(pattern)) | 48 if (!Parse(pattern)) |
| 48 NOTREACHED() << "URLPattern is invalid: " << pattern; | 49 NOTREACHED() << "URLPattern is invalid: " << pattern; |
| 49 } | 50 } |
| 50 | 51 |
| 52 URLPattern::~URLPattern() { |
| 53 } |
| 54 |
| 51 bool URLPattern::Parse(const std::string& pattern) { | 55 bool URLPattern::Parse(const std::string& pattern) { |
| 52 // Special case pattern to match every valid URL. | 56 // Special case pattern to match every valid URL. |
| 53 if (pattern == kAllUrlsPattern) { | 57 if (pattern == kAllUrlsPattern) { |
| 54 match_all_urls_ = true; | 58 match_all_urls_ = true; |
| 55 match_subdomains_ = true; | 59 match_subdomains_ = true; |
| 56 scheme_ = "*"; | 60 scheme_ = "*"; |
| 57 host_.clear(); | 61 host_.clear(); |
| 58 path_ = "/*"; | 62 path_ = "/*"; |
| 59 return true; | 63 return true; |
| 60 } | 64 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 if (MatchesScheme(kValidSchemes[i])) { | 261 if (MatchesScheme(kValidSchemes[i])) { |
| 258 URLPattern temp = *this; | 262 URLPattern temp = *this; |
| 259 temp.SetScheme(kValidSchemes[i]); | 263 temp.SetScheme(kValidSchemes[i]); |
| 260 temp.set_match_all_urls(false); | 264 temp.set_match_all_urls(false); |
| 261 result.push_back(temp); | 265 result.push_back(temp); |
| 262 } | 266 } |
| 263 } | 267 } |
| 264 | 268 |
| 265 return result; | 269 return result; |
| 266 } | 270 } |
| OLD | NEW |