diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp | 127 |
1 files changed, 71 insertions, 56 deletions
diff --git a/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp b/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp index b0d0f69d6..ec2e1f585 100644 --- a/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp +++ b/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. + * Copyright (C) 2012-2017 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,6 @@ #include "config.h" #include "WebResourceLoader.h" -#if ENABLE(NETWORK_PROCESS) - #include "DataReference.h" #include "Logging.h" #include "NetworkProcessConnection.h" @@ -35,23 +33,31 @@ #include "WebCoreArgumentCoders.h" #include "WebErrors.h" #include "WebProcess.h" +#include <WebCore/ApplicationCacheHost.h> #include <WebCore/CertificateInfo.h> +#include <WebCore/DiagnosticLoggingClient.h> +#include <WebCore/DiagnosticLoggingKeys.h> #include <WebCore/DocumentLoader.h> -#include <WebCore/ResourceBuffer.h> +#include <WebCore/Frame.h> +#include <WebCore/Page.h> #include <WebCore/ResourceError.h> #include <WebCore/ResourceLoader.h> +#include <WebCore/SubresourceLoader.h> using namespace WebCore; +#define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(isAlwaysOnLoggingAllowed(), Network, "%p - WebResourceLoader::" fmt, this, ##__VA_ARGS__) + namespace WebKit { -PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader) +Ref<WebResourceLoader> WebResourceLoader::create(Ref<ResourceLoader>&& coreLoader, const TrackingParameters& trackingParameters) { - return adoptRef(new WebResourceLoader(coreLoader)); + return adoptRef(*new WebResourceLoader(WTFMove(coreLoader), trackingParameters)); } -WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader) - : m_coreLoader(coreLoader) +WebResourceLoader::WebResourceLoader(Ref<WebCore::ResourceLoader>&& coreLoader, const TrackingParameters& trackingParameters) + : m_coreLoader(WTFMove(coreLoader)) + , m_trackingParameters(trackingParameters) { } @@ -61,7 +67,7 @@ WebResourceLoader::~WebResourceLoader() IPC::Connection* WebResourceLoader::messageSenderConnection() { - return WebProcess::shared().networkConnection()->connection(); + return &WebProcess::singleton().networkConnection().connection(); } uint64_t WebResourceLoader::messageSenderDestinationID() @@ -69,29 +75,27 @@ uint64_t WebResourceLoader::messageSenderDestinationID() return m_coreLoader->identifier(); } -void WebResourceLoader::cancelResourceLoader() -{ - m_coreLoader->cancel(); -} - void WebResourceLoader::detachFromCoreLoader() { - m_coreLoader = 0; + m_coreLoader = nullptr; } -void WebResourceLoader::willSendRequest(const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse) +void WebResourceLoader::willSendRequest(ResourceRequest&& proposedRequest, ResourceResponse&& redirectResponse) { - LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data()); + LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().latin1().data()); + RELEASE_LOG_IF_ALLOWED("willSendRequest: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID); - Ref<WebResourceLoader> protect(*this); - - ResourceRequest newRequest = proposedRequest; - m_coreLoader->willSendRequest(newRequest, redirectResponse); - - if (!m_coreLoader) + RefPtr<WebResourceLoader> protectedThis(this); + + if (m_coreLoader->documentLoader()->applicationCacheHost().maybeLoadFallbackForRedirect(m_coreLoader.get(), proposedRequest, redirectResponse)) return; - - send(Messages::NetworkResourceLoader::ContinueWillSendRequest(newRequest)); + + m_coreLoader->willSendRequest(WTFMove(proposedRequest), redirectResponse, [protectedThis](ResourceRequest&& request) { + if (!protectedThis->m_coreLoader) + return; + + protectedThis->send(Messages::NetworkResourceLoader::ContinueWillSendRequest(request)); + }); } void WebResourceLoader::didSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent) @@ -99,21 +103,17 @@ void WebResourceLoader::didSendData(uint64_t bytesSent, uint64_t totalBytesToBeS m_coreLoader->didSendData(bytesSent, totalBytesToBeSent); } -void WebResourceLoader::didReceiveResponseWithCertificateInfo(const ResourceResponse& response, const CertificateInfo& certificateInfo, bool needsContinueDidReceiveResponseMessage) +void WebResourceLoader::didReceiveResponse(const ResourceResponse& response, bool needsContinueDidReceiveResponseMessage) { - LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponseWithCertificateInfo for '%s'. Status %d.", m_coreLoader->url().string().utf8().data(), response.httpStatusCode()); + LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponse for '%s'. Status %d.", m_coreLoader->url().string().latin1().data(), response.httpStatusCode()); + RELEASE_LOG_IF_ALLOWED("didReceiveResponse: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", status = %d)", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID, response.httpStatusCode()); Ref<WebResourceLoader> protect(*this); - ResourceResponse responseCopy(response); - // FIXME: This should use CertificateInfo to avoid the platform ifdefs. See https://bugs.webkit.org/show_bug.cgi?id=124724. -#if PLATFORM(MAC) - responseCopy.setCertificateChain(certificateInfo.certificateChain()); -#elif USE(SOUP) - responseCopy.setSoupMessageCertificate(certificateInfo.certificate()); - responseCopy.setSoupMessageTLSErrors(certificateInfo.tlsErrors()); -#endif - m_coreLoader->didReceiveResponse(responseCopy); + if (m_coreLoader->documentLoader()->applicationCacheHost().maybeLoadFallbackForResponse(m_coreLoader.get(), response)) + return; + + m_coreLoader->didReceiveResponse(response); // If m_coreLoader becomes null as a result of the didReceiveResponse callback, we can't use the send function(). if (!m_coreLoader) @@ -125,31 +125,57 @@ void WebResourceLoader::didReceiveResponseWithCertificateInfo(const ResourceResp void WebResourceLoader::didReceiveData(const IPC::DataReference& data, int64_t encodedDataLength) { - LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data()); + LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %lu for '%s'", data.size(), m_coreLoader->url().string().latin1().data()); + + if (!m_hasReceivedData) { + RELEASE_LOG_IF_ALLOWED("didReceiveData: Started receiving data (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID); + m_hasReceivedData = true; + } + m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, DataPayloadBytes); } +void WebResourceLoader::didRetrieveDerivedData(const String& type, const IPC::DataReference& data) +{ + LOG(Network, "(WebProcess) WebResourceLoader::didRetrieveDerivedData of size %lu for '%s'", data.size(), m_coreLoader->url().string().latin1().data()); + + auto buffer = SharedBuffer::create(data.data(), data.size()); + m_coreLoader->didRetrieveDerivedDataFromCache(type, buffer.get()); +} + void WebResourceLoader::didFinishResourceLoad(double finishTime) { - LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); + LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().latin1().data()); + RELEASE_LOG_IF_ALLOWED("didFinishResourceLoad: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID); + m_coreLoader->didFinishLoading(finishTime); } void WebResourceLoader::didFailResourceLoad(const ResourceError& error) { - LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); - + LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().latin1().data()); + RELEASE_LOG_IF_ALLOWED("didFailResourceLoad: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID); + + if (m_coreLoader->documentLoader()->applicationCacheHost().maybeLoadFallbackForError(m_coreLoader.get(), error)) + return; m_coreLoader->didFail(error); } #if ENABLE(SHAREABLE_RESOURCE) void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime) { - LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data()); + LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().latin1().data()); + RELEASE_LOG_IF_ALLOWED("didReceiveResource: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID); RefPtr<SharedBuffer> buffer = handle.tryWrapInSharedBuffer(); + if (!buffer) { LOG_ERROR("Unable to create buffer from ShareableResource sent from the network process."); + RELEASE_LOG_IF_ALLOWED("didReceiveResource: Unable to create SharedBuffer (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_trackingParameters.pageID, m_trackingParameters.frameID, m_trackingParameters.resourceID); + if (auto* frame = m_coreLoader->frame()) { + if (auto* page = frame->page()) + page->diagnosticLoggingClient().logDiagnosticMessage(WebCore::DiagnosticLoggingKeys::internalErrorKey(), WebCore::DiagnosticLoggingKeys::createSharedBufferFailedKey(), WebCore::ShouldSample::No); + } m_coreLoader->didFail(internalError(m_coreLoader->request().url())); return; } @@ -157,8 +183,8 @@ void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& hand Ref<WebResourceLoader> protect(*this); // Only send data to the didReceiveData callback if it exists. - if (buffer->size()) - m_coreLoader->didReceiveBuffer(buffer.get(), buffer->size(), DataPayloadWholeResource); + if (unsigned bufferSize = buffer->size()) + m_coreLoader->didReceiveBuffer(buffer.releaseNonNull(), bufferSize, DataPayloadWholeResource); if (!m_coreLoader) return; @@ -167,20 +193,9 @@ void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& hand } #endif -#if USE(PROTECTION_SPACE_AUTH_CALLBACK) -void WebResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace) +bool WebResourceLoader::isAlwaysOnLoggingAllowed() const { - Ref<WebResourceLoader> protect(*this); - - bool result = m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace); - - if (!m_coreLoader) - return; - - send(Messages::NetworkResourceLoader::ContinueCanAuthenticateAgainstProtectionSpace(result)); + return resourceLoader() && resourceLoader()->isAlwaysOnLoggingAllowed(); } -#endif } // namespace WebKit - -#endif // ENABLE(NETWORK_PROCESS) |