summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/Network
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebKit2/WebProcess/Network
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebKit2/WebProcess/Network')
-rw-r--r--Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp76
-rw-r--r--Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h32
-rw-r--r--Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in7
-rw-r--r--Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp383
-rw-r--r--Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h81
-rw-r--r--Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp233
-rw-r--r--Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h83
-rw-r--r--Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp127
-rw-r--r--Source/WebKit2/WebProcess/Network/WebResourceLoader.h39
-rw-r--r--Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in15
-rw-r--r--Source/WebKit2/WebProcess/Network/WebSocketProvider.cpp50
-rw-r--r--Source/WebKit2/WebProcess/Network/WebSocketProvider.h41
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCNetwork.h54
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.cpp43
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.h45
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.cpp103
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.h67
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.cpp178
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.h104
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp105
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h67
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.cpp99
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.h61
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.messages.in29
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.cpp76
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.h58
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.messages.in30
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.cpp95
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.h65
-rw-r--r--Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.messages.in33
30 files changed, 2034 insertions, 445 deletions
diff --git a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
index b216e1297..6403c746e 100644
--- a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
+++ b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
@@ -29,23 +29,25 @@
#include "DataReference.h"
#include "NetworkConnectionToWebProcessMessages.h"
#include "WebCoreArgumentCoders.h"
+#include "WebLoaderStrategy.h"
#include "WebProcess.h"
-#include "WebResourceBuffer.h"
-#include "WebResourceLoadScheduler.h"
+#include "WebRTCMonitor.h"
+#include "WebRTCMonitorMessages.h"
+#include "WebRTCResolverMessages.h"
+#include "WebRTCSocketMessages.h"
#include "WebResourceLoaderMessages.h"
#include <WebCore/CachedResource.h>
#include <WebCore/MemoryCache.h>
-#include <WebCore/ResourceBuffer.h>
-
-#if ENABLE(NETWORK_PROCESS)
+#include <WebCore/SessionID.h>
+#include <WebCore/SharedBuffer.h>
using namespace WebCore;
namespace WebKit {
NetworkProcessConnection::NetworkProcessConnection(IPC::Connection::Identifier connectionIdentifier)
+ : m_connection(IPC::Connection::createClientConnection(connectionIdentifier, *this))
{
- m_connection = IPC::Connection::createClientConnection(connectionIdentifier, this, RunLoop::main());
m_connection->open();
}
@@ -53,50 +55,86 @@ NetworkProcessConnection::~NetworkProcessConnection()
{
}
-void NetworkProcessConnection::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder)
+void NetworkProcessConnection::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
{
if (decoder.messageReceiverName() == Messages::WebResourceLoader::messageReceiverName()) {
- if (WebResourceLoader* webResourceLoader = WebProcess::shared().webResourceLoadScheduler().webResourceLoaderForIdentifier(decoder.destinationID()))
+ if (auto* webResourceLoader = WebProcess::singleton().webLoaderStrategy().webResourceLoaderForIdentifier(decoder.destinationID()))
webResourceLoader->didReceiveWebResourceLoaderMessage(connection, decoder);
-
return;
}
+#if USE(LIBWEBRTC)
+ if (decoder.messageReceiverName() == Messages::WebRTCSocket::messageReceiverName()) {
+ WebProcess::singleton().libWebRTCNetwork().socket(decoder.destinationID()).didReceiveMessage(connection, decoder);
+ return;
+ }
+ if (decoder.messageReceiverName() == Messages::WebRTCMonitor::messageReceiverName()) {
+ WebProcess::singleton().libWebRTCNetwork().monitor().didReceiveMessage(connection, decoder);
+ return;
+ }
+ if (decoder.messageReceiverName() == Messages::WebRTCResolver::messageReceiverName()) {
+ WebProcess::singleton().libWebRTCNetwork().resolver(decoder.destinationID()).didReceiveMessage(connection, decoder);
+ return;
+ }
+#endif
+
didReceiveNetworkProcessConnectionMessage(connection, decoder);
}
-void NetworkProcessConnection::didReceiveSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder)
+void NetworkProcessConnection::didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&)
{
ASSERT_NOT_REACHED();
}
-void NetworkProcessConnection::didClose(IPC::Connection*)
+void NetworkProcessConnection::didClose(IPC::Connection&)
{
// The NetworkProcess probably crashed.
- WebProcess::shared().networkProcessConnectionClosed(this);
+ Ref<NetworkProcessConnection> protector(*this);
+ WebProcess::singleton().networkProcessConnectionClosed(this);
+
+ Vector<String> dummyFilenames;
+ for (auto& handler : m_writeBlobToFileCompletionHandlers.values())
+ handler(dummyFilenames);
+
+ m_writeBlobToFileCompletionHandlers.clear();
+}
+
+void NetworkProcessConnection::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference)
+{
+}
+
+void NetworkProcessConnection::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler)
+{
+ static uint64_t writeBlobToFileIdentifier;
+ uint64_t requestIdentifier = ++writeBlobToFileIdentifier;
+
+ m_writeBlobToFileCompletionHandlers.set(requestIdentifier, WTFMove(completionHandler));
+
+ WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::WriteBlobsToTemporaryFiles(blobURLs, requestIdentifier), 0);
}
-void NetworkProcessConnection::didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference, IPC::StringReference)
+void NetworkProcessConnection::didWriteBlobsToTemporaryFiles(uint64_t requestIdentifier, const Vector<String>& filenames)
{
+ auto handler = m_writeBlobToFileCompletionHandlers.take(requestIdentifier);
+ if (handler)
+ handler(filenames);
}
#if ENABLE(SHAREABLE_RESOURCE)
-void NetworkProcessConnection::didCacheResource(const ResourceRequest& request, const ShareableResource::Handle& handle)
+void NetworkProcessConnection::didCacheResource(const ResourceRequest& request, const ShareableResource::Handle& handle, SessionID sessionID)
{
- CachedResource* resource = memoryCache()->resourceForRequest(request);
+ CachedResource* resource = MemoryCache::singleton().resourceForRequest(request, sessionID);
if (!resource)
return;
RefPtr<SharedBuffer> buffer = handle.tryWrapInSharedBuffer();
if (!buffer) {
- LOG_ERROR("Unabled to create SharedBuffer from ShareableResource handle for resource url %s", request.url().string().utf8().data());
+ LOG_ERROR("Unable to create SharedBuffer from ShareableResource handle for resource url %s", request.url().string().utf8().data());
return;
}
- resource->tryReplaceEncodedData(buffer.release());
+ resource->tryReplaceEncodedData(*buffer);
}
#endif
} // namespace WebKit
-
-#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h
index 842f6ebad..fb30156e8 100644
--- a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h
+++ b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h
@@ -31,8 +31,6 @@
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
-#if ENABLE(NETWORK_PROCESS)
-
namespace IPC {
class DataReference;
}
@@ -41,6 +39,7 @@ namespace WebCore {
class ResourceError;
class ResourceRequest;
class ResourceResponse;
+class SessionID;
}
namespace WebKit {
@@ -49,37 +48,40 @@ typedef uint64_t ResourceLoadIdentifier;
class NetworkProcessConnection : public RefCounted<NetworkProcessConnection>, IPC::Connection::Client {
public:
- static PassRefPtr<NetworkProcessConnection> create(IPC::Connection::Identifier connectionIdentifier)
+ static Ref<NetworkProcessConnection> create(IPC::Connection::Identifier connectionIdentifier)
{
- return adoptRef(new NetworkProcessConnection(connectionIdentifier));
+ return adoptRef(*new NetworkProcessConnection(connectionIdentifier));
}
~NetworkProcessConnection();
- IPC::Connection* connection() const { return m_connection.get(); }
+ IPC::Connection& connection() { return m_connection.get(); }
+
+ void didReceiveNetworkProcessConnectionMessage(IPC::Connection&, IPC::Decoder&);
- void didReceiveNetworkProcessConnectionMessage(IPC::Connection*, IPC::MessageDecoder&);
+ void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler);
private:
NetworkProcessConnection(IPC::Connection::Identifier);
// IPC::Connection::Client
- virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
- virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
- virtual void didClose(IPC::Connection*) override;
- virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
+ void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
+ void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
+ void didClose(IPC::Connection&) override;
+ void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
+
+ void didWriteBlobsToTemporaryFiles(uint64_t requestIdentifier, const Vector<String>& filenames);
#if ENABLE(SHAREABLE_RESOURCE)
// Message handlers.
- void didCacheResource(const WebCore::ResourceRequest&, const ShareableResource::Handle&);
+ void didCacheResource(const WebCore::ResourceRequest&, const ShareableResource::Handle&, WebCore::SessionID);
#endif
// The connection from the web process to the network process.
- RefPtr<IPC::Connection> m_connection;
+ Ref<IPC::Connection> m_connection;
+
+ HashMap<uint64_t, Function<void (const Vector<String>&)>> m_writeBlobToFileCompletionHandlers;
};
} // namespace WebKit
-#endif // ENABLE(NETWORK_PROCESS)
-
-
#endif // NetworkProcessConnection_h
diff --git a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in
index e6989d98f..a4fc426d8 100644
--- a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in
+++ b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in
@@ -20,14 +20,11 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#if ENABLE(NETWORK_PROCESS)
-
messages -> NetworkProcessConnection LegacyReceiver {
#if ENABLE(SHAREABLE_RESOURCE)
- DidCacheResource(WebCore::ResourceRequest request, WebKit::ShareableResource::Handle resource)
+ DidCacheResource(WebCore::ResourceRequest request, WebKit::ShareableResource::Handle resource, WebCore::SessionID sessionID)
#endif
+ DidWriteBlobsToTemporaryFiles(uint64_t requestIdentifier, Vector<String> filenames)
}
-
-#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp b/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp
new file mode 100644
index 000000000..6b874e01e
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp
@@ -0,0 +1,383 @@
+/*
+ * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebLoaderStrategy.h"
+
+#include "DataReference.h"
+#include "HangDetectionDisabler.h"
+#include "Logging.h"
+#include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkProcessConnection.h"
+#include "NetworkResourceLoadParameters.h"
+#include "SessionTracker.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebErrors.h"
+#include "WebFrame.h"
+#include "WebFrameLoaderClient.h"
+#include "WebFrameNetworkingContext.h"
+#include "WebPage.h"
+#include "WebProcess.h"
+#include "WebResourceLoader.h"
+#include <WebCore/ApplicationCacheHost.h>
+#include <WebCore/CachedResource.h>
+#include <WebCore/DiagnosticLoggingClient.h>
+#include <WebCore/DiagnosticLoggingKeys.h>
+#include <WebCore/Document.h>
+#include <WebCore/DocumentLoader.h>
+#include <WebCore/Frame.h>
+#include <WebCore/FrameLoader.h>
+#include <WebCore/NetscapePlugInStreamLoader.h>
+#include <WebCore/PlatformStrategies.h>
+#include <WebCore/ReferrerPolicy.h>
+#include <WebCore/ResourceLoader.h>
+#include <WebCore/SessionID.h>
+#include <WebCore/Settings.h>
+#include <WebCore/SubresourceLoader.h>
+#include <wtf/text/CString.h>
+
+#if USE(QUICK_LOOK)
+#include <WebCore/QuickLook.h>
+#endif
+
+using namespace WebCore;
+
+#define RELEASE_LOG_IF_ALLOWED(permissionChecker, fmt, ...) RELEASE_LOG_IF(permissionChecker.isAlwaysOnLoggingAllowed(), Network, "%p - WebLoaderStrategy::" fmt, this, ##__VA_ARGS__)
+#define RELEASE_LOG_ERROR_IF_ALLOWED(permissionChecker, fmt, ...) RELEASE_LOG_ERROR_IF(permissionChecker.isAlwaysOnLoggingAllowed(), Network, "%p - WebLoaderStrategy::" fmt, this, ##__VA_ARGS__)
+
+namespace WebKit {
+
+WebLoaderStrategy::WebLoaderStrategy()
+ : m_internallyFailedLoadTimer(RunLoop::main(), this, &WebLoaderStrategy::internallyFailedLoadTimerFired)
+{
+}
+
+WebLoaderStrategy::~WebLoaderStrategy()
+{
+}
+
+RefPtr<SubresourceLoader> WebLoaderStrategy::loadResource(Frame& frame, CachedResource& resource, const ResourceRequest& request, const ResourceLoaderOptions& options)
+{
+ RefPtr<SubresourceLoader> loader = SubresourceLoader::create(frame, resource, request, options);
+ if (loader)
+ scheduleLoad(*loader, &resource, frame.document()->referrerPolicy() == ReferrerPolicy::Default);
+ else
+ RELEASE_LOG_IF_ALLOWED(frame, "loadResource: Unable to create SubresourceLoader (frame = %p", &frame);
+ return loader;
+}
+
+RefPtr<NetscapePlugInStreamLoader> WebLoaderStrategy::schedulePluginStreamLoad(Frame& frame, NetscapePlugInStreamLoaderClient& client, const ResourceRequest& request)
+{
+ RefPtr<NetscapePlugInStreamLoader> loader = NetscapePlugInStreamLoader::create(frame, client, request);
+ if (loader)
+ scheduleLoad(*loader, 0, frame.document()->referrerPolicy() == ReferrerPolicy::Default);
+ return loader;
+}
+
+static std::chrono::milliseconds maximumBufferingTime(CachedResource* resource)
+{
+ if (!resource)
+ return 0ms;
+
+ switch (resource->type()) {
+ case CachedResource::CSSStyleSheet:
+ case CachedResource::Script:
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
+ case CachedResource::FontResource:
+ return std::chrono::milliseconds::max();
+ case CachedResource::ImageResource:
+ return 500ms;
+ case CachedResource::MediaResource:
+ case CachedResource::MainResource:
+ case CachedResource::RawResource:
+ case CachedResource::SVGDocumentResource:
+#if ENABLE(LINK_PREFETCH)
+ case CachedResource::LinkPrefetch:
+ case CachedResource::LinkSubresource:
+#endif
+#if ENABLE(VIDEO_TRACK)
+ case CachedResource::TextTrackResource:
+#endif
+#if ENABLE(XSLT)
+ case CachedResource::XSLStyleSheet:
+#endif
+ return 0ms;
+ }
+
+ ASSERT_NOT_REACHED();
+ return 0ms;
+}
+
+void WebLoaderStrategy::scheduleLoad(ResourceLoader& resourceLoader, CachedResource* resource, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
+{
+ ResourceLoadIdentifier identifier = resourceLoader.identifier();
+ ASSERT(identifier);
+
+ // FIXME: Some entities in WebCore use WebCore's "EmptyFrameLoaderClient" instead of having a proper WebFrameLoaderClient.
+ // EmptyFrameLoaderClient shouldn't exist and everything should be using a WebFrameLoaderClient,
+ // but in the meantime we have to make sure not to mis-cast.
+ WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(resourceLoader.frameLoader()->client());
+ WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
+ WebPage* webPage = webFrame ? webFrame->page() : nullptr;
+
+ WebResourceLoader::TrackingParameters trackingParameters;
+ trackingParameters.pageID = webPage ? webPage->pageID() : 0;
+ trackingParameters.frameID = webFrame ? webFrame->frameID() : 0;
+ trackingParameters.resourceID = identifier;
+
+#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
+ // If the DocumentLoader schedules this as an archive resource load,
+ // then we should remember the ResourceLoader in our records but not schedule it in the NetworkProcess.
+ if (resourceLoader.documentLoader()->scheduleArchiveLoad(resourceLoader, resourceLoader.request())) {
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as an archive resource.", resourceLoader.url().string().utf8().data());
+ RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled as an archive resource (frame = %p, resourceID = %" PRIu64 ")", resourceLoader.frame(), identifier);
+ m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader, trackingParameters));
+ return;
+ }
+#endif
+
+ if (resourceLoader.documentLoader()->applicationCacheHost().maybeLoadResource(resourceLoader, resourceLoader.request(), resourceLoader.request().url())) {
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be loaded from application cache.", resourceLoader.url().string().utf8().data());
+ RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be loaded from application cache (frame = %p, resourceID = %" PRIu64 ")", resourceLoader.frame(), identifier);
+ m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader, trackingParameters));
+ return;
+ }
+
+ if (resourceLoader.request().url().protocolIsData()) {
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be loaded as data.", resourceLoader.url().string().utf8().data());
+ RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be loaded as data (frame = %p, resourceID = %" PRIu64 ")", resourceLoader.frame(), identifier);
+ startLocalLoad(resourceLoader);
+ return;
+ }
+
+#if USE(QUICK_LOOK)
+ if (resourceLoader.request().url().protocolIs(QLPreviewProtocol())) {
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as a QuickLook resource.", resourceLoader.url().string().utf8().data());
+ RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled as a QuickLook resource (frame = %p, resourceID = %" PRIu64 ")", resourceLoader.frame(), identifier);
+ startLocalLoad(resourceLoader);
+ return;
+ }
+#endif
+
+#if USE(SOUP)
+ // For apps that call g_resource_load in a web extension.
+ // https://blogs.gnome.org/alexl/2012/01/26/resources-in-glib/
+ if (resourceLoader.request().url().protocolIs("resource")) {
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as a GResource.", resourceLoader.url().string().utf8().data());
+ RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled as a GResource (frame = %p, resourceID = %" PRIu64 ")", resourceLoader.frame(), identifier);
+ startLocalLoad(resourceLoader);
+ return;
+ }
+#endif
+
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled with the NetworkProcess with priority %d", resourceLoader.url().string().latin1().data(), static_cast<int>(resourceLoader.request().priority()));
+
+ ContentSniffingPolicy contentSniffingPolicy = resourceLoader.shouldSniffContent() ? SniffContent : DoNotSniffContent;
+ StoredCredentials allowStoredCredentials = resourceLoader.shouldUseCredentialStorage() ? AllowStoredCredentials : DoNotAllowStoredCredentials;
+
+ NetworkResourceLoadParameters loadParameters;
+ loadParameters.identifier = identifier;
+ loadParameters.webPageID = webPage ? webPage->pageID() : 0;
+ loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0;
+ loadParameters.sessionID = webPage ? webPage->sessionID() : SessionID::defaultSessionID();
+ loadParameters.request = resourceLoader.request();
+ loadParameters.contentSniffingPolicy = contentSniffingPolicy;
+ loadParameters.allowStoredCredentials = allowStoredCredentials;
+ // If there is no WebFrame then this resource cannot be authenticated with the client.
+ loadParameters.clientCredentialPolicy = (webFrame && webPage && resourceLoader.isAllowedToAskUserForCredentials()) ? ClientCredentialPolicy::MayAskClientForCredentials : ClientCredentialPolicy::CannotAskClientForCredentials;
+ loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = shouldClearReferrerOnHTTPSToHTTPRedirect;
+ loadParameters.defersLoading = resourceLoader.defersLoading();
+ loadParameters.needsCertificateInfo = resourceLoader.shouldIncludeCertificateInfo();
+ loadParameters.maximumBufferingTime = maximumBufferingTime(resource);
+ loadParameters.derivedCachedDataTypesToRetrieve = resourceLoader.options().derivedCachedDataTypesToRetrieve;
+
+ ASSERT((loadParameters.webPageID && loadParameters.webFrameID) || loadParameters.clientCredentialPolicy == ClientCredentialPolicy::CannotAskClientForCredentials);
+
+ if (!WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::ScheduleResourceLoad(loadParameters), 0)) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(resourceLoader, "scheduleLoad: Unable to schedule resource with the NetworkProcess (frame = %p, priority = %d, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), static_cast<int>(resourceLoader.request().priority()), loadParameters.webPageID, loadParameters.webFrameID, loadParameters.identifier);
+ // We probably failed to schedule this load with the NetworkProcess because it had crashed.
+ // This load will never succeed so we will schedule it to fail asynchronously.
+ scheduleInternallyFailedLoad(resourceLoader);
+ return;
+ }
+
+ auto webResourceLoader = WebResourceLoader::create(resourceLoader, trackingParameters);
+ RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: Resource has been queued for scheduling with the NetworkProcess (frame = %p, priority = %d, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", WebResourceLoader = %p)", resourceLoader.frame(), static_cast<int>(resourceLoader.request().priority()), loadParameters.webPageID, loadParameters.webFrameID, loadParameters.identifier, webResourceLoader.ptr());
+ m_webResourceLoaders.set(identifier, WTFMove(webResourceLoader));
+}
+
+void WebLoaderStrategy::scheduleInternallyFailedLoad(WebCore::ResourceLoader& resourceLoader)
+{
+ m_internallyFailedResourceLoaders.add(&resourceLoader);
+ m_internallyFailedLoadTimer.startOneShot(0);
+}
+
+void WebLoaderStrategy::internallyFailedLoadTimerFired()
+{
+ Vector<RefPtr<ResourceLoader>> internallyFailedResourceLoaders;
+ copyToVector(m_internallyFailedResourceLoaders, internallyFailedResourceLoaders);
+
+ for (size_t i = 0; i < internallyFailedResourceLoaders.size(); ++i)
+ internallyFailedResourceLoaders[i]->didFail(internalError(internallyFailedResourceLoaders[i]->url()));
+}
+
+void WebLoaderStrategy::startLocalLoad(WebCore::ResourceLoader& resourceLoader)
+{
+ resourceLoader.start();
+ m_webResourceLoaders.set(resourceLoader.identifier(), WebResourceLoader::create(resourceLoader, { }));
+}
+
+void WebLoaderStrategy::remove(ResourceLoader* resourceLoader)
+{
+ ASSERT(resourceLoader);
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::remove, url '%s'", resourceLoader->url().string().utf8().data());
+
+ if (m_internallyFailedResourceLoaders.contains(resourceLoader)) {
+ m_internallyFailedResourceLoaders.remove(resourceLoader);
+ return;
+ }
+
+ ResourceLoadIdentifier identifier = resourceLoader->identifier();
+ if (!identifier) {
+ LOG_ERROR("WebLoaderStrategy removing a ResourceLoader that has no identifier.");
+ return;
+ }
+
+ RefPtr<WebResourceLoader> loader = m_webResourceLoaders.take(identifier);
+ // Loader may not be registered if we created it, but haven't scheduled yet (a bundle client can decide to cancel such request via willSendRequest).
+ if (!loader)
+ return;
+
+ WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::RemoveLoadIdentifier(identifier), 0);
+
+ // It's possible that this WebResourceLoader might be just about to message back to the NetworkProcess (e.g. ContinueWillSendRequest)
+ // but there's no point in doing so anymore.
+ loader->detachFromCoreLoader();
+}
+
+void WebLoaderStrategy::setDefersLoading(ResourceLoader* resourceLoader, bool defers)
+{
+ ResourceLoadIdentifier identifier = resourceLoader->identifier();
+ WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::SetDefersLoading(identifier, defers), 0);
+}
+
+void WebLoaderStrategy::crossOriginRedirectReceived(ResourceLoader*, const URL&)
+{
+ // We handle cross origin redirects entirely within the NetworkProcess.
+ // We override this call in the WebProcess to make it a no-op.
+}
+
+void WebLoaderStrategy::servePendingRequests(ResourceLoadPriority)
+{
+ // This overrides the base class version.
+ // We don't need to do anything as this is handled by the network process.
+}
+
+void WebLoaderStrategy::suspendPendingRequests()
+{
+ // Network process does keep requests in pending state.
+}
+
+void WebLoaderStrategy::resumePendingRequests()
+{
+ // Network process does keep requests in pending state.
+}
+
+void WebLoaderStrategy::networkProcessCrashed()
+{
+ RELEASE_LOG_ERROR(Network, "WebLoaderStrategy::networkProcessCrashed: failing all pending resource loaders");
+
+ for (auto& loader : m_webResourceLoaders)
+ scheduleInternallyFailedLoad(*loader.value->resourceLoader());
+
+ m_webResourceLoaders.clear();
+}
+
+void WebLoaderStrategy::loadResourceSynchronously(NetworkingContext* context, unsigned long resourceLoadIdentifier, const ResourceRequest& request, StoredCredentials storedCredentials, ClientCredentialPolicy clientCredentialPolicy, ResourceError& error, ResourceResponse& response, Vector<char>& data)
+{
+ WebFrameNetworkingContext* webContext = static_cast<WebFrameNetworkingContext*>(context);
+ // FIXME: Some entities in WebCore use WebCore's "EmptyFrameLoaderClient" instead of having a proper WebFrameLoaderClient.
+ // EmptyFrameLoaderClient shouldn't exist and everything should be using a WebFrameLoaderClient,
+ // but in the meantime we have to make sure not to mis-cast.
+ WebFrameLoaderClient* webFrameLoaderClient = webContext->webFrameLoaderClient();
+ WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebPage* webPage = webFrame ? webFrame->page() : 0;
+
+ NetworkResourceLoadParameters loadParameters;
+ loadParameters.identifier = resourceLoadIdentifier;
+ loadParameters.webPageID = webPage ? webPage->pageID() : 0;
+ loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0;
+ loadParameters.sessionID = webPage ? webPage->sessionID() : SessionID::defaultSessionID();
+ loadParameters.request = request;
+ loadParameters.contentSniffingPolicy = SniffContent;
+ loadParameters.allowStoredCredentials = storedCredentials;
+ loadParameters.clientCredentialPolicy = clientCredentialPolicy;
+ loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = context->shouldClearReferrerOnHTTPSToHTTPRedirect();
+
+ data.resize(0);
+
+ HangDetectionDisabler hangDetectionDisabler;
+
+ if (!WebProcess::singleton().networkConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad(loadParameters), Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::Reply(error, response, data), 0)) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(loadParameters.sessionID, "loadResourceSynchronously: failed sending synchronous network process message (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", loadParameters.webPageID, loadParameters.webFrameID, loadParameters.identifier);
+ if (auto* page = webPage->corePage())
+ page->diagnosticLoggingClient().logDiagnosticMessage(WebCore::DiagnosticLoggingKeys::internalErrorKey(), WebCore::DiagnosticLoggingKeys::synchronousMessageFailedKey(), WebCore::ShouldSample::No);
+ response = ResourceResponse();
+ error = internalError(request.url());
+ }
+}
+
+void WebLoaderStrategy::createPingHandle(NetworkingContext* networkingContext, ResourceRequest& request, bool shouldUseCredentialStorage, bool shouldFollowRedirects)
+{
+ // It's possible that call to createPingHandle might be made during initial empty Document creation before a NetworkingContext exists.
+ // It is not clear that we should send ping loads during that process anyways.
+ if (!networkingContext)
+ return;
+
+ WebFrameNetworkingContext* webContext = static_cast<WebFrameNetworkingContext*>(networkingContext);
+ WebFrameLoaderClient* webFrameLoaderClient = webContext->webFrameLoaderClient();
+ WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
+ WebPage* webPage = webFrame ? webFrame->page() : nullptr;
+
+ NetworkResourceLoadParameters loadParameters;
+ loadParameters.request = request;
+ loadParameters.sessionID = webPage ? webPage->sessionID() : SessionID::defaultSessionID();
+ loadParameters.allowStoredCredentials = shouldUseCredentialStorage ? AllowStoredCredentials : DoNotAllowStoredCredentials;
+ loadParameters.shouldFollowRedirects = shouldFollowRedirects;
+ loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = networkingContext->shouldClearReferrerOnHTTPSToHTTPRedirect();
+
+ WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::LoadPing(loadParameters), 0);
+}
+
+void WebLoaderStrategy::storeDerivedDataToCache(const SHA1::Digest& bodyHash, const String& type, const String& partition, WebCore::SharedBuffer& data)
+{
+ NetworkCache::DataKey key { partition, type, bodyHash };
+ IPC::SharedBufferDataReference dataReference { &data };
+ WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::StoreDerivedDataToCache(key, dataReference), 0);
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h b/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h
new file mode 100644
index 000000000..b7e1b1994
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebLoaderStrategy_h
+#define WebLoaderStrategy_h
+
+#include "WebResourceLoader.h"
+#include <WebCore/LoaderStrategy.h>
+#include <WebCore/ResourceLoader.h>
+#include <wtf/HashSet.h>
+#include <wtf/RunLoop.h>
+
+namespace WebKit {
+
+class NetworkProcessConnection;
+typedef uint64_t ResourceLoadIdentifier;
+
+class WebLoaderStrategy : public WebCore::LoaderStrategy {
+ WTF_MAKE_NONCOPYABLE(WebLoaderStrategy); WTF_MAKE_FAST_ALLOCATED;
+public:
+ WebLoaderStrategy();
+ ~WebLoaderStrategy() override;
+
+ RefPtr<WebCore::SubresourceLoader> loadResource(WebCore::Frame&, WebCore::CachedResource&, const WebCore::ResourceRequest&, const WebCore::ResourceLoaderOptions&) override;
+ void loadResourceSynchronously(WebCore::NetworkingContext*, unsigned long resourceLoadIdentifier, const WebCore::ResourceRequest&, WebCore::StoredCredentials, WebCore::ClientCredentialPolicy, WebCore::ResourceError&, WebCore::ResourceResponse&, Vector<char>& data) override;
+
+ void remove(WebCore::ResourceLoader*) override;
+ void setDefersLoading(WebCore::ResourceLoader*, bool) override;
+ void crossOriginRedirectReceived(WebCore::ResourceLoader*, const WebCore::URL& redirectURL) override;
+
+ void servePendingRequests(WebCore::ResourceLoadPriority minimumPriority) override;
+
+ void suspendPendingRequests() override;
+ void resumePendingRequests() override;
+
+ void createPingHandle(WebCore::NetworkingContext*, WebCore::ResourceRequest&, bool shouldUseCredentialStorage, bool shouldFollowRedirects) override;
+
+ void storeDerivedDataToCache(const SHA1::Digest& bodyHash, const String& type, const String& partition, WebCore::SharedBuffer&) override;
+
+ WebResourceLoader* webResourceLoaderForIdentifier(ResourceLoadIdentifier identifier) const { return m_webResourceLoaders.get(identifier); }
+ RefPtr<WebCore::NetscapePlugInStreamLoader> schedulePluginStreamLoad(WebCore::Frame&, WebCore::NetscapePlugInStreamLoaderClient&, const WebCore::ResourceRequest&);
+
+ void networkProcessCrashed();
+
+private:
+ void scheduleLoad(WebCore::ResourceLoader&, WebCore::CachedResource*, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
+ void scheduleInternallyFailedLoad(WebCore::ResourceLoader&);
+ void internallyFailedLoadTimerFired();
+ void startLocalLoad(WebCore::ResourceLoader&);
+
+ HashSet<RefPtr<WebCore::ResourceLoader>> m_internallyFailedResourceLoaders;
+ RunLoop::Timer<WebLoaderStrategy> m_internallyFailedLoadTimer;
+
+ HashMap<unsigned long, RefPtr<WebResourceLoader>> m_webResourceLoaders;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp b/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp
deleted file mode 100644
index eabd654d4..000000000
--- a/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WebResourceLoadScheduler.h"
-
-#include "Logging.h"
-#include "NetworkConnectionToWebProcessMessages.h"
-#include "NetworkProcessConnection.h"
-#include "NetworkResourceLoadParameters.h"
-#include "SessionTracker.h"
-#include "WebCoreArgumentCoders.h"
-#include "WebErrors.h"
-#include "WebFrame.h"
-#include "WebFrameLoaderClient.h"
-#include "WebPage.h"
-#include "WebProcess.h"
-#include "WebResourceLoader.h"
-#include <WebCore/CachedResource.h>
-#include <WebCore/Document.h>
-#include <WebCore/DocumentLoader.h>
-#include <WebCore/Frame.h>
-#include <WebCore/FrameLoader.h>
-#include <WebCore/NetscapePlugInStreamLoader.h>
-#include <WebCore/ReferrerPolicy.h>
-#include <WebCore/ResourceBuffer.h>
-#include <WebCore/ResourceLoader.h>
-#include <WebCore/Settings.h>
-#include <WebCore/SubresourceLoader.h>
-#include <wtf/text/CString.h>
-
-#if ENABLE(NETWORK_PROCESS)
-
-using namespace WebCore;
-
-namespace WebKit {
-
-WebResourceLoadScheduler::WebResourceLoadScheduler()
- : m_internallyFailedLoadTimer(RunLoop::main(), this, &WebResourceLoadScheduler::internallyFailedLoadTimerFired)
- , m_suspendPendingRequestsCount(0)
-{
-}
-
-WebResourceLoadScheduler::~WebResourceLoadScheduler()
-{
-}
-
-PassRefPtr<SubresourceLoader> WebResourceLoadScheduler::scheduleSubresourceLoad(Frame* frame, CachedResource* resource, const ResourceRequest& request, ResourceLoadPriority priority, const ResourceLoaderOptions& options)
-{
- RefPtr<SubresourceLoader> loader = SubresourceLoader::create(frame, resource, request, options);
- if (loader)
- scheduleLoad(loader.get(), resource, priority, frame->document()->referrerPolicy() == ReferrerPolicyDefault);
- return loader.release();
-}
-
-PassRefPtr<NetscapePlugInStreamLoader> WebResourceLoadScheduler::schedulePluginStreamLoad(Frame* frame, NetscapePlugInStreamLoaderClient* client, const ResourceRequest& request)
-{
- RefPtr<NetscapePlugInStreamLoader> loader = NetscapePlugInStreamLoader::create(frame, client, request);
- if (loader)
- scheduleLoad(loader.get(), 0, ResourceLoadPriorityLow, frame->document()->referrerPolicy() == ReferrerPolicyDefault);
- return loader.release();
-}
-
-void WebResourceLoadScheduler::scheduleLoad(ResourceLoader* resourceLoader, CachedResource* resource, ResourceLoadPriority priority, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
-{
- ASSERT(resourceLoader);
- ASSERT(priority != ResourceLoadPriorityUnresolved);
- priority = ResourceLoadPriorityHighest;
-
- ResourceLoadIdentifier identifier = resourceLoader->identifier();
- ASSERT(identifier);
-
-#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
- // If the DocumentLoader schedules this as an archive resource load,
- // then we should remember the ResourceLoader in our records but not schedule it in the NetworkProcess.
- if (resourceLoader->documentLoader()->scheduleArchiveLoad(resourceLoader, resourceLoader->request())) {
- LOG(NetworkScheduling, "(WebProcess) WebResourceLoadScheduler::scheduleLoad, url '%s' will be handled as an archive resource.", resourceLoader->url().string().utf8().data());
- m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader));
- return;
- }
-#endif
-
- LOG(NetworkScheduling, "(WebProcess) WebResourceLoadScheduler::scheduleLoad, url '%s' will be scheduled with the NetworkProcess with priority %i", resourceLoader->url().string().utf8().data(), priority);
-
- ContentSniffingPolicy contentSniffingPolicy = resourceLoader->shouldSniffContent() ? SniffContent : DoNotSniffContent;
- StoredCredentials allowStoredCredentials = resourceLoader->shouldUseCredentialStorage() ? AllowStoredCredentials : DoNotAllowStoredCredentials;
-
- // FIXME: Some entities in WebCore use WebCore's "EmptyFrameLoaderClient" instead of having a proper WebFrameLoaderClient.
- // EmptyFrameLoaderClient shouldn't exist and everything should be using a WebFrameLoaderClient,
- // but in the meantime we have to make sure not to mis-cast.
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(resourceLoader->frameLoader()->client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
- WebPage* webPage = webFrame ? webFrame->page() : 0;
-
- NetworkResourceLoadParameters loadParameters;
- loadParameters.identifier = identifier;
- loadParameters.webPageID = webPage ? webPage->pageID() : 0;
- loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0;
- loadParameters.sessionID = webPage ? webPage->sessionID() : SessionTracker::defaultSessionID;
- loadParameters.request = resourceLoader->request();
- loadParameters.priority = priority;
- loadParameters.contentSniffingPolicy = contentSniffingPolicy;
- loadParameters.allowStoredCredentials = allowStoredCredentials;
- // If there is no WebFrame then this resource cannot be authenticated with the client.
- loadParameters.clientCredentialPolicy = (webFrame && webPage) ? resourceLoader->clientCredentialPolicy() : DoNotAskClientForAnyCredentials;
- loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = shouldClearReferrerOnHTTPSToHTTPRedirect;
- loadParameters.isMainResource = resource && resource->type() == CachedResource::MainResource;
-
- ASSERT((loadParameters.webPageID && loadParameters.webFrameID) || loadParameters.clientCredentialPolicy == DoNotAskClientForAnyCredentials);
-
- if (!WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::ScheduleResourceLoad(loadParameters), 0)) {
- // We probably failed to schedule this load with the NetworkProcess because it had crashed.
- // This load will never succeed so we will schedule it to fail asynchronously.
- scheduleInternallyFailedLoad(resourceLoader);
- return;
- }
-
- m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader));
-
- notifyDidScheduleResourceRequest(resourceLoader);
-}
-
-void WebResourceLoadScheduler::scheduleInternallyFailedLoad(WebCore::ResourceLoader* resourceLoader)
-{
- m_internallyFailedResourceLoaders.add(resourceLoader);
- m_internallyFailedLoadTimer.startOneShot(0);
-}
-
-void WebResourceLoadScheduler::internallyFailedLoadTimerFired()
-{
- Vector<RefPtr<ResourceLoader>> internallyFailedResourceLoaders;
- copyToVector(m_internallyFailedResourceLoaders, internallyFailedResourceLoaders);
-
- for (size_t i = 0; i < internallyFailedResourceLoaders.size(); ++i)
- internallyFailedResourceLoaders[i]->didFail(internalError(internallyFailedResourceLoaders[i]->url()));
-}
-
-void WebResourceLoadScheduler::remove(ResourceLoader* resourceLoader)
-{
- ASSERT(resourceLoader);
- LOG(NetworkScheduling, "(WebProcess) WebResourceLoadScheduler::remove, url '%s'", resourceLoader->url().string().utf8().data());
-
- if (m_internallyFailedResourceLoaders.contains(resourceLoader)) {
- m_internallyFailedResourceLoaders.remove(resourceLoader);
- return;
- }
-
- ResourceLoadIdentifier identifier = resourceLoader->identifier();
- if (!identifier) {
- LOG_ERROR("WebResourceLoadScheduler removing a ResourceLoader that has no identifier.");
- return;
- }
-
- RefPtr<WebResourceLoader> loader = m_webResourceLoaders.take(identifier);
- // Loader may not be registered if we created it, but haven't scheduled yet (a bundle client can decide to cancel such request via willSendRequest).
- if (!loader)
- return;
-
- WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::RemoveLoadIdentifier(identifier), 0);
-
- // It's possible that this WebResourceLoader might be just about to message back to the NetworkProcess (e.g. ContinueWillSendRequest)
- // but there's no point in doing so anymore.
- loader->detachFromCoreLoader();
-}
-
-void WebResourceLoadScheduler::crossOriginRedirectReceived(ResourceLoader*, const URL&)
-{
- // We handle cross origin redirects entirely within the NetworkProcess.
- // We override this call in the WebProcess to make it a no-op.
-}
-
-void WebResourceLoadScheduler::servePendingRequests(ResourceLoadPriority minimumPriority)
-{
- LOG(NetworkScheduling, "(WebProcess) WebResourceLoadScheduler::servePendingRequests");
-
- // The NetworkProcess scheduler is good at making sure loads are serviced until there are no more pending requests.
- // If this WebProcess isn't expecting requests to be served then we can ignore messaging the NetworkProcess right now.
- if (m_suspendPendingRequestsCount)
- return;
-
- WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::ServePendingRequests(minimumPriority), 0);
-}
-
-void WebResourceLoadScheduler::suspendPendingRequests()
-{
- ++m_suspendPendingRequestsCount;
-}
-
-void WebResourceLoadScheduler::resumePendingRequests()
-{
- ASSERT(m_suspendPendingRequestsCount);
- --m_suspendPendingRequestsCount;
-}
-
-void WebResourceLoadScheduler::setSerialLoadingEnabled(bool enabled)
-{
- WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::SetSerialLoadingEnabled(enabled), Messages::NetworkConnectionToWebProcess::SetSerialLoadingEnabled::Reply(), 0);
-}
-
-void WebResourceLoadScheduler::networkProcessCrashed()
-{
- HashMap<unsigned long, RefPtr<WebResourceLoader>>::iterator end = m_webResourceLoaders.end();
- for (HashMap<unsigned long, RefPtr<WebResourceLoader>>::iterator i = m_webResourceLoaders.begin(); i != end; ++i)
- scheduleInternallyFailedLoad(i->value.get()->resourceLoader());
-
- m_webResourceLoaders.clear();
-}
-
-} // namespace WebKit
-
-#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h b/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h
deleted file mode 100644
index 72c199fc2..000000000
--- a/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WebResourceLoadScheduler_h
-#define WebResourceLoadScheduler_h
-
-#include "WebResourceLoader.h"
-#include <WebCore/ResourceLoadPriority.h>
-#include <WebCore/ResourceLoadScheduler.h>
-#include <WebCore/ResourceLoader.h>
-#include <wtf/RunLoop.h>
-
-#if ENABLE(NETWORK_PROCESS)
-
-namespace WebKit {
-
-class NetworkProcessConnection;
-typedef uint64_t ResourceLoadIdentifier;
-
-class WebResourceLoadScheduler : public WebCore::ResourceLoadScheduler {
- WTF_MAKE_NONCOPYABLE(WebResourceLoadScheduler); WTF_MAKE_FAST_ALLOCATED;
-public:
- WebResourceLoadScheduler();
- virtual ~WebResourceLoadScheduler();
-
- virtual PassRefPtr<WebCore::SubresourceLoader> scheduleSubresourceLoad(WebCore::Frame*, WebCore::CachedResource*, const WebCore::ResourceRequest&, WebCore::ResourceLoadPriority, const WebCore::ResourceLoaderOptions&) override;
- virtual PassRefPtr<WebCore::NetscapePlugInStreamLoader> schedulePluginStreamLoad(WebCore::Frame*, WebCore::NetscapePlugInStreamLoaderClient*, const WebCore::ResourceRequest&) override;
-
- virtual void remove(WebCore::ResourceLoader*) override;
- virtual void crossOriginRedirectReceived(WebCore::ResourceLoader*, const WebCore::URL& redirectURL) override;
-
- virtual void servePendingRequests(WebCore::ResourceLoadPriority minimumPriority = WebCore::ResourceLoadPriorityVeryLow) override;
-
- virtual void suspendPendingRequests() override;
- virtual void resumePendingRequests() override;
-
- virtual void setSerialLoadingEnabled(bool) override;
-
- WebResourceLoader* webResourceLoaderForIdentifier(ResourceLoadIdentifier identifier) const { return m_webResourceLoaders.get(identifier); }
-
- void networkProcessCrashed();
-
-private:
- void scheduleLoad(WebCore::ResourceLoader*, WebCore::CachedResource*, WebCore::ResourceLoadPriority, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
- void scheduleInternallyFailedLoad(WebCore::ResourceLoader*);
- void internallyFailedLoadTimerFired();
-
- HashSet<RefPtr<WebCore::ResourceLoader>> m_internallyFailedResourceLoaders;
- RunLoop::Timer<WebResourceLoadScheduler> m_internallyFailedLoadTimer;
-
- HashMap<unsigned long, RefPtr<WebResourceLoader>> m_webResourceLoaders;
-
- unsigned m_suspendPendingRequestsCount;
-
-};
-
-} // namespace WebKit
-
-#endif // ENABLE(NETWORK_PROCESS)
-
-#endif // WebResourceLoadScheduler_h
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)
diff --git a/Source/WebKit2/WebProcess/Network/WebResourceLoader.h b/Source/WebKit2/WebProcess/Network/WebResourceLoader.h
index 9c8ae48c4..9e391b5fa 100644
--- a/Source/WebKit2/WebProcess/Network/WebResourceLoader.h
+++ b/Source/WebKit2/WebProcess/Network/WebResourceLoader.h
@@ -26,12 +26,9 @@
#ifndef WebResourceLoader_h
#define WebResourceLoader_h
-#if ENABLE(NETWORK_PROCESS)
-
#include "Connection.h"
#include "MessageSender.h"
#include "ShareableResource.h"
-#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
@@ -40,9 +37,6 @@ class DataReference;
}
namespace WebCore {
-class CertificateInfo;
-class ProtectionSpace;
-class ResourceBuffer;
class ResourceError;
class ResourceLoader;
class ResourceRequest;
@@ -55,44 +49,47 @@ typedef uint64_t ResourceLoadIdentifier;
class WebResourceLoader : public RefCounted<WebResourceLoader>, public IPC::MessageSender {
public:
- static PassRefPtr<WebResourceLoader> create(PassRefPtr<WebCore::ResourceLoader>);
+ struct TrackingParameters {
+ uint64_t pageID { 0 };
+ uint64_t frameID { 0 };
+ ResourceLoadIdentifier resourceID { 0 };
+ };
+
+ static Ref<WebResourceLoader> create(Ref<WebCore::ResourceLoader>&&, const TrackingParameters&);
~WebResourceLoader();
- void didReceiveWebResourceLoaderMessage(IPC::Connection*, IPC::MessageDecoder&);
+ void didReceiveWebResourceLoaderMessage(IPC::Connection&, IPC::Decoder&);
WebCore::ResourceLoader* resourceLoader() const { return m_coreLoader.get(); }
void detachFromCoreLoader();
+ bool isAlwaysOnLoggingAllowed() const;
+
private:
- WebResourceLoader(PassRefPtr<WebCore::ResourceLoader>);
+ WebResourceLoader(Ref<WebCore::ResourceLoader>&&, const TrackingParameters&);
// IPC::MessageSender
- virtual IPC::Connection* messageSenderConnection() override;
- virtual uint64_t messageSenderDestinationID() override;
-
- void cancelResourceLoader();
+ IPC::Connection* messageSenderConnection() override;
+ uint64_t messageSenderDestinationID() override;
- void willSendRequest(const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
+ void willSendRequest(WebCore::ResourceRequest&&, WebCore::ResourceResponse&&);
void didSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent);
- void didReceiveResponseWithCertificateInfo(const WebCore::ResourceResponse&, const WebCore::CertificateInfo&, bool needsContinueDidReceiveResponseMessage);
+ void didReceiveResponse(const WebCore::ResourceResponse&, bool needsContinueDidReceiveResponseMessage);
void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength);
+ void didRetrieveDerivedData(const String& type, const IPC::DataReference&);
void didFinishResourceLoad(double finishTime);
void didFailResourceLoad(const WebCore::ResourceError&);
#if ENABLE(SHAREABLE_RESOURCE)
void didReceiveResource(const ShareableResource::Handle&, double finishTime);
#endif
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
- void canAuthenticateAgainstProtectionSpace(const WebCore::ProtectionSpace&);
-#endif
-
RefPtr<WebCore::ResourceLoader> m_coreLoader;
+ TrackingParameters m_trackingParameters;
+ bool m_hasReceivedData { false };
};
} // namespace WebKit
-#endif // ENABLE(NETWORK_PROCESS)
-
#endif // WebResourceLoader_h
diff --git a/Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in b/Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in
index 86166de69..842e0a4cc 100644
--- a/Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in
+++ b/Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in
@@ -20,28 +20,17 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#if ENABLE(NETWORK_PROCESS)
-
messages -> WebResourceLoader LegacyReceiver {
-
- CancelResourceLoader()
-
- // FIXME (NetworkProcess): We'll need much more granularity for response messages.
WillSendRequest(WebCore::ResourceRequest request, WebCore::ResourceResponse redirectResponse)
DidSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent)
- DidReceiveResponseWithCertificateInfo(WebCore::ResourceResponse response, WebCore::CertificateInfo certificateInfo, bool needsContinueDidReceiveResponseMessage)
+ DidReceiveResponse(WebCore::ResourceResponse response, bool needsContinueDidReceiveResponseMessage)
DidReceiveData(IPC::DataReference data, int64_t encodedDataLength)
DidFinishResourceLoad(double finishTime)
+ DidRetrieveDerivedData(String type, IPC::DataReference data)
DidFailResourceLoad(WebCore::ResourceError error)
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
- CanAuthenticateAgainstProtectionSpace(WebCore::ProtectionSpace protectionSpace)
-#endif
-
#if ENABLE(SHAREABLE_RESOURCE)
// DidReceiveResource is for when we have the entire resource data available at once, such as when the resource is cached in memory
DidReceiveResource(WebKit::ShareableResource::Handle resource, double finishTime)
#endif
}
-
-#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/WebProcess/Network/WebSocketProvider.cpp b/Source/WebKit2/WebProcess/Network/WebSocketProvider.cpp
new file mode 100644
index 000000000..2e8f40dd4
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/WebSocketProvider.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebSocketProvider.h"
+
+#if ENABLE(WEB_SOCKETS)
+
+#include <WebCore/SocketStreamHandleImpl.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+Ref<SocketStreamHandle> WebSocketProvider::createSocketStreamHandle(const URL& url, SocketStreamHandleClient& client, SessionID sessionID, const String& credentialPartition)
+{
+ // FIXME: This should return a proxy so we can do the actual network interactions in the NetworkProcess.
+ return SocketStreamHandleImpl::create(url, client, sessionID, credentialPartition);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(WEB_SOCKETS)
diff --git a/Source/WebKit2/WebProcess/Network/WebSocketProvider.h b/Source/WebKit2/WebProcess/Network/WebSocketProvider.h
new file mode 100644
index 000000000..dca5f315a
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/WebSocketProvider.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <WebCore/SocketProvider.h>
+
+namespace WebKit {
+
+class WebSocketProvider final : public WebCore::SocketProvider {
+public:
+ static Ref<WebSocketProvider> create() { return adoptRef(*new WebSocketProvider); }
+#if ENABLE(WEB_SOCKETS)
+ Ref<WebCore::SocketStreamHandle> createSocketStreamHandle(const WebCore::URL&, WebCore::SocketStreamHandleClient&, WebCore::SessionID, const String& credentialPartition) final;
+#endif
+ virtual ~WebSocketProvider() { }
+};
+
+}
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCNetwork.h b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCNetwork.h
new file mode 100644
index 000000000..2a9c5ba73
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCNetwork.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCSocketFactory.h"
+#include "WebRTCMonitor.h"
+#include "WebRTCResolver.h"
+#include "WebRTCSocket.h"
+
+namespace WebKit {
+
+class LibWebRTCNetwork {
+public:
+ LibWebRTCNetwork() = default;
+
+ WebRTCMonitor& monitor() { return m_webNetworkMonitor; }
+ LibWebRTCSocketFactory& socketFactory() { return m_socketFactory; }
+
+ WebRTCSocket socket(uint64_t identifier) { return WebRTCSocket(socketFactory(), identifier); }
+ WebRTCResolver resolver(uint64_t identifier) { return WebRTCResolver(socketFactory(), identifier); }
+
+private:
+ LibWebRTCSocketFactory m_socketFactory;
+ WebRTCMonitor m_webNetworkMonitor;
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.cpp b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.cpp
new file mode 100644
index 000000000..d3b15151b
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LibWebRTCProvider.h"
+
+#if USE(LIBWEBRTC)
+
+#include "WebProcess.h"
+#include <webrtc/api/peerconnectionfactory.h>
+
+namespace WebKit {
+
+rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer)
+{
+ return WebCore::LibWebRTCProvider::createPeerConnection(observer, WebProcess::singleton().libWebRTCNetwork().monitor(), WebProcess::singleton().libWebRTCNetwork().socketFactory());
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.h b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.h
new file mode 100644
index 000000000..87dc23b90
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <WebCore/LibWebRTCProvider.h>
+
+
+namespace WebKit {
+
+#if USE(LIBWEBRTC)
+class LibWebRTCProvider final : public WebCore::LibWebRTCProvider {
+public:
+ LibWebRTCProvider() = default;
+
+private:
+ rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&) final;
+};
+#else
+using LibWebRTCProvider = WebCore::LibWebRTCProvider;
+#endif // USE(LIBWEBRTC)
+
+} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.cpp b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.cpp
new file mode 100644
index 000000000..9c718790f
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LibWebRTCResolver.h"
+
+#if USE(LIBWEBRTC)
+
+#include "NetworkProcessConnection.h"
+#include "NetworkRTCProviderMessages.h"
+#include "WebProcess.h"
+#include <wtf/MainThread.h>
+
+namespace WebKit {
+
+static inline void sendOnMainThread(Function<void(IPC::Connection&)>&& callback)
+{
+ callOnMainThread([callback = WTFMove(callback)]() {
+ callback(WebProcess::singleton().networkConnection().connection());
+ });
+}
+
+void LibWebRTCResolver::Start(const rtc::SocketAddress& address)
+{
+ m_isResolving = true;
+ m_addressToResolve = address;
+ m_port = address.port();
+ auto identifier = m_identifier;
+ sendOnMainThread([identifier, address](IPC::Connection& connection) {
+ auto addressString = address.HostAsURIString();
+ connection.send(Messages::NetworkRTCProvider::CreateResolver(identifier, String(addressString.data(), addressString.length())), 0);
+ });
+}
+
+bool LibWebRTCResolver::GetResolvedAddress(int family, rtc::SocketAddress* address) const
+{
+ ASSERT(address);
+ if (m_error || !m_addresses.size())
+ return false;
+
+ *address = m_addressToResolve;
+ for (auto& ipAddress : m_addresses) {
+ if (family == ipAddress.family()) {
+ address->SetResolvedIP(ipAddress);
+ address->SetPort(m_port);
+ return true;
+ }
+ }
+ return false;
+}
+
+void LibWebRTCResolver::Destroy(bool)
+{
+ if (!isResolving())
+ return;
+
+ auto identifier = m_identifier;
+ sendOnMainThread([identifier](IPC::Connection& connection) {
+ connection.send(Messages::NetworkRTCProvider::StopResolver(identifier), 0);
+ });
+
+ // Let's take the resolver so that it gets destroyed at the end of this function.
+ auto resolver = WebProcess::singleton().libWebRTCNetwork().socketFactory().takeResolver(m_identifier);
+ ASSERT(resolver);
+}
+
+void LibWebRTCResolver::setResolvedAddress(const Vector<rtc::IPAddress>& addresses)
+{
+ m_addresses = addresses;
+ SignalDone(this);
+}
+
+void LibWebRTCResolver::setError(int error)
+{
+ m_error = error;
+ SignalDone(this);
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.h b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.h
new file mode 100644
index 000000000..935b62975
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCResolver.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include <WebCore/LibWebRTCMacros.h>
+#include <webrtc/base/nethelpers.h>
+#include <webrtc/p2p/base/packetsocketfactory.h>
+#include <wtf/Vector.h>
+
+namespace WebKit {
+class LibWebRTCSocketFactory;
+
+class LibWebRTCResolver final : public rtc::AsyncResolverInterface {
+public:
+ LibWebRTCResolver(uint64_t identifier) : m_identifier(identifier) { }
+
+ bool isResolving() const { return m_isResolving; }
+ uint64_t identifier() const { return m_identifier; }
+
+private:
+ friend class WebRTCResolver;
+
+ // AsyncResolverInterface API.
+ void Start(const rtc::SocketAddress&) final;
+ bool GetResolvedAddress(int, rtc::SocketAddress*) const final;
+ int GetError() const final { return m_error; }
+ void Destroy(bool) final;
+
+ void setError(int);
+ void setResolvedAddress(const Vector<rtc::IPAddress>&);
+
+ uint64_t m_identifier;
+ Vector<rtc::IPAddress> m_addresses;
+ rtc::SocketAddress m_addressToResolve;
+ int m_error { 0 };
+ uint16_t m_port { 0 };
+ bool m_isResolving { false };
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.cpp b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.cpp
new file mode 100644
index 000000000..20277d577
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LibWebRTCSocket.h"
+
+#if USE(LIBWEBRTC)
+
+#include "DataReference.h"
+#include "LibWebRTCSocketFactory.h"
+#include "NetworkProcessConnection.h"
+#include "NetworkRTCSocketMessages.h"
+#include "WebProcess.h"
+#include <WebCore/SharedBuffer.h>
+#include <wtf/Function.h>
+#include <wtf/MainThread.h>
+
+namespace WebKit {
+
+static inline void sendOnMainThread(Function<void(IPC::Connection&)>&& callback)
+{
+ callOnMainThread([callback = WTFMove(callback)]() {
+ callback(WebProcess::singleton().networkConnection().connection());
+ });
+}
+
+LibWebRTCSocket::LibWebRTCSocket(LibWebRTCSocketFactory& factory, uint64_t identifier, Type type, const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress)
+ : m_factory(factory)
+ , m_identifier(identifier)
+ , m_type(type)
+ , m_localAddress(localAddress)
+ , m_remoteAddress(remoteAddress)
+{
+ memset(&m_options, 1, MAX_SOCKET_OPTION);
+}
+
+LibWebRTCSocket::~LibWebRTCSocket()
+{
+ m_factory.detach(*this);
+}
+
+rtc::SocketAddress LibWebRTCSocket::GetLocalAddress() const
+{
+ return m_localAddress;
+}
+
+rtc::SocketAddress LibWebRTCSocket::GetRemoteAddress() const
+{
+ return m_remoteAddress;
+}
+
+void LibWebRTCSocket::signalAddressReady(const rtc::SocketAddress& address)
+{
+ m_localAddress = address;
+ m_state = (m_type == Type::ClientTCP) ? STATE_CONNECTED : STATE_BOUND;
+ SignalAddressReady(this, m_localAddress);
+}
+
+void LibWebRTCSocket::signalReadPacket(const WebCore::SharedBuffer& buffer, rtc::SocketAddress&& address, int64_t timestamp)
+{
+ m_remoteAddress = WTFMove(address);
+ SignalReadPacket(this, buffer.data(), buffer.size(), m_remoteAddress, rtc::PacketTime(timestamp, 0));
+}
+
+void LibWebRTCSocket::signalSentPacket(int rtcPacketID, int64_t sendTimeMs)
+{
+ m_availableSendingBytes += m_beingSentPacketSizes.takeFirst();
+ SignalSentPacket(this, rtc::SentPacket(rtcPacketID, sendTimeMs));
+ if (m_shouldSignalReadyToSend) {
+ m_shouldSignalReadyToSend = false;
+ SignalReadyToSend(this);
+ }
+}
+
+void LibWebRTCSocket::signalConnect()
+{
+ m_state = STATE_CONNECTED;
+ SignalConnect(this);
+}
+
+void LibWebRTCSocket::signalClose(int error)
+{
+ m_state = STATE_CLOSED;
+ SignalClose(this, error);
+}
+
+static inline String authKey(const rtc::PacketOptions& options)
+{
+ if (options.packet_time_params.srtp_auth_key.size() <= 0)
+ return { };
+ return String(options.packet_time_params.srtp_auth_key.data(), options.packet_time_params.srtp_auth_key.size());
+}
+
+bool LibWebRTCSocket::willSend(size_t size)
+{
+ if (size > m_availableSendingBytes) {
+ m_shouldSignalReadyToSend = true;
+ setError(EWOULDBLOCK);
+ return false;
+ }
+ m_availableSendingBytes -= size;
+ m_beingSentPacketSizes.append(size);
+ return true;
+}
+
+int LibWebRTCSocket::SendTo(const void *value, size_t size, const rtc::SocketAddress& address, const rtc::PacketOptions& options)
+{
+ if (!willSend(size))
+ return -1;
+
+ auto buffer = WebCore::SharedBuffer::create(static_cast<const uint8_t*>(value), size);
+ auto identifier = this->identifier();
+
+ sendOnMainThread([identifier, buffer = WTFMove(buffer), address, options](IPC::Connection& connection) {
+ IPC::DataReference data(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
+ String srtpAuthKey = authKey(options);
+ Messages::NetworkRTCSocket::SendTo message(data, RTCNetwork::SocketAddress(address), options.packet_id, options.packet_time_params.rtp_sendtime_extension_id, srtpAuthKey, options.packet_time_params.srtp_packet_index, options.dscp);
+ connection.send(WTFMove(message), identifier);
+ });
+ return size;
+}
+
+int LibWebRTCSocket::Close()
+{
+ auto identifier = this->identifier();
+ sendOnMainThread([identifier](IPC::Connection& connection) {
+ connection.send(Messages::NetworkRTCSocket::Close(), identifier);
+ });
+ return 0;
+}
+
+int LibWebRTCSocket::GetOption(rtc::Socket::Option option, int* value)
+{
+ ASSERT(option < MAX_SOCKET_OPTION);
+ int storedValue = m_options[option];
+ if (storedValue != -1)
+ *value = m_options[option];
+ return 0;
+}
+
+int LibWebRTCSocket::SetOption(rtc::Socket::Option option, int value)
+{
+ ASSERT(option < MAX_SOCKET_OPTION);
+
+ m_options[option] = value;
+
+ auto identifier = this->identifier();
+ sendOnMainThread([identifier, option, value](IPC::Connection& connection) {
+ connection.send(Messages::NetworkRTCSocket::SetOption(option, value), identifier);
+ });
+ return 0;
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.h b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.h
new file mode 100644
index 000000000..957437f8d
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include <WebCore/LibWebRTCProvider.h>
+#include <webrtc/base/asyncpacketsocket.h>
+#include <wtf/Deque.h>
+#include <wtf/Forward.h>
+
+namespace IPC {
+class Connection;
+class DataReference;
+class Decoder;
+}
+
+namespace WebCore {
+class SharedBuffer;
+}
+
+namespace WebKit {
+
+class LibWebRTCSocketFactory;
+
+class LibWebRTCSocket final : public rtc::AsyncPacketSocket {
+public:
+ enum class Type { UDP, ServerTCP, ClientTCP };
+
+ LibWebRTCSocket(LibWebRTCSocketFactory&, uint64_t identifier, Type, const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress);
+ ~LibWebRTCSocket();
+
+ uint64_t identifier() const { return m_identifier; }
+ const rtc::SocketAddress& localAddress() const { return m_localAddress; }
+ const rtc::SocketAddress& remoteAddress() const { return m_remoteAddress; }
+
+ void setError(int error) { m_error = error; }
+ void setState(State state) { m_state = state; }
+
+private:
+ bool willSend(size_t);
+
+ friend class WebRTCSocket;
+ void signalReadPacket(const WebCore::SharedBuffer&, rtc::SocketAddress&&, int64_t);
+ void signalSentPacket(int, int64_t);
+ void signalAddressReady(const rtc::SocketAddress&);
+ void signalConnect();
+ void signalClose(int);
+
+ // AsyncPacketSocket API
+ int GetError() const final { return m_error; }
+ void SetError(int error) final { setError(error); }
+ rtc::SocketAddress GetLocalAddress() const final;
+ rtc::SocketAddress GetRemoteAddress() const final;
+ int Send(const void *pv, size_t cb, const rtc::PacketOptions& options) final { return SendTo(pv, cb, m_remoteAddress, options); }
+ int SendTo(const void *, size_t, const rtc::SocketAddress&, const rtc::PacketOptions&) final;
+ int Close() final;
+ State GetState() const final { return m_state; }
+ int GetOption(rtc::Socket::Option, int*) final;
+ int SetOption(rtc::Socket::Option, int) final;
+
+ LibWebRTCSocketFactory& m_factory;
+ uint64_t m_identifier { 0 };
+ Type m_type;
+ rtc::SocketAddress m_localAddress;
+ rtc::SocketAddress m_remoteAddress;
+
+ int m_error { 0 };
+ State m_state { STATE_BINDING };
+
+ static const unsigned MAX_SOCKET_OPTION { rtc::Socket::OPT_RTP_SENDTIME_EXTN_ID + 1 };
+ int m_options[MAX_SOCKET_OPTION];
+
+ Deque<size_t> m_beingSentPacketSizes;
+ size_t m_availableSendingBytes { 65536 };
+ bool m_shouldSignalReadyToSend { false };
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp
new file mode 100644
index 000000000..ccd8d60d1
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LibWebRTCSocketFactory.h"
+
+#if USE(LIBWEBRTC)
+
+#include "NetworkProcessConnection.h"
+#include "NetworkRTCMonitorMessages.h"
+#include "NetworkRTCProviderMessages.h"
+#include "WebProcess.h"
+#include "WebRTCSocket.h"
+#include <wtf/MainThread.h>
+
+namespace WebKit {
+
+uint64_t LibWebRTCSocketFactory::s_uniqueSocketIdentifier = 0;
+uint64_t LibWebRTCSocketFactory::s_uniqueResolverIdentifier = 0;
+
+rtc::AsyncPacketSocket* LibWebRTCSocketFactory::CreateServerTcpSocket(const rtc::SocketAddress& address, uint16_t minPort, uint16_t maxPort, int options)
+{
+ auto socket = std::make_unique<LibWebRTCSocket>(*this, ++s_uniqueSocketIdentifier, LibWebRTCSocket::Type::ServerTCP, address, rtc::SocketAddress());
+ m_sockets.set(socket->identifier(), socket.get());
+
+ callOnMainThread([identifier = socket->identifier(), address = RTCNetwork::isolatedCopy(address), minPort, maxPort, options]() {
+ if (!WebProcess::singleton().networkConnection().connection().send(Messages::NetworkRTCProvider::CreateServerTCPSocket(identifier, RTCNetwork::SocketAddress(address), minPort, maxPort, options), 0)) {
+ // FIXME: Set error back to socket
+ return;
+ }
+
+ });
+
+ return socket.release();
+}
+
+rtc::AsyncPacketSocket* LibWebRTCSocketFactory::CreateUdpSocket(const rtc::SocketAddress& address, uint16_t minPort, uint16_t maxPort)
+{
+ auto socket = std::make_unique<LibWebRTCSocket>(*this, ++s_uniqueSocketIdentifier, LibWebRTCSocket::Type::UDP, address, rtc::SocketAddress());
+ m_sockets.set(socket->identifier(), socket.get());
+
+ callOnMainThread([identifier = socket->identifier(), address = RTCNetwork::isolatedCopy(address), minPort, maxPort]() {
+ if (!WebProcess::singleton().networkConnection().connection().send(Messages::NetworkRTCProvider::CreateUDPSocket(identifier, RTCNetwork::SocketAddress(address), minPort, maxPort), 0)) {
+ // FIXME: Set error back to socket
+ return;
+ }
+ });
+ return socket.release();
+}
+
+rtc::AsyncPacketSocket* LibWebRTCSocketFactory::CreateClientTcpSocket(const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress, const rtc::ProxyInfo&, const std::string&, int options)
+{
+ auto socket = std::make_unique<LibWebRTCSocket>(*this, ++s_uniqueSocketIdentifier, LibWebRTCSocket::Type::ClientTCP, localAddress, remoteAddress);
+ socket->setState(LibWebRTCSocket::STATE_CONNECTING);
+ m_sockets.set(socket->identifier(), socket.get());
+
+ callOnMainThread([identifier = socket->identifier(), localAddress = RTCNetwork::isolatedCopy(localAddress), remoteAddress = RTCNetwork::isolatedCopy(remoteAddress), options]() {
+ if (!WebProcess::singleton().networkConnection().connection().send(Messages::NetworkRTCProvider::CreateClientTCPSocket(identifier, RTCNetwork::SocketAddress(localAddress), RTCNetwork::SocketAddress(remoteAddress), options), 0)) {
+ // FIXME: Set error back to socket
+ return;
+ }
+ });
+
+ return socket.release();
+}
+
+void LibWebRTCSocketFactory::detach(LibWebRTCSocket& socket)
+{
+ ASSERT(m_sockets.contains(socket.identifier()));
+ m_sockets.remove(socket.identifier());
+}
+
+rtc::AsyncResolverInterface* LibWebRTCSocketFactory::CreateAsyncResolver()
+{
+ auto resolver = std::make_unique<LibWebRTCResolver>(++s_uniqueResolverIdentifier);
+ auto* resolverPointer = resolver.get();
+ m_resolvers.set(resolverPointer->identifier(), WTFMove(resolver));
+ return resolverPointer;
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h
new file mode 100644
index 000000000..023f17561
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCResolver.h"
+#include "LibWebRTCSocket.h"
+#include <WebCore/LibWebRTCMacros.h>
+#include <webrtc/base/nethelpers.h>
+#include <webrtc/p2p/base/packetsocketfactory.h>
+#include <wtf/HashMap.h>
+
+namespace WebKit {
+
+class LibWebRTCSocketFactory final : public rtc::PacketSocketFactory {
+public:
+ LibWebRTCSocketFactory() { }
+
+ void detach(LibWebRTCSocket&);
+
+ LibWebRTCSocket* socket(uint64_t identifier) { return m_sockets.get(identifier); }
+ LibWebRTCResolver* resolver(uint64_t identifier) { return m_resolvers.get(identifier); }
+
+ std::unique_ptr<LibWebRTCResolver> takeResolver(uint64_t identifier) { return m_resolvers.take(identifier); }
+
+private:
+ rtc::AsyncPacketSocket* CreateUdpSocket(const rtc::SocketAddress&, uint16_t minPort, uint16_t maxPort) final;
+ rtc::AsyncPacketSocket* CreateServerTcpSocket(const rtc::SocketAddress&, uint16_t min_port, uint16_t max_port, int options) final;
+ rtc::AsyncPacketSocket* CreateClientTcpSocket(const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress, const rtc::ProxyInfo&, const std::string&, int options);
+ rtc::AsyncResolverInterface* CreateAsyncResolver() final;
+
+ // We cannot own sockets, clients of the factory are responsible to free them.
+ HashMap<uint64_t, LibWebRTCSocket*> m_sockets;
+ static uint64_t s_uniqueSocketIdentifier;
+
+ // We can own resolvers as we control their Destroy method.
+ HashMap<uint64_t, std::unique_ptr<LibWebRTCResolver>> m_resolvers;
+ static uint64_t s_uniqueResolverIdentifier;
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.cpp b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.cpp
new file mode 100644
index 000000000..9eac494bb
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebRTCMonitor.h"
+
+#if USE(LIBWEBRTC)
+
+#include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkProcessConnection.h"
+#include "NetworkRTCMonitorMessages.h"
+#include "WebProcess.h"
+#include <WebCore/LibWebRTCMacros.h>
+#include <webrtc/base/nethelpers.h>
+#include <wtf/MainThread.h>
+
+namespace WebKit {
+
+static inline void sendOnMainThread(Function<void(IPC::Connection&)>&& callback)
+{
+ callOnMainThread([callback = WTFMove(callback)]() {
+ callback(WebProcess::singleton().networkConnection().connection());
+ });
+}
+
+void WebRTCMonitor::StartUpdating()
+{
+ if (m_clientCount) {
+ // Need to signal new client that we already have the network list, let's do it asynchronously
+ if (m_receivedNetworkList) {
+ WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this] {
+ SignalNetworksChanged();
+ });
+ }
+ } else {
+ m_receivedNetworkList = false;
+ sendOnMainThread([](IPC::Connection& connection) {
+ connection.send(Messages::NetworkRTCMonitor::StartUpdating(), 0);
+ });
+ }
+ ++m_clientCount;
+}
+
+void WebRTCMonitor::StopUpdating()
+{
+ ASSERT(m_clientCount);
+ if (--m_clientCount)
+ return;
+
+ sendOnMainThread([](IPC::Connection& connection) {
+ connection.send(Messages::NetworkRTCMonitor::StopUpdating(), 0);
+ });
+}
+
+void WebRTCMonitor::networksChanged(const Vector<RTCNetwork>& networks, const RTCNetwork::IPAddress& ipv4, const RTCNetwork::IPAddress& ipv6)
+{
+ // No need to protect 'this' as it has the lifetime of LibWebRTC which has the lifetime of the web process.
+ WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this, networks, ipv4, ipv6] {
+ std::vector<rtc::Network*> networkList(networks.size());
+ for (size_t index = 0; index < networks.size(); ++index)
+ networkList[index] = new rtc::Network(networks[index].value());
+
+ bool forceSignaling = !m_receivedNetworkList;
+ m_receivedNetworkList = true;
+
+ bool hasChanged;
+ set_default_local_addresses(ipv4.value, ipv6.value);
+ MergeNetworkList(networkList, &hasChanged);
+ if (hasChanged || forceSignaling)
+ SignalNetworksChanged();
+
+ });
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.h b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.h
new file mode 100644
index 000000000..dc1524911
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "RTCNetwork.h"
+#include <WebCore/LibWebRTCProvider.h>
+#include <wtf/Vector.h>
+
+namespace IPC {
+class Connection;
+class Decoder;
+}
+
+namespace WebKit {
+
+struct NetworksChangedData;
+
+class WebRTCMonitor final : public rtc::NetworkManagerBase {
+public:
+ WebRTCMonitor() = default;
+
+ void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
+
+private:
+ void networksChanged(const Vector<RTCNetwork>& networkList, const RTCNetwork::IPAddress&, const RTCNetwork::IPAddress&);
+
+ void StartUpdating() final;
+ void StopUpdating() final;
+
+ unsigned m_clientCount { 0 };
+ bool m_receivedNetworkList { false };
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.messages.in b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.messages.in
new file mode 100644
index 000000000..eae177047
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCMonitor.messages.in
@@ -0,0 +1,29 @@
+# Copyright (C) 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
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if USE(LIBWEBRTC)
+
+messages -> WebRTCMonitor {
+ void NetworksChanged(Vector<WebKit::RTCNetwork> networks, WebKit::RTCNetwork::IPAddress defaultIPV4Address, WebKit::RTCNetwork::IPAddress defaultIPV6Address)
+}
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.cpp b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.cpp
new file mode 100644
index 000000000..b4bd8711e
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebRTCResolver.h"
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCResolver.h"
+#include "LibWebRTCSocketFactory.h"
+#include <WebCore/LibWebRTCProvider.h>
+#include <wtf/Function.h>
+
+namespace WebKit {
+
+WebRTCResolver::WebRTCResolver(LibWebRTCSocketFactory& socketFactory, uint64_t identifier)
+ : m_socketFactory(socketFactory)
+ , m_identifier(identifier)
+{
+}
+
+void WebRTCResolver::setResolvedAddress(const Vector<RTCNetwork::IPAddress>& addresses)
+{
+ auto identifier = m_identifier;
+ auto& factory = m_socketFactory;
+
+ Vector<rtc::IPAddress> rtcAddresses;
+ rtcAddresses.reserveInitialCapacity(addresses.size());
+ for (auto& address : addresses)
+ rtcAddresses.uncheckedAppend(address.value);
+
+ WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier, rtcAddresses = WTFMove(rtcAddresses)]() {
+ auto* resolver = factory.resolver(identifier);
+ if (!resolver)
+ return;
+ resolver->setResolvedAddress(rtcAddresses);
+ });
+}
+
+void WebRTCResolver::resolvedAddressError(int error)
+{
+ auto identifier = m_identifier;
+ auto& factory = m_socketFactory;
+ WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier, error]() {
+ auto* resolver = factory.resolver(identifier);
+ if (!resolver)
+ return;
+ resolver->setError(error);
+ });
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.h b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.h
new file mode 100644
index 000000000..1b82eec0a
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "RTCNetwork.h"
+#include <wtf/Vector.h>
+
+namespace IPC {
+class Connection;
+class Decoder;
+}
+
+namespace WebKit {
+
+class LibWebRTCSocketFactory;
+
+class WebRTCResolver {
+public:
+ WebRTCResolver(LibWebRTCSocketFactory&, uint64_t);
+
+ void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
+
+private:
+ void setResolvedAddress(const Vector<RTCNetwork::IPAddress>&);
+ void resolvedAddressError(int);
+
+ LibWebRTCSocketFactory& m_socketFactory;
+ uint64_t m_identifier { 0 };
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.messages.in b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.messages.in
new file mode 100644
index 000000000..430c8d6b8
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCResolver.messages.in
@@ -0,0 +1,30 @@
+# Copyright (C) 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
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if USE(LIBWEBRTC)
+
+messages -> WebRTCResolver {
+ void SetResolvedAddress(Vector<WebKit::RTCNetwork::IPAddress> addresses)
+ void ResolvedAddressError(int error)
+}
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.cpp b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.cpp
new file mode 100644
index 000000000..d6dce48aa
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebRTCSocket.h"
+
+#if USE(LIBWEBRTC)
+
+#include "DataReference.h"
+#include "LibWebRTCSocket.h"
+#include "LibWebRTCSocketFactory.h"
+#include "NetworkRTCSocketMessages.h"
+#include <WebCore/SharedBuffer.h>
+#include <wtf/Function.h>
+
+namespace WebKit {
+
+void WebRTCSocket::signalOnNetworkThread(LibWebRTCSocketFactory& factory, uint64_t identifier, Function<void(LibWebRTCSocket&)>&& callback)
+{
+ // factory is staying valid during the process lifetime.
+ WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([&factory, identifier, callback = WTFMove(callback)]() {
+ auto* socket = factory.socket(identifier);
+ if (!socket)
+ return;
+ callback(*socket);
+ });
+}
+
+WebRTCSocket::WebRTCSocket(LibWebRTCSocketFactory& factory, uint64_t identifier)
+ : m_factory(factory)
+ , m_identifier(identifier)
+{
+}
+
+void WebRTCSocket::signalAddressReady(const RTCNetwork::SocketAddress& address)
+{
+ signalOnNetworkThread(m_factory, m_identifier, [address](LibWebRTCSocket& socket) {
+ socket.signalAddressReady(address.value);
+ });
+}
+
+void WebRTCSocket::signalReadPacket(const IPC::DataReference& data, const RTCNetwork::IPAddress& address, uint16_t port, int64_t timestamp)
+{
+ auto buffer = WebCore::SharedBuffer::create(data.data(), data.size());
+ signalOnNetworkThread(m_factory, m_identifier, [buffer = WTFMove(buffer), address, port, timestamp](LibWebRTCSocket& socket) {
+ socket.signalReadPacket(buffer.get(), rtc::SocketAddress(address.value, port), timestamp);
+ });
+}
+
+void WebRTCSocket::signalSentPacket(int rtcPacketID, int64_t sendTimeMs)
+{
+ signalOnNetworkThread(m_factory, m_identifier, [rtcPacketID, sendTimeMs](LibWebRTCSocket& socket) {
+ socket.signalSentPacket(rtcPacketID, sendTimeMs);
+ });
+}
+
+void WebRTCSocket::signalConnect()
+{
+ signalOnNetworkThread(m_factory, m_identifier, [](LibWebRTCSocket& socket) {
+ socket.signalConnect();
+ });
+}
+
+void WebRTCSocket::signalClose(int error)
+{
+ signalOnNetworkThread(m_factory, m_identifier, [error](LibWebRTCSocket& socket) {
+ socket.signalClose(error);
+ });
+}
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.h b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.h
new file mode 100644
index 000000000..d26d60f24
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "RTCNetwork.h"
+#include <wtf/Function.h>
+
+namespace IPC {
+class Connection;
+class DataReference;
+class Decoder;
+}
+
+namespace WebKit {
+
+class LibWebRTCSocket;
+class LibWebRTCSocketFactory;
+
+class WebRTCSocket {
+public:
+ WebRTCSocket(LibWebRTCSocketFactory&, uint64_t);
+
+ void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
+
+ static void signalOnNetworkThread(LibWebRTCSocketFactory&, uint64_t, Function<void(LibWebRTCSocket&)>&&);
+
+private:
+ void signalReadPacket(const IPC::DataReference&, const RTCNetwork::IPAddress&, uint16_t port, int64_t);
+ void signalSentPacket(int, int64_t);
+ void signalAddressReady(const RTCNetwork::SocketAddress&);
+ void signalConnect();
+ void signalClose(int);
+
+ LibWebRTCSocketFactory& m_factory;
+ uint64_t m_identifier { 0 };
+};
+
+} // namespace WebKit
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.messages.in b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.messages.in
new file mode 100644
index 000000000..426d6d192
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.messages.in
@@ -0,0 +1,33 @@
+# Copyright (C) 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
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if USE(LIBWEBRTC)
+
+messages -> WebRTCSocket {
+ SignalReadPacket(IPC::DataReference data, WebKit::RTCNetwork::IPAddress address, uint16_t port, int64_t timestamp)
+ SignalSentPacket(int packetSize, int64_t timestamp)
+ SignalAddressReady(WebKit::RTCNetwork::SocketAddress address)
+ SignalConnect()
+ SignalClose(int error)
+}
+
+#endif // USE(LIBWEBRTC)