- Revision
- 256890
- Author
- you...@apple.com
- Date
- 2020-02-18 17:06:26 -0800 (Tue, 18 Feb 2020)
Log Message
Add support for WebInspector WebSocket handshake in the new WebSocket code path
https://bugs.webkit.org/show_bug.cgi?id=207913
Reviewed by Alex Christensen.
Whenever creating the WebSocketTask, pass the request actually used for handshake to the WebProcess.
Whenever being connected, pass the request actually used for handshake to the WebProcess.
In case of failure before the web socket is connected, we send the response if we can get a non null from the task.
* NetworkProcess/NetworkSocketChannel.cpp:
(WebKit::NetworkSocketChannel::didSendHandshakeRequest):
(WebKit::NetworkSocketChannel::didReceiveHandshakeResponse):
* NetworkProcess/NetworkSocketChannel.h:
* NetworkProcess/cocoa/WebSocketTaskCocoa.mm:
(WebKit::WebSocketTask::WebSocketTask):
(WebKit::WebSocketTask::didConnect):
* WebProcess/Network/WebSocketChannel.cpp:
(WebKit::WebSocketChannel::connect):
(WebKit::WebSocketChannel::didConnect):
(WebKit::WebSocketChannel::didSendHandshakeRequest):
(WebKit::WebSocketChannel::didReceiveHandshakeResponse):
* WebProcess/Network/WebSocketChannel.h:
* WebProcess/Network/WebSocketChannel.messages.in:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (256889 => 256890)
--- trunk/Source/WebKit/ChangeLog 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/ChangeLog 2020-02-19 01:06:26 UTC (rev 256890)
@@ -1,3 +1,29 @@
+2020-02-18 Youenn Fablet <you...@apple.com>
+
+ Add support for WebInspector WebSocket handshake in the new WebSocket code path
+ https://bugs.webkit.org/show_bug.cgi?id=207913
+
+ Reviewed by Alex Christensen.
+
+ Whenever creating the WebSocketTask, pass the request actually used for handshake to the WebProcess.
+ Whenever being connected, pass the request actually used for handshake to the WebProcess.
+ In case of failure before the web socket is connected, we send the response if we can get a non null from the task.
+
+ * NetworkProcess/NetworkSocketChannel.cpp:
+ (WebKit::NetworkSocketChannel::didSendHandshakeRequest):
+ (WebKit::NetworkSocketChannel::didReceiveHandshakeResponse):
+ * NetworkProcess/NetworkSocketChannel.h:
+ * NetworkProcess/cocoa/WebSocketTaskCocoa.mm:
+ (WebKit::WebSocketTask::WebSocketTask):
+ (WebKit::WebSocketTask::didConnect):
+ * WebProcess/Network/WebSocketChannel.cpp:
+ (WebKit::WebSocketChannel::connect):
+ (WebKit::WebSocketChannel::didConnect):
+ (WebKit::WebSocketChannel::didSendHandshakeRequest):
+ (WebKit::WebSocketChannel::didReceiveHandshakeResponse):
+ * WebProcess/Network/WebSocketChannel.h:
+ * WebProcess/Network/WebSocketChannel.messages.in:
+
2020-02-18 Chris Dumez <cdu...@apple.com>
Do not eagerly launch WebProcess when WKPagePostMessageToInjectedBundle() is called
Modified: trunk/Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp (256889 => 256890)
--- trunk/Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp 2020-02-19 01:06:26 UTC (rev 256890)
@@ -123,6 +123,17 @@
send(Messages::WebSocketChannel::DidReceiveMessageError { errorMessage });
}
+void NetworkSocketChannel::didSendHandshakeRequest(ResourceRequest&& request)
+{
+ send(Messages::WebSocketChannel::DidSendHandshakeRequest { request });
+}
+
+void NetworkSocketChannel::didReceiveHandshakeResponse(ResourceResponse&& response)
+{
+ response.sanitizeHTTPHeaderFields(ResourceResponse::SanitizationType::CrossOriginSafe);
+ send(Messages::WebSocketChannel::DidReceiveHandshakeResponse { response });
+}
+
IPC::Connection* NetworkSocketChannel::messageSenderConnection() const
{
return &m_connectionToWebProcess.connection();
Modified: trunk/Source/WebKit/NetworkProcess/NetworkSocketChannel.h (256889 => 256890)
--- trunk/Source/WebKit/NetworkProcess/NetworkSocketChannel.h 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSocketChannel.h 2020-02-19 01:06:26 UTC (rev 256890)
@@ -67,6 +67,8 @@
void didReceiveBinaryData(const uint8_t* data, size_t length);
void didClose(unsigned short code, const String& reason);
void didReceiveMessageError(const String&);
+ void didSendHandshakeRequest(WebCore::ResourceRequest&&);
+ void didReceiveHandshakeResponse(WebCore::ResourceResponse&&);
void sendString(const String&, CompletionHandler<void()>&&);
void sendData(const IPC::DataReference&, CompletionHandler<void()>&&);
Modified: trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.h (256889 => 256890)
--- trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.h 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.h 2020-02-19 01:06:26 UTC (rev 256890)
@@ -68,6 +68,7 @@
NetworkSocketChannel& m_channel;
RetainPtr<NSURLSessionWebSocketTask> m_task;
bool m_receivedDidClose { false };
+ bool m_receivedDidConnect { false };
};
} // namespace WebKit
Modified: trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm (256889 => 256890)
--- trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm 2020-02-19 01:06:26 UTC (rev 256890)
@@ -32,9 +32,13 @@
#import "NetworkSessionCocoa.h"
#import "NetworkSocketChannel.h"
#import <Foundation/NSURLSession.h>
+#import <WebCore/ResourceRequest.h>
+#import <WebCore/ResourceResponse.h>
#import <WebCore/WebSocketChannel.h>
#import <wtf/BlockPtr.h>
+using namespace WebCore;
+
namespace WebKit {
WebSocketTask::WebSocketTask(NetworkSocketChannel& channel, RetainPtr<NSURLSessionWebSocketTask>&& task)
@@ -42,6 +46,7 @@
, m_task(WTFMove(task))
{
readNextMessage();
+ m_channel.didSendHandshakeRequest(ResourceRequest { [m_task currentRequest] });
}
WebSocketTask::~WebSocketTask()
@@ -58,6 +63,13 @@
// If closeCode is not zero, we are closing the connection and didClose will be called for us.
if ([m_task closeCode])
return;
+
+ if (!m_receivedDidConnect) {
+ ResourceResponse response { [m_task response] };
+ if (!response.isNull())
+ m_channel.didReceiveHandshakeResponse(WTFMove(response));
+ }
+
m_channel.didReceiveMessageError([error localizedDescription]);
didClose(WebCore::WebSocketChannel::CloseEventCodeAbnormalClosure, emptyString());
return;
@@ -89,7 +101,9 @@
void WebSocketTask::didConnect(const String& protocol)
{
// FIXME: support extensions.
+ m_receivedDidConnect = true;
m_channel.didConnect(protocol, { });
+ m_channel.didReceiveHandshakeResponse(ResourceResponse { [m_task response] });
}
void WebSocketTask::didClose(unsigned short code, const String& reason)
Modified: trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp (256889 => 256890)
--- trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp 2020-02-19 01:06:26 UTC (rev 256890)
@@ -115,8 +115,6 @@
m_client->didUpgradeURL();
m_inspector.didCreateWebSocket(m_document.get(), url);
- // FIXME: Get the real request from networking process
- m_inspector.willSendWebSocketHandshakeRequest(m_document.get(), *request);
MessageSender::send(Messages::NetworkConnectionToWebProcess::CreateSocketChannel { *request, protocol, m_identifier });
return ConnectStatus::OK;
@@ -244,9 +242,6 @@
return;
}
- // FIXME: Get the real response from networking process
- m_inspector.didReceiveWebSocketHandshakeResponse(m_document.get(), { });
-
m_subprotocol = WTFMove(subprotocol);
m_extensions = WTFMove(extensions);
m_client->didConnect();
@@ -371,4 +366,26 @@
m_pendingTasks.append(WTFMove(task));
}
+void WebSocketChannel::didSendHandshakeRequest(ResourceRequest&& request)
+{
+ if (m_isSuspended) {
+ enqueueTask([this, request = WTFMove(request)]() mutable {
+ didSendHandshakeRequest(WTFMove(request));
+ });
+ return;
+ }
+ m_inspector.willSendWebSocketHandshakeRequest(m_document.get(), request);
+}
+
+void WebSocketChannel::didReceiveHandshakeResponse(ResourceResponse&& response)
+{
+ if (m_isSuspended) {
+ enqueueTask([this, response = WTFMove(response)]() mutable {
+ didReceiveHandshakeResponse(WTFMove(response));
+ });
+ return;
+ }
+ m_inspector.didReceiveWebSocketHandshakeResponse(m_document.get(), response);
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h (256889 => 256890)
--- trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h 2020-02-19 01:06:26 UTC (rev 256890)
@@ -85,6 +85,8 @@
void didReceiveBinaryData(IPC::DataReference&&);
void didClose(unsigned short code, String&&);
void didReceiveMessageError(String&&);
+ void didSendHandshakeRequest(WebCore::ResourceRequest&&);
+ void didReceiveHandshakeResponse(WebCore::ResourceResponse&&);
// MessageSender
IPC::Connection* messageSenderConnection() const final;
Modified: trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.messages.in (256889 => 256890)
--- trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.messages.in 2020-02-19 00:49:13 UTC (rev 256889)
+++ trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.messages.in 2020-02-19 01:06:26 UTC (rev 256890)
@@ -26,4 +26,7 @@
DidReceiveText(String message)
DidReceiveBinaryData(IPC::DataReference data)
DidReceiveMessageError(String errorMessage)
+
+ DidSendHandshakeRequest(WebCore::ResourceRequest request)
+ DidReceiveHandshakeResponse(WebCore::ResourceResponse response)
}