Commit 41d010e8 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

KURL::Port(): Remove unneeded constants

Remove the constants kMaximumValidPortNumber and kInvalidPortNumber from
kurl.cc as they are confusing and don't actually do anything.

Also change remaining CHECKs in KURL::Port back to DCHECKs now that we
have confidence the change is safe.

Also make the method comment less confusing.

BUG=606462

Change-Id: I4719b8611cc6f3f0c5f488d8c86f3b6b8ad6d88f
Reviewed-on: https://chromium-review.googlesource.com/1127083
Commit-Queue: Adam Rice <ricea@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575942}
parent 984b8a71
...@@ -45,9 +45,6 @@ ...@@ -45,9 +45,6 @@
namespace blink { namespace blink {
static const int kMaximumValidPortNumber = 0xFFFE;
static const int kInvalidPortNumber = 0xFFFF;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
static void AssertProtocolIsGood(const StringView protocol) { static void AssertProtocolIsGood(const StringView protocol) {
DCHECK(protocol != ""); DCHECK(protocol != "");
...@@ -359,26 +356,15 @@ String KURL::Host() const { ...@@ -359,26 +356,15 @@ String KURL::Host() const {
return ComponentString(parsed_.host); return ComponentString(parsed_.host);
} }
// Returns 0 when there is no port.
//
// We treat URL's with out-of-range port numbers as invalid URLs, and they will
// be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but
// return invalidPortNumber from this port() function, so we mirror that
// behavior here.
unsigned short KURL::Port() const { unsigned short KURL::Port() const {
if (!is_valid_ || parsed_.port.len <= 0) if (!is_valid_ || parsed_.port.len <= 0)
return 0; return 0;
// TODO(ricea): Change this back to DCHECK. DCHECK(!string_.IsNull());
CHECK(!string_.IsNull());
int port = string_.Is8Bit() int port = string_.Is8Bit()
? url::ParsePort(AsURLChar8Subtle(string_), parsed_.port) ? url::ParsePort(AsURLChar8Subtle(string_), parsed_.port)
: url::ParsePort(string_.Characters16(), parsed_.port); : url::ParsePort(string_.Characters16(), parsed_.port);
// TODO(ricea): Change these two to DCHECK. DCHECK_NE(port, url::PORT_UNSPECIFIED); // Checked port.len <= 0 already.
CHECK_NE(port, url::PORT_UNSPECIFIED); // Checked port.len <= 0 already. DCHECK_NE(port, url::PORT_INVALID); // Checked is_valid_ already.
CHECK_NE(port, url::PORT_INVALID); // Checked is_valid_ already.
// TODO(ricea): Remove this CHECK and the constants it uses.
CHECK(port <= kMaximumValidPortNumber || port == kInvalidPortNumber);
return static_cast<unsigned short>(port); return static_cast<unsigned short>(port);
} }
......
...@@ -147,6 +147,12 @@ class PLATFORM_EXPORT KURL { ...@@ -147,6 +147,12 @@ class PLATFORM_EXPORT KURL {
String Protocol() const; String Protocol() const;
String Host() const; String Host() const;
// Returns 0 when there is no port or the default port was specified, or the
// URL is invalid.
//
// We treat URLs with out-of-range port numbers as invalid URLs, and they
// will be rejected by the canonicalizer.
unsigned short Port() const; unsigned short Port() const;
bool HasPort() const; bool HasPort() const;
String User() const; String User() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment