Index: url/url_util.cc |
diff --git a/url/url_util.cc b/url/url_util.cc |
index 5a19390b2199515dd7b84f2deac56cea36c61d99..2ef8592e42eb59571e0e565b2ec2965d16282869 100644 |
--- a/url/url_util.cc |
+++ b/url/url_util.cc |
@@ -19,21 +19,21 @@ namespace url { |
namespace { |
const int kNumStandardURLSchemes = 8; |
-const char* kStandardURLSchemes[kNumStandardURLSchemes] = { |
- kHttpScheme, |
- kHttpsScheme, |
- kFileScheme, // Yes, file urls can have a hostname! |
- kFtpScheme, |
- kGopherScheme, |
- kWsScheme, // WebSocket. |
- kWssScheme, // WebSocket secure. |
- kFileSystemScheme, |
+const SchemeWithType kStandardURLSchemes[kNumStandardURLSchemes] = { |
+ {kHttpScheme, SCHEME_WITH_PORT}, |
+ {kHttpsScheme, SCHEME_WITH_PORT}, |
+ {kFileScheme, SCHEME_WITHOUT_PORT}, // Yes, file urls can have a hostname! |
Ryan Sleevi
2015/08/13 22:32:12
nit: It took me a while to find out why this is 't
tyoshino (SeeGerritForStatus)
2015/08/14 06:29:01
Ya. At least we won't break anything new, I think.
|
+ {kFtpScheme, SCHEME_WITH_PORT}, |
+ {kGopherScheme, SCHEME_WITH_PORT}, |
+ {kWsScheme, SCHEME_WITH_PORT}, // WebSocket. |
+ {kWssScheme, SCHEME_WITH_PORT}, // WebSocket secure. |
+ {kFileSystemScheme, SCHEME_WITHOUT_AUTHORITY}, |
}; |
// List of the currently installed standard schemes. This list is lazily |
// initialized by InitStandardSchemes and is leaked on shutdown to prevent |
// any destructors from being called that will slow us down or cause problems. |
-std::vector<const char*>* standard_schemes = NULL; |
+std::vector<SchemeWithType>* standard_schemes = NULL; |
// See the LockStandardSchemes declaration in the header. |
bool standard_schemes_locked = false; |
@@ -54,7 +54,7 @@ template<> struct CharToStringPiece<base::char16> { |
void InitStandardSchemes() { |
if (standard_schemes) |
return; |
- standard_schemes = new std::vector<const char*>; |
+ standard_schemes = new std::vector<SchemeWithType>; |
for (int i = 0; i < kNumStandardURLSchemes; i++) |
standard_schemes->push_back(kStandardURLSchemes[i]); |
} |
@@ -73,10 +73,13 @@ inline bool DoCompareSchemeComponent(const CHAR* spec, |
compare_to); |
} |
-// Returns true if the given scheme identified by |scheme| within |spec| is one |
-// of the registered "standard" schemes. |
+// Returns true and sets |type| to the SchemeType of the given scheme |
+// identified by |scheme| within |spec| if the scheme is one of the registered |
+// "standard" schemes. |
template<typename CHAR> |
-bool DoIsStandard(const CHAR* spec, const Component& scheme) { |
+bool DoIsStandard(const CHAR* spec, |
+ const Component& scheme, |
+ SchemeType* type) { |
if (!scheme.is_nonempty()) |
return false; // Empty or invalid schemes are non-standard. |
@@ -85,8 +88,10 @@ bool DoIsStandard(const CHAR* spec, const Component& scheme) { |
if (base::LowerCaseEqualsASCII( |
typename CharToStringPiece<CHAR>::Piece( |
&spec[scheme.begin], scheme.len), |
- standard_schemes->at(i))) |
+ standard_schemes->at(i).scheme)) { |
+ *type = standard_schemes->at(i).type; |
return true; |
+ } |
} |
return false; |
} |
@@ -156,6 +161,7 @@ bool DoCanonicalize(const CHAR* in_spec, |
// This is the parsed version of the input URL, we have to canonicalize it |
// before storing it in our object. |
bool success; |
+ SchemeType unused_scheme_type = SCHEME_WITH_PORT; |
if (DoCompareSchemeComponent(spec, scheme, url::kFileScheme)) { |
// File URLs are special. |
ParseFileURL(spec, spec_len, &parsed_input); |
@@ -168,7 +174,7 @@ bool DoCanonicalize(const CHAR* in_spec, |
charset_converter, output, |
output_parsed); |
- } else if (DoIsStandard(spec, scheme)) { |
+ } else if (DoIsStandard(spec, scheme, &unused_scheme_type)) { |
// All "normal" URLs. |
ParseStandardURL(spec, spec_len, &parsed_input); |
success = CanonicalizeStandardURL(spec, spec_len, parsed_input, |
@@ -216,9 +222,10 @@ bool DoResolveRelative(const char* base_spec, |
base_is_hierarchical = num_slashes > 0; |
} |
+ SchemeType unused_scheme_type = SCHEME_WITH_PORT; |
bool standard_base_scheme = |
base_parsed.scheme.is_nonempty() && |
- DoIsStandard(base_spec, base_parsed.scheme); |
+ DoIsStandard(base_spec, base_parsed.scheme, &unused_scheme_type); |
bool is_relative; |
Component relative_component; |
@@ -339,7 +346,8 @@ bool DoReplaceComponents(const char* spec, |
return ReplaceFileSystemURL(spec, parsed, replacements, charset_converter, |
output, out_parsed); |
} |
- if (DoIsStandard(spec, parsed.scheme)) { |
+ SchemeType unused_scheme_type = SCHEME_WITH_PORT; |
+ if (DoIsStandard(spec, parsed.scheme, &unused_scheme_type)) { |
return ReplaceStandardURL(spec, parsed, replacements, charset_converter, |
output, out_parsed); |
} |
@@ -364,7 +372,8 @@ void Shutdown() { |
} |
} |
-void AddStandardScheme(const char* new_scheme) { |
+void AddStandardScheme(const char* new_scheme, |
+ SchemeType type) { |
// If this assert triggers, it means you've called AddStandardScheme after |
// LockStandardSchemes have been called (see the header file for |
// LockStandardSchemes for more). |
@@ -387,7 +396,7 @@ void AddStandardScheme(const char* new_scheme) { |
memcpy(dup_scheme, new_scheme, scheme_len + 1); |
InitStandardSchemes(); |
- standard_schemes->push_back(dup_scheme); |
+ standard_schemes->push_back(SchemeWithType(dup_scheme, type)); |
} |
void LockStandardSchemes() { |
@@ -395,11 +404,19 @@ void LockStandardSchemes() { |
} |
bool IsStandard(const char* spec, const Component& scheme) { |
- return DoIsStandard(spec, scheme); |
+ SchemeType unused_scheme_type; |
+ return DoIsStandard(spec, scheme, &unused_scheme_type); |
+} |
+ |
+bool GetStandardSchemeType(const char* spec, |
+ const Component& scheme, |
+ SchemeType* type) { |
+ return DoIsStandard(spec, scheme, type); |
} |
bool IsStandard(const base::char16* spec, const Component& scheme) { |
- return DoIsStandard(spec, scheme); |
+ SchemeType unused_scheme_type; |
+ return DoIsStandard(spec, scheme, &unused_scheme_type); |
} |
bool FindAndCompareScheme(const char* str, |