Commit 87c0b543 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

WebSocket: Add OffMainThreadWebSocket flag and run tests with it

This CL adds the OffMainThreadWebSocket flag to enable the off-main-thread
WebSocket for WebWorkers. With the flag, WebSocket connection requests on worker
threads are not routed via the main thread. Also, this CL runs layout tests and
web-platform-tests with the flag. Failing tests will be fixed by following CLs.

Design Doc: https://docs.google.com/document/d/1ya3sfQ5YsDtHSCXn2renQjCxM4AWeYlhehw8Skppsr8/edit?usp=sharing

Bug: 825740
Change-Id: I9fe5a98632a02eb97c0d32d63917088af7f69994
Reviewed-on: https://chromium-review.googlesource.com/979835
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547726}
parent 760ab2a1
......@@ -436,6 +436,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
// Make srcset on link rel=preload work with SignedHTTPExchange flag too.
if (base::FeatureList::IsEnabled(features::kSignedHTTPExchange))
WebRuntimeFeatures::EnablePreloadImageSrcSetEnabled(true);
WebRuntimeFeatures::EnableOffMainThreadWebSocket(
base::FeatureList::IsEnabled(features::kOffMainThreadWebSocket));
};
} // namespace content
......@@ -208,6 +208,7 @@
"blink::mojom::NotificationService",
"blink::mojom::PermissionService",
"blink::mojom::QuotaDispatcherHost",
"network::mojom::WebSocket",
"payments::mojom::PaymentManager",
"shape_detection::mojom::BarcodeDetection",
"shape_detection::mojom::FaceDetectionProvider",
......
......@@ -231,6 +231,10 @@ const base::Feature kNotificationContentImage{"NotificationContentImage",
const base::Feature kNotificationsWithMojo{"NotificationsWithMojo",
base::FEATURE_DISABLED_BY_DEFAULT};
// Off-main-thread WebSocket. See https://crbug.com/825740
const base::Feature kOffMainThreadWebSocket{"OffMainThreadWebSocket",
base::FEATURE_DISABLED_BY_DEFAULT};
// Origin Manifest. See crbug.com/751996
const base::Feature kOriginManifest{"OriginManifest",
base::FEATURE_DISABLED_BY_DEFAULT};
......
......@@ -61,6 +61,7 @@ CONTENT_EXPORT extern const base::Feature kNavigationMojoResponse;
CONTENT_EXPORT extern const base::Feature kNetworkServiceInProcess;
CONTENT_EXPORT extern const base::Feature kNotificationContentImage;
CONTENT_EXPORT extern const base::Feature kNotificationsWithMojo;
CONTENT_EXPORT extern const base::Feature kOffMainThreadWebSocket;
CONTENT_EXPORT extern const base::Feature kOriginManifest;
CONTENT_EXPORT extern const base::Feature kOriginTrials;
CONTENT_EXPORT extern const base::Feature kPassiveDocumentEventListeners;
......
......@@ -3361,3 +3361,14 @@ crbug.com/826936 external/wpt/webauthn/getcredential-badargs-userverification.ht
crbug.com/826936 external/wpt/webauthn/getcredential-extensions.https.html [ Pass Timeout ]
crbug.com/826936 external/wpt/webauthn/getcredential-passing.https.html [ Pass Timeout ]
crbug.com/826936 external/wpt/webauthn/getcredential-timeout.https.html [ Pass Timeout ]
crbug.com/825740 virtual/off-main-thread-websocket/external/wpt/websockets/Create-Secure-extensions-empty.htm [ Timeout ]
crbug.com/825740 virtual/off-main-thread-websocket/external/wpt/websockets/constructor/014.html?wss [ Timeout ]
crbug.com/825740 virtual/off-main-thread-websocket/external/wpt/websockets/cookies/006.html?wss [ Failure ]
crbug.com/825740 virtual/off-main-thread-websocket/external/wpt/websockets/keeping-connection-open/001.html?wss [ Timeout ]
crbug.com/825740 virtual/off-main-thread-websocket/external/wpt/websockets/opening-handshake/003-sets-origin.worker.html [ Timeout ]
crbug.com/825740 virtual/off-main-thread-websocket/external/wpt/websockets/opening-handshake/005.html?wss [ Failure ]
crbug.com/825740 virtual/off-main-thread-websocket/http/tests/security/mixedContent/websocket/insecure-websocket-in-secure-page-worker.html [ Failure ]
crbug.com/825740 virtual/off-main-thread-websocket/http/tests/websocket/multiple-connections-throttled.html [ Timeout ]
crbug.com/825740 virtual/off-main-thread-websocket/http/tests/websocket/workers/close-code-and-reason.html [ Failure ]
crbug.com/825740 virtual/off-main-thread-websocket/http/tests/websocket/workers/close.html [ Failure ]
......@@ -623,5 +623,20 @@
"prefix": "picture-in-picture",
"base": "media/picture-in-picture",
"args": ["--enable-features=PictureInPicture,UseSurfaceLayerForVideo"]
},
{
"prefix": "off-main-thread-websocket",
"base": "external/wpt/websockets",
"args": ["--enable-features=OffMainThreadWebSocket"]
},
{
"prefix": "off-main-thread-websocket",
"base": "http/tests/websocket",
"args": ["--enable-features=OffMainThreadWebSocket"]
},
{
"prefix": "off-main-thread-websocket",
"base": "http/tests/security/mixedContent/websocket",
"args": ["--enable-features=OffMainThreadWebSocket"]
}
]
This directory is for testing off-main-thread WebSocket.
Tracking bug: https://crbug.com/825740
This directory is for testing off-main-thread WebSocket.
Tracking bug: https://crbug.com/825740
This directory is for testing off-main-thread WebSocket.
Tracking bug: https://crbug.com/825740
......@@ -13,6 +13,7 @@
#include "core/inspector/ConsoleMessage.h"
#include "core/loader/DocumentLoader.h"
#include "core/workers/WorkerOrWorkletGlobalScope.h"
#include "platform/runtime_enabled_features.h"
#include "platform/weborigin/KURL.h"
#include "platform/wtf/text/StringBuilder.h"
#include "public/platform/TaskType.h"
......@@ -68,8 +69,11 @@ bool SubresourceFilter::AllowLoad(
}
bool SubresourceFilter::AllowWebSocketConnection(const KURL& url) {
// Currently WebSocket is handled via document on the main thread.
DCHECK(execution_context_->IsDocument());
// WebSocket is handled via document on the main thread unless the
// experimental off-main-thread WebSocket flag is enabled. See
// https://crbug.com/825740 for the details of the off-main-thread WebSocket.
DCHECK(execution_context_->IsDocument() ||
RuntimeEnabledFeatures::OffMainThreadWebSocketEnabled());
WebDocumentSubresourceFilter::LoadPolicy load_policy =
subresource_filter_->GetLoadPolicyForWebSocketConnect(url);
......
......@@ -71,13 +71,14 @@ class WorkerThreadableLoadingContext : public ThreadableLoadingContext {
Member<WorkerGlobalScope> worker_global_scope_;
};
ThreadableLoadingContext* ThreadableLoadingContext::Create(Document& document) {
return new DocumentThreadableLoadingContext(document);
}
ThreadableLoadingContext* ThreadableLoadingContext::Create(
WorkerGlobalScope& worker_global_scope) {
return new WorkerThreadableLoadingContext(worker_global_scope);
ExecutionContext& context) {
if (context.IsDocument())
return new DocumentThreadableLoadingContext(ToDocument(context));
if (context.IsWorkerGlobalScope())
return new WorkerThreadableLoadingContext(ToWorkerGlobalScope(context));
NOTREACHED();
return nullptr;
}
BaseFetchContext* ThreadableLoadingContext::GetFetchContext() {
......
......@@ -13,10 +13,8 @@
namespace blink {
class BaseFetchContext;
class Document;
class ExecutionContext;
class ResourceFetcher;
class WorkerGlobalScope;
// A convenient holder for various contexts associated with the loading
// activity. This should be accessed only from the thread where the loading
......@@ -24,8 +22,7 @@ class WorkerGlobalScope;
class CORE_EXPORT ThreadableLoadingContext
: public GarbageCollected<ThreadableLoadingContext> {
public:
static ThreadableLoadingContext* Create(Document&);
static ThreadableLoadingContext* Create(WorkerGlobalScope&);
static ThreadableLoadingContext* Create(ExecutionContext&);
ThreadableLoadingContext() = default;
virtual ~ThreadableLoadingContext() = default;
......
......@@ -70,11 +70,11 @@ class MODULES_EXPORT DocumentWebSocketChannel final
// In the usual case, they are set automatically and you don't have to
// pass it.
static DocumentWebSocketChannel* Create(
Document* document,
ExecutionContext* context,
WebSocketChannelClient* client,
std::unique_ptr<SourceLocation> location) {
DCHECK(document);
return Create(ThreadableLoadingContext::Create(*document), client,
DCHECK(context);
return Create(ThreadableLoadingContext::Create(*context), client,
std::move(location));
}
static DocumentWebSocketChannel* Create(ThreadableLoadingContext*,
......
......@@ -39,6 +39,7 @@
#include "modules/websockets/DocumentWebSocketChannel.h"
#include "modules/websockets/WebSocketChannelClient.h"
#include "modules/websockets/WorkerWebSocketChannel.h"
#include "platform/runtime_enabled_features.h"
namespace blink {
......@@ -49,15 +50,18 @@ WebSocketChannel* WebSocketChannel::Create(ExecutionContext* context,
std::unique_ptr<SourceLocation> location = SourceLocation::Capture(context);
if (context->IsWorkerGlobalScope()) {
WorkerGlobalScope* worker_global_scope = ToWorkerGlobalScope(context);
return WorkerWebSocketChannel::Create(*worker_global_scope, client,
std::move(location));
// When the off-main-thread WebSocket flag is enabled, web workers use
// DocumentWebSocketChannel as opposed to WorkerWebSocketChannel. See
// https://crbug.com/825740
if (context->IsDocument() ||
RuntimeEnabledFeatures::OffMainThreadWebSocketEnabled()) {
return DocumentWebSocketChannel::Create(context, client,
std::move(location));
}
Document* document = ToDocument(context);
return DocumentWebSocketChannel::Create(document, client,
std::move(location));
WorkerGlobalScope* worker_global_scope = ToWorkerGlobalScope(context);
return WorkerWebSocketChannel::Create(*worker_global_scope, client,
std::move(location));
}
} // namespace blink
......@@ -506,4 +506,8 @@ void WebRuntimeFeatures::EnableMojoBlobURLs(bool enable) {
RuntimeEnabledFeatures::SetMojoBlobURLsEnabled(enable);
}
void WebRuntimeFeatures::EnableOffMainThreadWebSocket(bool enable) {
RuntimeEnabledFeatures::SetOffMainThreadWebSocketEnabled(enable);
}
} // namespace blink
......@@ -790,6 +790,9 @@
name: "NullableDocumentDomain",
status: "experimental",
},
{
name: "OffMainThreadWebSocket",
},
{
name: "OffscreenCanvas",
status: "experimental",
......
......@@ -187,6 +187,7 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableCodeCacheAfterExecute(bool);
BLINK_PLATFORM_EXPORT static void EnableUnifiedTouchAdjustment(bool);
BLINK_PLATFORM_EXPORT static void EnableMojoBlobURLs(bool);
BLINK_PLATFORM_EXPORT static void EnableOffMainThreadWebSocket(bool);
private:
WebRuntimeFeatures();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment