Commit 7ae68cab authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Refactor: unsigned short/int -> uint16_t in third_party/blink/renderer/platform/weborigin

- unsigned short/int -> uint16_t.
- No logic changes.
- Reference: https://google.github.io/styleguide/cppguide.html#Integer_Types

Bug: 929986
Change-Id: I82c389e5865267daef3bbf25c5098aa584e17c76
Reviewed-on: https://chromium-review.googlesource.com/c/1488481Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635474}
parent 0e284dfa
...@@ -70,12 +70,12 @@ class WebSecurityOrigin { ...@@ -70,12 +70,12 @@ class WebSecurityOrigin {
BLINK_PLATFORM_EXPORT WebString Protocol() const; BLINK_PLATFORM_EXPORT WebString Protocol() const;
BLINK_PLATFORM_EXPORT WebString Host() const; BLINK_PLATFORM_EXPORT WebString Host() const;
BLINK_PLATFORM_EXPORT unsigned short Port() const; BLINK_PLATFORM_EXPORT uint16_t Port() const;
// |Port()| will return 0 if the port is the default for an origin. This // |Port()| will return 0 if the port is the default for an origin. This
// method instead returns the effective port, even if it is the default port // method instead returns the effective port, even if it is the default port
// (e.g. "http" => 80). // (e.g. "http" => 80).
BLINK_PLATFORM_EXPORT unsigned short EffectivePort() const; BLINK_PLATFORM_EXPORT uint16_t EffectivePort() const;
// A unique WebSecurityOrigin is the least privileged WebSecurityOrigin. // A unique WebSecurityOrigin is the least privileged WebSecurityOrigin.
BLINK_PLATFORM_EXPORT bool IsOpaque() const; BLINK_PLATFORM_EXPORT bool IsOpaque() const;
......
...@@ -67,12 +67,12 @@ WebString WebSecurityOrigin::Host() const { ...@@ -67,12 +67,12 @@ WebString WebSecurityOrigin::Host() const {
return private_->Host(); return private_->Host();
} }
unsigned short WebSecurityOrigin::Port() const { uint16_t WebSecurityOrigin::Port() const {
DCHECK(private_); DCHECK(private_);
return private_->Port(); return private_->Port();
} }
unsigned short WebSecurityOrigin::EffectivePort() const { uint16_t WebSecurityOrigin::EffectivePort() const {
DCHECK(private_); DCHECK(private_);
return private_->EffectivePort(); return private_->EffectivePort();
} }
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
namespace blink { namespace blink {
bool IsDefaultPortForProtocol(unsigned short port, bool IsDefaultPortForProtocol(uint16_t port, const WTF::String& protocol) {
const WTF::String& protocol) {
if (protocol.IsEmpty()) if (protocol.IsEmpty())
return false; return false;
...@@ -53,7 +52,7 @@ bool IsDefaultPortForProtocol(unsigned short port, ...@@ -53,7 +52,7 @@ bool IsDefaultPortForProtocol(unsigned short port,
return false; return false;
} }
unsigned short DefaultPortForProtocol(const WTF::String& protocol) { uint16_t DefaultPortForProtocol(const WTF::String& protocol) {
if (protocol == "http" || protocol == "ws") if (protocol == "http" || protocol == "ws")
return 80; return 80;
if (protocol == "https" || protocol == "wss") if (protocol == "https" || protocol == "wss")
...@@ -76,7 +75,7 @@ bool IsPortAllowedForScheme(const KURL& url) { ...@@ -76,7 +75,7 @@ bool IsPortAllowedForScheme(const KURL& url) {
String protocol = url.Protocol(); String protocol = url.Protocol();
if (protocol.IsNull()) if (protocol.IsNull())
protocol = g_empty_string; protocol = g_empty_string;
unsigned short effective_port = url.Port(); uint16_t effective_port = url.Port();
if (!effective_port) if (!effective_port)
effective_port = DefaultPortForProtocol(protocol); effective_port = DefaultPortForProtocol(protocol);
StringUTF8Adaptor utf8(protocol); StringUTF8Adaptor utf8(protocol);
......
...@@ -36,12 +36,11 @@ class KURL; ...@@ -36,12 +36,11 @@ class KURL;
// Returns true if |port| is known to be the default for |protocol|. |protocol| // Returns true if |port| is known to be the default for |protocol|. |protocol|
// must be lower case. // must be lower case.
PLATFORM_EXPORT bool IsDefaultPortForProtocol(unsigned short port, PLATFORM_EXPORT bool IsDefaultPortForProtocol(uint16_t port,
const WTF::String& protocol); const WTF::String& protocol);
// Returns 0 for unknown protocols. |protocol| must be lower case. // Returns 0 for unknown protocols. |protocol| must be lower case.
PLATFORM_EXPORT unsigned short DefaultPortForProtocol( PLATFORM_EXPORT uint16_t DefaultPortForProtocol(const WTF::String& protocol);
const WTF::String& protocol);
// Returns true if the port of the |url| is allowed for the scheme of the |url|. // Returns true if the port of the |url| is allowed for the scheme of the |url|.
PLATFORM_EXPORT bool IsPortAllowedForScheme(const KURL&); PLATFORM_EXPORT bool IsPortAllowedForScheme(const KURL&);
......
...@@ -11,7 +11,7 @@ namespace blink { ...@@ -11,7 +11,7 @@ namespace blink {
TEST(KnownPortsTest, IsDefaultPortForProtocol) { TEST(KnownPortsTest, IsDefaultPortForProtocol) {
struct TestCase { struct TestCase {
const unsigned short port; const uint16_t port;
const char* protocol; const char* protocol;
const bool is_known; const bool is_known;
} inputs[] = { } inputs[] = {
...@@ -43,7 +43,7 @@ TEST(KnownPortsTest, IsDefaultPortForProtocol) { ...@@ -43,7 +43,7 @@ TEST(KnownPortsTest, IsDefaultPortForProtocol) {
TEST(KnownPortsTest, DefaultPortForProtocol) { TEST(KnownPortsTest, DefaultPortForProtocol) {
struct TestCase { struct TestCase {
const unsigned short port; const uint16_t port;
const char* protocol; const char* protocol;
} inputs[] = { } inputs[] = {
// Known ones. // Known ones.
......
...@@ -356,7 +356,7 @@ String KURL::Host() const { ...@@ -356,7 +356,7 @@ String KURL::Host() const {
return ComponentString(parsed_.host); return ComponentString(parsed_.host);
} }
unsigned short KURL::Port() const { uint16_t KURL::Port() const {
if (!is_valid_ || parsed_.port.len <= 0) if (!is_valid_ || parsed_.port.len <= 0)
return 0; return 0;
DCHECK(!string_.IsNull()); DCHECK(!string_.IsNull());
...@@ -366,7 +366,7 @@ unsigned short KURL::Port() const { ...@@ -366,7 +366,7 @@ unsigned short KURL::Port() const {
DCHECK_NE(port, url::PORT_UNSPECIFIED); // Checked port.len <= 0 already. DCHECK_NE(port, url::PORT_UNSPECIFIED); // Checked port.len <= 0 already.
DCHECK_NE(port, url::PORT_INVALID); // Checked is_valid_ already. DCHECK_NE(port, url::PORT_INVALID); // Checked is_valid_ already.
return static_cast<unsigned short>(port); return static_cast<uint16_t>(port);
} }
// TODO(csharrison): Migrate pass() and user() to return a StringView. Most // TODO(csharrison): Migrate pass() and user() to return a StringView. Most
...@@ -517,7 +517,7 @@ void KURL::SetPort(const String& port) { ...@@ -517,7 +517,7 @@ void KURL::SetPort(const String& port) {
SetPort(parsed_port.ToUInt()); SetPort(parsed_port.ToUInt());
} }
void KURL::SetPort(unsigned short port) { void KURL::SetPort(uint16_t port) {
if (IsDefaultPortForProtocol(port, Protocol())) { if (IsDefaultPortForProtocol(port, Protocol())) {
RemovePort(); RemovePort();
return; return;
......
...@@ -161,7 +161,7 @@ class PLATFORM_EXPORT KURL { ...@@ -161,7 +161,7 @@ class PLATFORM_EXPORT KURL {
// //
// We treat URLs with out-of-range port numbers as invalid URLs, and they // We treat URLs with out-of-range port numbers as invalid URLs, and they
// will be rejected by the canonicalizer. // will be rejected by the canonicalizer.
unsigned short Port() const; uint16_t Port() const;
bool HasPort() const; bool HasPort() const;
String User() const; String User() const;
String Pass() const; String Pass() const;
...@@ -190,7 +190,7 @@ class PLATFORM_EXPORT KURL { ...@@ -190,7 +190,7 @@ class PLATFORM_EXPORT KURL {
void SetHost(const String&); void SetHost(const String&);
void RemovePort(); void RemovePort();
void SetPort(unsigned short); void SetPort(uint16_t);
void SetPort(const String&); void SetPort(const String&);
// Input is like "foo.com" or "foo.com:8000". // Input is like "foo.com" or "foo.com:8000".
......
...@@ -302,7 +302,7 @@ class PLATFORM_EXPORT SecurityOrigin : public RefCounted<SecurityOrigin> { ...@@ -302,7 +302,7 @@ class PLATFORM_EXPORT SecurityOrigin : public RefCounted<SecurityOrigin> {
static String CanonicalizeHost(const String& host, bool* success); static String CanonicalizeHost(const String& host, bool* success);
private: private:
constexpr static const int kInvalidPort = 0; constexpr static const uint16_t kInvalidPort = 0;
friend struct mojo::UrlOriginAdapter; friend struct mojo::UrlOriginAdapter;
friend struct blink::SecurityOriginHash; friend struct blink::SecurityOriginHash;
......
...@@ -460,8 +460,8 @@ TEST_F(SecurityOriginTest, PunycodeNotUnicode) { ...@@ -460,8 +460,8 @@ TEST_F(SecurityOriginTest, PunycodeNotUnicode) {
TEST_F(SecurityOriginTest, PortAndEffectivePortMethod) { TEST_F(SecurityOriginTest, PortAndEffectivePortMethod) {
struct TestCase { struct TestCase {
unsigned short port; uint16_t port;
unsigned short effective_port; uint16_t effective_port;
const char* origin; const char* origin;
} cases[] = { } cases[] = {
{0, 80, "http://example.com"}, {0, 80, "http://example.com"},
......
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