Diff
Modified: trunk/Source/WebCore/ChangeLog (222067 => 222068)
--- trunk/Source/WebCore/ChangeLog 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/ChangeLog 2017-09-15 00:29:47 UTC (rev 222068)
@@ -1,3 +1,36 @@
+2017-09-14 Basuke Suzuki <[email protected]>
+
+ [Curl] Replace the implementation with NetworkLoadMetrics
+ https://bugs.webkit.org/show_bug.cgi?id=176906
+
+ Reviewed by Alex Christensen.
+
+ * platform/network/curl/CurlContext.cpp:
+ (WebCore::CurlHandle::getEffectiveURL):
+ (WebCore::CurlHandle::getPrimaryPort):
+ (WebCore::CurlHandle::getResponseCode):
+ (WebCore::CurlHandle::getContentLenghtDownload):
+ (WebCore::CurlHandle::getHttpAuthAvail):
+ (WebCore::CurlHandle::getTimes):
+ (WebCore::CurlHandle::getEffectiveURL const): Deleted.
+ * platform/network/curl/CurlContext.h:
+ * platform/network/curl/CurlDownload.cpp:
+ (WebCore::CurlDownload::didReceiveHeader):
+ * platform/network/curl/ResourceHandleCurlDelegate.cpp:
+ (WebCore::ResourceHandleCurlDelegate::dispatchSynchronousJob):
+ (WebCore::ResourceHandleCurlDelegate::notifyFinish):
+ (WebCore::ResourceHandleCurlDelegate::getProtectionSpace):
+ (WebCore::ResourceHandleCurlDelegate::didReceiveAllHeaders):
+ (WebCore::ResourceHandleCurlDelegate::handleLocalReceiveResponse):
+ (WebCore::ResourceHandleCurlDelegate::didFinish):
+ (WebCore::ResourceHandleCurlDelegate::getNetworkLoadMetrics):
+ (WebCore::ResourceHandleCurlDelegate::didReceiveHeader):
+ (WebCore::ResourceHandleCurlDelegate::didReceiveData):
+ (WebCore::ResourceHandleCurlDelegate::setWebTimings): Deleted.
+ * platform/network/curl/ResourceHandleCurlDelegate.h:
+ * platform/network/curl/ResourceResponse.h:
+ (WebCore::ResourceResponse::setDeprecatedNetworkLoadMetrics):
+
2017-09-14 Daniel Bates <[email protected]>
[Mac] Spelling, grammar and correction dots are painted upside down
Modified: trunk/Source/WebCore/platform/network/curl/CurlContext.cpp (222067 => 222068)
--- trunk/Source/WebCore/platform/network/curl/CurlContext.cpp 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/platform/network/curl/CurlContext.cpp 2017-09-15 00:29:47 UTC (rev 222068)
@@ -29,6 +29,7 @@
#if USE(CURL)
#include "CurlContext.h"
#include "HTTPHeaderMap.h"
+#include <NetworkLoadMetrics.h>
#include <wtf/MainThread.h>
#include <wtf/text/CString.h>
@@ -571,92 +572,135 @@
curl_easy_setopt(m_handle, CURLOPT_SSL_CTX_FUNCTION, callbackFunc);
}
-URL CurlHandle::getEffectiveURL() const
+URL CurlHandle::getEffectiveURL()
{
- CURLcode errCd = CURLE_FAILED_INIT;
- char* url = ""
+ if (!m_handle) {
+ m_errorCode = CURLE_FAILED_INIT;
+ return URL();
+ }
- if (m_handle)
- errCd = curl_easy_getinfo(m_handle, CURLINFO_EFFECTIVE_URL, &url);
+ char* url;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_EFFECTIVE_URL, &url);
+ if (m_errorCode != CURLE_OK)
+ return URL();
- if ((errCd == CURLE_OK) && url)
- return URL(URL(), url);
-
- return URL();
+ return URL(URL(), url);
}
-CURLcode CurlHandle::getPrimaryPort(long& port)
+std::optional<uint16_t> CurlHandle::getPrimaryPort()
{
- CURLcode errCd = CURLE_FAILED_INIT;
- port = 0;
+ if (!m_handle) {
+ m_errorCode = CURLE_FAILED_INIT;
+ return std::nullopt;
+ }
- if (m_handle)
- errCd = curl_easy_getinfo(m_handle, CURLINFO_PRIMARY_PORT, &port);
+ long port;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_PRIMARY_PORT, &port);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- return errCd;
+ /*
+ * https://github.com/curl/curl/blob/master/lib/connect.c#L612-L660
+ * confirmed that `port` is originally unsigned short.
+ */
+ return static_cast<uint16_t>(port);
}
-CURLcode CurlHandle::getResponseCode(long& responseCode)
+std::optional<long> CurlHandle::getResponseCode()
{
- CURLcode errCd = CURLE_FAILED_INIT;
- responseCode = 0L;
+ if (!m_handle) {
+ m_errorCode = CURLE_FAILED_INIT;
+ return std::nullopt;
+ }
- if (m_handle)
- errCd = curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &responseCode);
+ long responseCode;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &responseCode);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- return errCd;
+ return responseCode;
}
-CURLcode CurlHandle::getContentLenghtDownload(long long& contentLength)
+std::optional<long long> CurlHandle::getContentLenghtDownload()
{
- CURLcode errCd = CURLE_FAILED_INIT;
- contentLength = 0;
+ if (!m_handle) {
+ m_errorCode = CURLE_FAILED_INIT;
+ return std::nullopt;
+ }
- if (m_handle) {
- double tmpContentLength = 0;
+ double contentLength;
- errCd = curl_easy_getinfo(m_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &tmpContentLength);
- if (errCd == CURLE_OK)
- contentLength = static_cast<long long>(tmpContentLength);
- }
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- return errCd;
+ return static_cast<long long>(contentLength);
}
-CURLcode CurlHandle::getHttpAuthAvail(long& httpAuthAvail)
+std::optional<long> CurlHandle::getHttpAuthAvail()
{
- CURLcode errCd = CURLE_FAILED_INIT;
+ if (!m_handle) {
+ m_errorCode = CURLE_FAILED_INIT;
+ return std::nullopt;
+ }
- if (m_handle)
- errCd = curl_easy_getinfo(m_handle, CURLINFO_HTTPAUTH_AVAIL, &httpAuthAvail);
+ long httpAuthAvailable;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_HTTPAUTH_AVAIL, &httpAuthAvailable);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- return errCd;
+ return httpAuthAvailable;
}
-CURLcode CurlHandle::getTimes(double& namelookup, double& connect, double& appconnect, double& pretransfer)
+std::optional<NetworkLoadMetrics> CurlHandle::getTimes()
{
- CURLcode errCd = CURLE_FAILED_INIT;
+ double nameLookup = 0.0;
+ double connect = 0.0;
+ double appConnect = 0.0;
+ double preTransfer = 0.0;
+ double startTransfer = 0.0;
- if (!m_handle)
- return errCd;
+ if (!m_handle) {
+ m_errorCode = CURLE_FAILED_INIT;
+ return std::nullopt;
+ }
- errCd = curl_easy_getinfo(m_handle, CURLINFO_NAMELOOKUP_TIME, &namelookup);
- if (errCd != CURLE_OK)
- return errCd;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_NAMELOOKUP_TIME, &nameLookup);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- errCd = curl_easy_getinfo(m_handle, CURLINFO_CONNECT_TIME, &connect);
- if (errCd != CURLE_OK)
- return errCd;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_CONNECT_TIME, &connect);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- errCd = curl_easy_getinfo(m_handle, CURLINFO_APPCONNECT_TIME, &appconnect);
- if (errCd != CURLE_OK)
- return errCd;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_APPCONNECT_TIME, &appConnect);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- errCd = curl_easy_getinfo(m_handle, CURLINFO_PRETRANSFER_TIME, &pretransfer);
- if (errCd != CURLE_OK)
- return errCd;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_PRETRANSFER_TIME, &preTransfer);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
- return errCd;
+ m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_STARTTRANSFER_TIME, &startTransfer);
+ if (m_errorCode != CURLE_OK)
+ return std::nullopt;
+
+ NetworkLoadMetrics networkLoadMetrics;
+
+ networkLoadMetrics.domainLookupStart = Seconds(0);
+ networkLoadMetrics.domainLookupEnd = Seconds(nameLookup);
+ networkLoadMetrics.connectStart = Seconds(nameLookup);
+ networkLoadMetrics.connectEnd = Seconds(connect);
+
+ if (appConnect > 0.0) {
+ networkLoadMetrics.secureConnectionStart = Seconds(connect);
+ networkLoadMetrics.connectEnd = Seconds(appConnect);
+ }
+
+ networkLoadMetrics.requestStart = networkLoadMetrics.connectEnd;
+ networkLoadMetrics.responseStart = Seconds(startTransfer);
+
+ return networkLoadMetrics;
}
long long CurlHandle::maxCurlOffT()
Modified: trunk/Source/WebCore/platform/network/curl/CurlContext.h (222067 => 222068)
--- trunk/Source/WebCore/platform/network/curl/CurlContext.h 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/platform/network/curl/CurlContext.h 2017-09-15 00:29:47 UTC (rev 222068)
@@ -201,6 +201,7 @@
// CurlHandle -------------------------------------------------
class HTTPHeaderMap;
+class NetworkLoadMetrics;
class CurlHandle {
WTF_MAKE_NONCOPYABLE(CurlHandle);
@@ -286,12 +287,12 @@
void setSslCtxCallbackFunction(curl_ssl_ctx_callback, void*);
// Status
- URL getEffectiveURL() const;
- CURLcode getPrimaryPort(long&);
- CURLcode getResponseCode(long&);
- CURLcode getContentLenghtDownload(long long&);
- CURLcode getHttpAuthAvail(long&);
- CURLcode getTimes(double&, double&, double&, double&);
+ URL getEffectiveURL();
+ std::optional<uint16_t> getPrimaryPort();
+ std::optional<long> getResponseCode();
+ std::optional<long long> getContentLenghtDownload();
+ std::optional<long> getHttpAuthAvail();
+ std::optional<NetworkLoadMetrics> getTimes();
static long long maxCurlOffT();
Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp (222067 => 222068)
--- trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp 2017-09-15 00:29:47 UTC (rev 222068)
@@ -181,11 +181,10 @@
if (header == "\r\n" || header == "\n") {
- long httpCode = 0;
- m_curlHandle.getResponseCode(httpCode);
+ auto httpCode = m_curlHandle.getResponseCode();
- if (httpCode >= 200 && httpCode < 300) {
- URL url = ""
+ if (httpCode && *httpCode >= 200 && *httpCode < 300) {
+ auto url = ""
callOnMainThread([protectedThis = makeRef(*this), url = "" {
ResourceResponse localResponse = protectedThis->getResponse();
protectedThis->m_responseUrl = url;
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp (222067 => 222068)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-15 00:29:47 UTC (rev 222068)
@@ -164,14 +164,6 @@
// curl_easy_perform blocks until the transfer is finished.
CURLcode ret = m_curlHandle.perform();
- double pretransferTime = 0;
- double dnsLookupTime = 0;
- double connectTime = 0;
- double appConnectTime = 0;
-
- m_curlHandle.getTimes(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
- setWebTimings(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
-
if (ret != CURLE_OK)
notifyFail();
else
@@ -277,20 +269,15 @@
void ResourceHandleCurlDelegate::notifyFinish()
{
- double pretransferTime = 0;
- double dnsLookupTime = 0;
- double connectTime = 0;
- double appConnectTime = 0;
+ NetworkLoadMetrics networkLoadMetrics = getNetworkLoadMetrics();
- m_curlHandle.getTimes(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
-
if (isMainThread())
- didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
+ didFinish(networkLoadMetrics);
else {
- callOnMainThread([protectedThis = makeRef(*this), pretransferTime, dnsLookupTime, connectTime, appConnectTime] {
+ callOnMainThread([protectedThis = makeRef(*this), metrics = networkLoadMetrics.isolatedCopy()] {
if (!protectedThis->m_handle)
return;
- protectedThis->didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
+ protectedThis->didFinish(metrics);
});
}
}
@@ -348,19 +335,15 @@
bool ResourceHandleCurlDelegate::getProtectionSpace(const ResourceResponse& response, ProtectionSpace& protectionSpace)
{
- CURLcode err;
-
- long port = 0;
- err = m_curlHandle.getPrimaryPort(port);
- if (err != CURLE_OK)
+ auto port = m_curlHandle.getPrimaryPort();
+ if (!port)
return false;
- long availableAuth = CURLAUTH_NONE;
- err = m_curlHandle.getHttpAuthAvail(availableAuth);
- if (err != CURLE_OK)
+ auto availableAuth = m_curlHandle.getHttpAuthAvail();
+ if (!availableAuth)
return false;
- URL url = ""
+ auto url = ""
if (!url.isValid())
return false;
@@ -384,16 +367,16 @@
ProtectionSpaceAuthenticationScheme authScheme = ProtectionSpaceAuthenticationSchemeUnknown;
- if (availableAuth & CURLAUTH_BASIC)
+ if (*availableAuth & CURLAUTH_BASIC)
authScheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
- if (availableAuth & CURLAUTH_DIGEST)
+ if (*availableAuth & CURLAUTH_DIGEST)
authScheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
- if (availableAuth & CURLAUTH_GSSNEGOTIATE)
+ if (*availableAuth & CURLAUTH_GSSNEGOTIATE)
authScheme = ProtectionSpaceAuthenticationSchemeNegotiate;
- if (availableAuth & CURLAUTH_NTLM)
+ if (*availableAuth & CURLAUTH_NTLM)
authScheme = ProtectionSpaceAuthenticationSchemeNTLM;
- protectionSpace = ProtectionSpace(host, port, serverType, realm, authScheme);
+ protectionSpace = ProtectionSpace(host, *port, serverType, realm, authScheme);
return true;
}
@@ -407,8 +390,9 @@
{
ASSERT(isMainThread());
+ response().setURL(m_curlHandle.getEffectiveURL());
+
response().setExpectedContentLength(contentLength);
- response().setURL(m_curlHandle.getEffectiveURL());
response().setHTTPStatusCode(httpCode);
response().setMimeType(extractMIMETypeFromMediaType(response().httpHeaderField(HTTPHeaderName::ContentType)).convertToASCIILowercase());
response().setTextEncodingName(extractCharsetFromMediaType(response().httpHeaderField(HTTPHeaderName::ContentType)));
@@ -492,9 +476,7 @@
// which means the ResourceLoader's response does not contain the URL.
// Run the code here for local files to resolve the issue.
// TODO: See if there is a better approach for handling this.
- URL url = ""
- ASSERT(url.isValid());
- response().setURL(url);
+ response().setURL(m_curlHandle.getEffectiveURL());
response().setResponseFired(true);
if (m_handle->client())
m_handle->client()->didReceiveResponse(m_handle, ResourceResponse(response()));
@@ -521,9 +503,9 @@
m_workerThreadConditionVariable.notifyOne();
}
-void ResourceHandleCurlDelegate::didFinish(double pretransferTime, double dnsLookupTime, double connectTime, double appConnectTime)
+void ResourceHandleCurlDelegate::didFinish(NetworkLoadMetrics networkLoadMetrics)
{
- setWebTimings(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
+ response().setDeprecatedNetworkLoadMetrics(networkLoadMetrics);
if (!m_handle)
return;
@@ -721,19 +703,13 @@
m_curlHandle.setHttpAuthUserPass(user, password);
}
-void ResourceHandleCurlDelegate::setWebTimings(double pretransferTime, double dnsLookupTime, double connectTime, double appConnectTime)
+NetworkLoadMetrics ResourceHandleCurlDelegate::getNetworkLoadMetrics()
{
- response().deprecatedNetworkLoadMetrics().domainLookupStart = Seconds(0);
- response().deprecatedNetworkLoadMetrics().domainLookupEnd = Seconds(dnsLookupTime);
+ NetworkLoadMetrics networkLoadMetrics;
+ if (auto metrics = m_curlHandle.getTimes())
+ networkLoadMetrics = *metrics;
- response().deprecatedNetworkLoadMetrics().connectStart = Seconds(dnsLookupTime);
- response().deprecatedNetworkLoadMetrics().connectEnd = Seconds(connectTime);
-
- response().deprecatedNetworkLoadMetrics().requestStart = Seconds(connectTime);
- response().deprecatedNetworkLoadMetrics().responseStart = Seconds(pretransferTime);
-
- if (appConnectTime)
- response().deprecatedNetworkLoadMetrics().secureConnectionStart = Seconds(connectTime);
+ return networkLoadMetrics;
}
/*
@@ -762,7 +738,8 @@
*/
if (header == AtomicString("\r\n") || header == AtomicString("\n")) {
long httpCode = 0;
- m_curlHandle.getResponseCode(httpCode);
+ if (auto code = m_curlHandle.getResponseCode())
+ httpCode = *code;
if (!httpCode) {
// Comes here when receiving 200 Connection Established. Just return.
@@ -775,7 +752,8 @@
}
long long contentLength = 0;
- m_curlHandle.getContentLenghtDownload(contentLength);
+ if (auto length = m_curlHandle.getContentLenghtDownload())
+ contentLength = *length;
if (isMainThread())
didReceiveAllHeaders(httpCode, contentLength);
@@ -817,10 +795,10 @@
// this shouldn't be necessary but apparently is. CURL writes the data
// of html page even if it is a redirect that was handled internally
// can be observed e.g. on gmail.com
- long httpCode = 0;
- CURLcode errCd = m_curlHandle.getResponseCode(httpCode);
- if (CURLE_OK == errCd && httpCode >= 300 && httpCode < 400)
- return data.size();
+ if (auto httpCode = m_curlHandle.getResponseCode()) {
+ if (*httpCode >= 300 && *httpCode < 400)
+ return data.size();
+ }
if (!data.size())
return 0;
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h (222067 => 222068)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h 2017-09-15 00:29:47 UTC (rev 222068)
@@ -80,7 +80,7 @@
void handleLocalReceiveResponse();
void prepareSendData(char*, size_t blockSize, size_t numberOfBlocks);
- void didFinish(double, double, double, double);
+ void didFinish(NetworkLoadMetrics);
void didFail(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, unsigned sslErrors);
void handleDataURL();
@@ -91,7 +91,7 @@
size_t getFormElementsCount();
void setupFormData(bool);
void applyAuthentication();
- void setWebTimings(double, double, double, double);
+ NetworkLoadMetrics getNetworkLoadMetrics();
size_t didReceiveHeader(String&&);
size_t didReceiveData(ThreadSafeDataBuffer);
Modified: trunk/Source/WebCore/platform/network/curl/ResourceResponse.h (222067 => 222068)
--- trunk/Source/WebCore/platform/network/curl/ResourceResponse.h 2017-09-15 00:14:10 UTC (rev 222067)
+++ trunk/Source/WebCore/platform/network/curl/ResourceResponse.h 2017-09-15 00:29:47 UTC (rev 222068)
@@ -50,6 +50,8 @@
void appendHTTPHeaderField(const String&);
+ void setDeprecatedNetworkLoadMetrics(const NetworkLoadMetrics& networkLoadMetrics) { m_networkLoadMetrics = networkLoadMetrics; }
+
bool isRedirection() const;
bool isNotModified() const;
bool isUnauthorized() const;