Diff
Modified: trunk/Source/WebCore/ChangeLog (208944 => 208945)
--- trunk/Source/WebCore/ChangeLog 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/ChangeLog 2016-11-21 10:04:01 UTC (rev 208945)
@@ -1,3 +1,24 @@
+2016-11-21 Carlos Garcia Campos <[email protected]>
+
+ Add URL::hostAndPort()
+ https://bugs.webkit.org/show_bug.cgi?id=164907
+
+ Reviewed by Alex Christensen.
+
+ As a convenient way of getting the host and port (if any) as a string.
+
+ * html/URLUtils.h:
+ (WebCore::URLUtils<T>::host): Use URL::hostAndPort().
+ * page/Location.cpp:
+ (WebCore::Location::host): Ditto.
+ * platform/URL.cpp:
+ (WebCore::URL::hostAndPort): Return host:port or just host if there isn't a port.
+ * platform/URL.h:
+ * platform/network/CredentialStorage.cpp:
+ (WebCore::originStringFromURL): Use URL::hostAndPort().
+ * workers/WorkerLocation.cpp:
+ (WebCore::WorkerLocation::host): Ditto.
+
2016-11-21 Philippe Normand <[email protected]>
[WebRTC][OpenWebRTC] parse turns urls
Modified: trunk/Source/WebCore/html/URLUtils.h (208944 => 208945)
--- trunk/Source/WebCore/html/URLUtils.h 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/html/URLUtils.h 2016-11-21 10:04:01 UTC (rev 208945)
@@ -125,12 +125,7 @@
template <typename T>
String URLUtils<T>::host() const
{
- const URL& url = ""
- if (url.hostEnd() == url.pathStart())
- return url.host();
- if (!url.port() || isDefaultPortForProtocol(url.port().value(), url.protocol()))
- return url.host();
- return url.host() + ':' + String::number(url.port().value());
+ return href().hostAndPort();
}
// This function does not allow leading spaces before the port number.
Modified: trunk/Source/WebCore/page/Location.cpp (208944 => 208945)
--- trunk/Source/WebCore/page/Location.cpp 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/page/Location.cpp 2016-11-21 10:04:01 UTC (rev 208945)
@@ -86,8 +86,7 @@
// Note: this is the IE spec. The NS spec swaps the two, it says
// "The hostname property is the concatenation of the host and port properties, separated by a colon."
- const URL& url = ""
- return url.port() ? url.host() + ":" + String::number(url.port().value()) : url.host();
+ return url().hostAndPort();
}
String Location::hostname() const
Modified: trunk/Source/WebCore/platform/URL.cpp (208944 => 208945)
--- trunk/Source/WebCore/platform/URL.cpp 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/platform/URL.cpp 2016-11-21 10:04:01 UTC (rev 208945)
@@ -730,6 +730,13 @@
return number;
}
+String URL::hostAndPort() const
+{
+ if (auto port = this->port())
+ return host() + ':' + String::number(port.value());
+ return host();
+}
+
String URL::user() const
{
return decodeURLEscapeSequences(m_string.substring(m_userStart, m_userEnd - m_userStart));
Modified: trunk/Source/WebCore/platform/URL.h (208944 => 208945)
--- trunk/Source/WebCore/platform/URL.h 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/platform/URL.h 2016-11-21 10:04:01 UTC (rev 208945)
@@ -103,6 +103,7 @@
WEBCORE_EXPORT StringView protocol() const;
WEBCORE_EXPORT String host() const;
WEBCORE_EXPORT Optional<uint16_t> port() const;
+ WEBCORE_EXPORT String hostAndPort() const;
WEBCORE_EXPORT String user() const;
WEBCORE_EXPORT String pass() const;
WEBCORE_EXPORT String path() const;
Modified: trunk/Source/WebCore/platform/network/CredentialStorage.cpp (208944 => 208945)
--- trunk/Source/WebCore/platform/network/CredentialStorage.cpp 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/platform/network/CredentialStorage.cpp 2016-11-21 10:04:01 UTC (rev 208945)
@@ -42,10 +42,7 @@
static String originStringFromURL(const URL& url)
{
- if (url.port())
- return makeString(url.protocol(), "://", url.host(), ':', String::number(url.port().value()), '/');
-
- return makeString(url.protocol(), "://", url.host(), '/');
+ return makeString(url.protocol(), "://", url.hostAndPort(), '/');
}
static String protectionSpaceMapKeyFromURL(const URL& url)
Modified: trunk/Source/WebCore/workers/WorkerLocation.cpp (208944 => 208945)
--- trunk/Source/WebCore/workers/WorkerLocation.cpp 2016-11-21 09:41:29 UTC (rev 208944)
+++ trunk/Source/WebCore/workers/WorkerLocation.cpp 2016-11-21 10:04:01 UTC (rev 208945)
@@ -43,7 +43,7 @@
String WorkerLocation::host() const
{
- return m_url.port() ? m_url.host() + ":" + String::number(m_url.port().value()) : m_url.host();
+ return m_url.hostAndPort();
}
String WorkerLocation::hostname() const