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

Unified Diff: url/scheme_host_port.cc

Issue 2391383003: Add Origin::CreateFromNormalizedTuple and call from WebSecurityOrigin (Closed)
Patch Set: git cl format Created 4 years, 2 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/scheme_host_port.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/scheme_host_port.cc
diff --git a/url/scheme_host_port.cc b/url/scheme_host_port.cc
index 48cae13a622d0f56d225d815ed236c237ce3d67d..5b359a76aa4508d3783bec421110113482fe68e0 100644
--- a/url/scheme_host_port.cc
+++ b/url/scheme_host_port.cc
@@ -49,7 +49,8 @@ bool IsCanonicalHost(const base::StringPiece& host) {
bool IsValidInput(const base::StringPiece& scheme,
const base::StringPiece& host,
- uint16_t port) {
+ uint16_t port,
+ SchemeHostPort::ConstructPolicy policy) {
SchemeType scheme_type = SCHEME_WITH_PORT;
bool is_standard = GetStandardSchemeType(
scheme.data(),
@@ -72,8 +73,14 @@ bool IsValidInput(const base::StringPiece& scheme,
if (host.empty() || port == 0)
return false;
- if (!IsCanonicalHost(host))
+ // Don't do an expensive canonicalization if the host is already
+ // canonicalized.
+ DCHECK(policy == SchemeHostPort::CHECK_CANONICALIZATION ||
+ IsCanonicalHost(host));
+ if (policy == SchemeHostPort::CHECK_CANONICALIZATION &&
+ !IsCanonicalHost(host)) {
return false;
+ }
return true;
@@ -84,8 +91,14 @@ bool IsValidInput(const base::StringPiece& scheme,
return false;
}
- if (!IsCanonicalHost(host))
+ // Don't do an expensive canonicalization if the host is already
+ // canonicalized.
+ DCHECK(policy == SchemeHostPort::CHECK_CANONICALIZATION ||
+ IsCanonicalHost(host));
+ if (policy == SchemeHostPort::CHECK_CANONICALIZATION &&
+ !IsCanonicalHost(host)) {
return false;
+ }
return true;
@@ -105,9 +118,10 @@ SchemeHostPort::SchemeHostPort() : port_(0) {
SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
base::StringPiece host,
- uint16_t port)
+ uint16_t port,
+ ConstructPolicy policy)
: port_(0) {
- if (!IsValidInput(scheme, host, port))
+ if (!IsValidInput(scheme, host, port, policy))
return;
scheme.CopyToString(&scheme_);
@@ -115,6 +129,14 @@ SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
port_ = port;
}
+SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
+ base::StringPiece host,
+ uint16_t port)
+ : SchemeHostPort(scheme,
+ host,
+ port,
+ ConstructPolicy::CHECK_CANONICALIZATION) {}
+
SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) {
if (!url.is_valid())
return;
@@ -127,7 +149,7 @@ SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) {
if (port == PORT_UNSPECIFIED)
port = 0;
- if (!IsValidInput(scheme, host, port))
+ if (!IsValidInput(scheme, host, port, ALREADY_CANONICALIZED))
return;
scheme.CopyToString(&scheme_);
« no previous file with comments | « url/scheme_host_port.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698