Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: url/url_util.cc

Issue 1272113002: Allow url::SchemeHostPort to hold non-file scheme without port (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/url_util.cc
diff --git a/url/url_util.cc b/url/url_util.cc
index 279ab7e24b1f5203c4b63f812fa3d395d7371c2a..21bf3cc462ef871470302bc00ca2c033ec70c748 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -19,21 +19,24 @@ 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},
+ // Yes, file URLs can have a hostname, so file URLs should be handled as
+ // "standard". File URLs never have a port as specified by the SchemeType
+ // field.
+ {kFileScheme, SCHEME_WITHOUT_PORT},
+ {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 +57,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 +76,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 +91,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 +164,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 +177,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,
@@ -217,9 +226,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;
@@ -340,7 +350,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);
}
@@ -365,7 +376,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).
@@ -388,7 +400,10 @@ void AddStandardScheme(const char* new_scheme) {
memcpy(dup_scheme, new_scheme, scheme_len + 1);
InitStandardSchemes();
- standard_schemes->push_back(dup_scheme);
+ SchemeWithType scheme_with_type;
+ scheme_with_type.scheme = dup_scheme;
+ scheme_with_type.type = type;
+ standard_schemes->push_back(scheme_with_type);
}
void LockStandardSchemes() {
@@ -396,11 +411,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,
« no previous file with comments | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698