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 <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const int kValidSchemeMasks[] = { | 36 const int kValidSchemeMasks[] = { |
37 URLPattern::SCHEME_HTTP, | 37 URLPattern::SCHEME_HTTP, |
38 URLPattern::SCHEME_HTTPS, | 38 URLPattern::SCHEME_HTTPS, |
39 URLPattern::SCHEME_FILE, | 39 URLPattern::SCHEME_FILE, |
40 URLPattern::SCHEME_FTP, | 40 URLPattern::SCHEME_FTP, |
41 URLPattern::SCHEME_CHROMEUI, | 41 URLPattern::SCHEME_CHROMEUI, |
42 URLPattern::SCHEME_EXTENSION, | 42 URLPattern::SCHEME_EXTENSION, |
43 URLPattern::SCHEME_FILESYSTEM, | 43 URLPattern::SCHEME_FILESYSTEM, |
44 }; | 44 }; |
45 | 45 |
46 COMPILE_ASSERT(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks), | 46 static_assert(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks), |
47 must_keep_these_arrays_in_sync); | 47 "must keep these arrays in sync"); |
48 | 48 |
49 const char kParseSuccess[] = "Success."; | 49 const char kParseSuccess[] = "Success."; |
50 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; | 50 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; |
51 const char kParseErrorInvalidScheme[] = "Invalid scheme."; | 51 const char kParseErrorInvalidScheme[] = "Invalid scheme."; |
52 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; | 52 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; |
53 const char kParseErrorEmptyHost[] = "Host can not be empty."; | 53 const char kParseErrorEmptyHost[] = "Host can not be empty."; |
54 const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard."; | 54 const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard."; |
55 const char kParseErrorEmptyPath[] = "Empty path."; | 55 const char kParseErrorEmptyPath[] = "Empty path."; |
56 const char kParseErrorInvalidPort[] = "Invalid port."; | 56 const char kParseErrorInvalidPort[] = "Invalid port."; |
57 const char kParseErrorInvalidHost[] = "Invalid host."; | 57 const char kParseErrorInvalidHost[] = "Invalid host."; |
58 | 58 |
59 // Message explaining each URLPattern::ParseResult. | 59 // Message explaining each URLPattern::ParseResult. |
60 const char* const kParseResultMessages[] = { | 60 const char* const kParseResultMessages[] = { |
61 kParseSuccess, | 61 kParseSuccess, |
62 kParseErrorMissingSchemeSeparator, | 62 kParseErrorMissingSchemeSeparator, |
63 kParseErrorInvalidScheme, | 63 kParseErrorInvalidScheme, |
64 kParseErrorWrongSchemeType, | 64 kParseErrorWrongSchemeType, |
65 kParseErrorEmptyHost, | 65 kParseErrorEmptyHost, |
66 kParseErrorInvalidHostWildcard, | 66 kParseErrorInvalidHostWildcard, |
67 kParseErrorEmptyPath, | 67 kParseErrorEmptyPath, |
68 kParseErrorInvalidPort, | 68 kParseErrorInvalidPort, |
69 kParseErrorInvalidHost, | 69 kParseErrorInvalidHost, |
70 }; | 70 }; |
71 | 71 |
72 COMPILE_ASSERT(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages), | 72 static_assert(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages), |
73 must_add_message_for_each_parse_result); | 73 "must add message for each parse result"); |
74 | 74 |
75 const char kPathSeparator[] = "/"; | 75 const char kPathSeparator[] = "/"; |
76 | 76 |
77 bool IsStandardScheme(const std::string& scheme) { | 77 bool IsStandardScheme(const std::string& scheme) { |
78 // "*" gets the same treatment as a standard scheme. | 78 // "*" gets the same treatment as a standard scheme. |
79 if (scheme == "*") | 79 if (scheme == "*") |
80 return true; | 80 return true; |
81 | 81 |
82 return url::IsStandard(scheme.c_str(), | 82 return url::IsStandard(scheme.c_str(), |
83 url::Component(0, static_cast<int>(scheme.length()))); | 83 url::Component(0, static_cast<int>(scheme.length()))); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 605 } |
606 | 606 |
607 return result; | 607 return result; |
608 } | 608 } |
609 | 609 |
610 // static | 610 // static |
611 const char* URLPattern::GetParseResultString( | 611 const char* URLPattern::GetParseResultString( |
612 URLPattern::ParseResult parse_result) { | 612 URLPattern::ParseResult parse_result) { |
613 return kParseResultMessages[parse_result]; | 613 return kParseResultMessages[parse_result]; |
614 } | 614 } |
OLD | NEW |