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

Unified Diff: url/scheme_host_port.cc

Issue 2391383003: Add Origin::CreateFromNormalizedTuple and call from WebSecurityOrigin (Closed)
Patch Set: loosen checks 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
« url/origin.cc ('K') | « 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 b9599865dd9f4e58ef7ffc63802efbad0aa313f4..94da494cff44ef8ddd0f2d0ec02a295122d41e37 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,
+ bool is_canonicalized) {
SchemeType scheme_type = SCHEME_WITH_PORT;
bool is_standard = GetStandardSchemeType(
scheme.data(),
@@ -72,7 +73,10 @@ 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(!is_canonicalized || IsCanonicalHost(host));
+ if (!is_canonicalized && !IsCanonicalHost(host))
return false;
return true;
@@ -84,7 +88,10 @@ bool IsValidInput(const base::StringPiece& scheme,
return false;
}
- if (!IsCanonicalHost(host))
+ // Don't do an expensive canonicalization if the host is already
+ // canonicalized.
+ DCHECK(!is_canonicalized || IsCanonicalHost(host));
+ if (!is_canonicalized && !IsCanonicalHost(host))
return false;
return true;
@@ -105,9 +112,10 @@ SchemeHostPort::SchemeHostPort() : port_(0) {
SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
base::StringPiece host,
- uint16_t port)
+ uint16_t port,
+ bool is_canonicalized)
: port_(0) {
- if (!IsValidInput(scheme, host, port))
+ if (!IsValidInput(scheme, host, port, is_canonicalized))
return;
scheme.CopyToString(&scheme_);
@@ -115,6 +123,11 @@ SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
port_ = port;
}
+SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
+ base::StringPiece host,
+ uint16_t port)
+ : SchemeHostPort(scheme, host, port, false /* is_canonicalized */) {}
+
SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) {
if (!url.is_valid())
return;
@@ -127,7 +140,7 @@ SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) {
if (port == PORT_UNSPECIFIED)
port = 0;
- if (!IsValidInput(scheme, host, port))
+ if (!IsValidInput(scheme, host, port, true /* is_canonicalized */))
return;
scheme.CopyToString(&scheme_);
« url/origin.cc ('K') | « url/scheme_host_port.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698