Changeset 274758 in webkit


Ignore:
Timestamp:
Mar 22, 2021 11:29:36 AM (16 months ago)
Author:
youenn@apple.com
Message:

Implement RTCDataChannel transfer out of process
https://bugs.webkit.org/show_bug.cgi?id=223443

Reviewed by Eric Carlson.

Source/WebCore:

Add support for serialization/deserialization of RTCDataChannel information so that it can be MessagePort transfered or transfered to out-of-process contexts like Window or Service Worker.
Add infrastructure for remote sources (that allows to send data or close data channels) and remote handlers which receive messages from out-of-process data channels.

Covered by API tests.

  • Modules/mediastream/DetachedRTCDataChannel.h: Added.

(WebCore::DetachedRTCDataChannel::DetachedRTCDataChannel):
(WebCore::DetachedRTCDataChannel::memoryCost const):
(WebCore::DetachedRTCDataChannel::encode const):
(WebCore::DetachedRTCDataChannel::decode):

  • Modules/mediastream/RTCDataChannel.cpp:

(WebCore::RTCDataChannel::RTCDataChannel):
(WebCore::rtcDataChannelLocalMap):
(WebCore::RTCDataChannel::handlerFromIdentifier):
(WebCore::RTCDataChannel::create):

  • Modules/mediastream/RTCDataChannel.h:
  • Modules/mediastream/RTCDataChannelRemoteHandler.cpp: Added.

(WebCore::RTCDataChannelRemoteHandler::create):
(WebCore::RTCDataChannelRemoteHandler::RTCDataChannelRemoteHandler):
(WebCore::RTCDataChannelRemoteHandler::~RTCDataChannelRemoteHandler):
(WebCore::RTCDataChannelRemoteHandler::didChangeReadyState):
(WebCore::RTCDataChannelRemoteHandler::didReceiveStringData):
(WebCore::RTCDataChannelRemoteHandler::didReceiveRawData):
(WebCore::RTCDataChannelRemoteHandler::didDetectError):
(WebCore::RTCDataChannelRemoteHandler::bufferedAmountIsDecreasing):
(WebCore::RTCDataChannelRemoteHandler::readyToSend):
(WebCore::RTCDataChannelRemoteHandler::setClient):
(WebCore::RTCDataChannelRemoteHandler::sendStringData):
(WebCore::RTCDataChannelRemoteHandler::sendRawData):
(WebCore::RTCDataChannelRemoteHandler::close):

  • Modules/mediastream/RTCDataChannelRemoteHandler.h: Added.
  • Modules/mediastream/RTCDataChannelRemoteSource.cpp: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.

(WebCore::RTCDataChannelRemoteSource::RTCDataChannelRemoteSource):
(WebCore::RTCDataChannelRemoteSource::~RTCDataChannelRemoteSource):

  • Modules/mediastream/RTCDataChannelRemoteSource.h: Added.

(WebCore::RTCDataChannelRemoteSource::create):
(WebCore::RTCDataChannelRemoteSource::sendStringData):
(WebCore::RTCDataChannelRemoteSource::sendRawData):
(WebCore::RTCDataChannelRemoteSource::close):

  • Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:

(WebCore::LibWebRTCDataChannelHandler::postTask):

  • Modules/webaudio/AudioWorkletMessagingProxy.cpp:

(WebCore::AudioWorkletMessagingProxy::createRTCDataChannelRemoteHandlerConnection):

  • Modules/webaudio/AudioWorkletMessagingProxy.h:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/SerializedScriptValue.cpp:

(WebCore::SerializedScriptValue::SerializedScriptValue):

  • bindings/js/SerializedScriptValue.h:

(WebCore::SerializedScriptValue::encode const):
(WebCore::SerializedScriptValue::decode):

  • dom/Document.cpp:

(WebCore::Document::createRTCDataChannelRemoteHandlerConnection):

  • dom/Document.h:
  • dom/ScriptExecutionContext.h:

(WebCore::ScriptExecutionContext::createRTCDataChannelRemoteHandlerConnection):

  • platform/ScriptExecutionContextIdentifier.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelState.h.
  • platform/mediastream/RTCDataChannelHandler.h:

(WebCore::RTCDataChannelInit::encode const):
(WebCore::RTCDataChannelInit::decode):

  • platform/mediastream/RTCDataChannelIdentifier.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.

(WebCore::RTCDataChannelIdentifier::encode const):
(WebCore::RTCDataChannelIdentifier::decode):

  • platform/mediastream/RTCDataChannelRemoteHandlerConnection.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.
  • platform/mediastream/RTCDataChannelRemoteSourceConnection.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.
  • platform/mediastream/RTCDataChannelState.h:
  • platform/mediastream/RTCPriorityType.h:
  • platform/mediastream/libwebrtc/LibWebRTCProvider.h:
  • workers/WorkerGlobalScope.cpp:

(WebCore::WorkerGlobalScope::createRTCDataChannelRemoteHandlerConnection):

  • workers/WorkerGlobalScope.h:
  • workers/WorkerLoaderProxy.h:
  • workers/WorkerMessagingProxy.cpp:

(WebCore::WorkerMessagingProxy::createRTCDataChannelRemoteHandlerConnection):

  • workers/WorkerMessagingProxy.h:
  • workers/service/context/ServiceWorkerThreadProxy.cpp:

(WebCore::ServiceWorkerThreadProxy::createRTCDataChannelRemoteHandlerConnection):

  • workers/service/context/ServiceWorkerThreadProxy.h:

Source/WebKit:

Add support for connecting remote sources to remote data channels.
This is done by connection detached data channels to remote source that will send messages to network process.
Network process then sends to the process in which was reattached the data channel.
Pairing of data channels is done in main thread through connectToSource message.
The data then flows in background threads, network process being the proxy between web processes.
RTCDataChannelRemoteManagerProxy is the forwarding entity in NetworkProcess.
RTCDataChannelRemoteManager is the entity in WebProcess doing the messaging from and to data channels.

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::connectToRTCDataChannelRemoteSource):
(WebKit::NetworkConnectionToWebProcess::registerToRTCDataChannelProxy):
(WebKit::NetworkConnectionToWebProcess::unregisterToRTCDataChannelProxy):

  • NetworkProcess/NetworkConnectionToWebProcess.h:
  • NetworkProcess/NetworkConnectionToWebProcess.messages.in:
  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::rtcDataChannelProxy):

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.cpp: Added.

(WebKit::RTCDataChannelRemoteManagerProxy::RTCDataChannelRemoteManagerProxy):
(WebKit::RTCDataChannelRemoteManagerProxy::registerConnectionToWebProcess):
(WebKit::RTCDataChannelRemoteManagerProxy::unregisterConnectionToWebProcess):
(WebKit::RTCDataChannelRemoteManagerProxy::sendData):
(WebKit::RTCDataChannelRemoteManagerProxy::close):
(WebKit::RTCDataChannelRemoteManagerProxy::changeReadyState):
(WebKit::RTCDataChannelRemoteManagerProxy::receiveData):
(WebKit::RTCDataChannelRemoteManagerProxy::detectError):
(WebKit::RTCDataChannelRemoteManagerProxy::bufferedAmountIsDecreasing):

  • NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.h: Added.
  • NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.messages.in: Added.
  • Sources.txt:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/Network/NetworkProcessConnection.cpp:

(WebKit::NetworkProcessConnection::connectToRTCDataChannelRemoteSource):

  • WebProcess/Network/NetworkProcessConnection.h:
  • WebProcess/Network/NetworkProcessConnection.messages.in:
  • WebProcess/Network/webrtc/LibWebRTCProvider.cpp:

(WebKit::LibWebRTCProvider::createRTCDataChannelRemoteHandlerConnection):

  • WebProcess/Network/webrtc/LibWebRTCProvider.h:
  • WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp: Added.

(WebKit::RTCDataChannelRemoteManager::sharedManager):
(WebKit::RTCDataChannelRemoteManager::RTCDataChannelRemoteManager):
(WebKit::RTCDataChannelRemoteManager::setConnection):
(WebKit::RTCDataChannelRemoteManager::connectToRemoteSource):
(WebKit::RTCDataChannelRemoteManager::remoteHandlerConnection):
(WebKit::RTCDataChannelRemoteManager::remoteSourceConnection):
(WebKit::RTCDataChannelRemoteManager::postTaskToHandler):
(WebKit::RTCDataChannelRemoteManager::sourceFromIdentifier):
(WebKit::RTCDataChannelRemoteManager::sendData):
(WebKit::RTCDataChannelRemoteManager::close):
(WebKit::RTCDataChannelRemoteManager::changeReadyState):
(WebKit::RTCDataChannelRemoteManager::receiveData):
(WebKit::RTCDataChannelRemoteManager::detectError):
(WebKit::RTCDataChannelRemoteManager::bufferedAmountIsDecreasing):
(WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::create):
(WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::RemoteHandlerConnection):
(WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::connectToSource):
(WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::sendData):
(WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::close):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::create):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::RemoteSourceConnection):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didChangeReadyState):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didReceiveStringData):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didReceiveRawData):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didDetectError):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::bufferedAmountIsDecreasing):

  • WebProcess/Network/webrtc/RTCDataChannelRemoteManager.h: Added.
  • WebProcess/Network/webrtc/RTCDataChannelRemoteManager.messages.in: Copied from Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in.
  • WebProcess/Storage/WebSWContextManagerConnection.cpp:

(WebKit::WebSWContextManagerConnection::installServiceWorker):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Location:
trunk
Files:
9 added
45 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r274756 r274758  
     12021-03-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Implement RTCDataChannel transfer out of process
     4        https://bugs.webkit.org/show_bug.cgi?id=223443
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add support for serialization/deserialization of RTCDataChannel information so that it can be MessagePort transfered or transfered to out-of-process contexts like Window or Service Worker.
     9        Add infrastructure for remote sources (that allows to send data or close data channels) and remote handlers which receive messages from out-of-process data channels.
     10
     11        Covered by API tests.
     12
     13        * Modules/mediastream/DetachedRTCDataChannel.h: Added.
     14        (WebCore::DetachedRTCDataChannel::DetachedRTCDataChannel):
     15        (WebCore::DetachedRTCDataChannel::memoryCost const):
     16        (WebCore::DetachedRTCDataChannel::encode const):
     17        (WebCore::DetachedRTCDataChannel::decode):
     18        * Modules/mediastream/RTCDataChannel.cpp:
     19        (WebCore::RTCDataChannel::RTCDataChannel):
     20        (WebCore::rtcDataChannelLocalMap):
     21        (WebCore::RTCDataChannel::handlerFromIdentifier):
     22        (WebCore::RTCDataChannel::create):
     23        * Modules/mediastream/RTCDataChannel.h:
     24        * Modules/mediastream/RTCDataChannelRemoteHandler.cpp: Added.
     25        (WebCore::RTCDataChannelRemoteHandler::create):
     26        (WebCore::RTCDataChannelRemoteHandler::RTCDataChannelRemoteHandler):
     27        (WebCore::RTCDataChannelRemoteHandler::~RTCDataChannelRemoteHandler):
     28        (WebCore::RTCDataChannelRemoteHandler::didChangeReadyState):
     29        (WebCore::RTCDataChannelRemoteHandler::didReceiveStringData):
     30        (WebCore::RTCDataChannelRemoteHandler::didReceiveRawData):
     31        (WebCore::RTCDataChannelRemoteHandler::didDetectError):
     32        (WebCore::RTCDataChannelRemoteHandler::bufferedAmountIsDecreasing):
     33        (WebCore::RTCDataChannelRemoteHandler::readyToSend):
     34        (WebCore::RTCDataChannelRemoteHandler::setClient):
     35        (WebCore::RTCDataChannelRemoteHandler::sendStringData):
     36        (WebCore::RTCDataChannelRemoteHandler::sendRawData):
     37        (WebCore::RTCDataChannelRemoteHandler::close):
     38        * Modules/mediastream/RTCDataChannelRemoteHandler.h: Added.
     39        * Modules/mediastream/RTCDataChannelRemoteSource.cpp: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.
     40        (WebCore::RTCDataChannelRemoteSource::RTCDataChannelRemoteSource):
     41        (WebCore::RTCDataChannelRemoteSource::~RTCDataChannelRemoteSource):
     42        * Modules/mediastream/RTCDataChannelRemoteSource.h: Added.
     43        (WebCore::RTCDataChannelRemoteSource::create):
     44        (WebCore::RTCDataChannelRemoteSource::sendStringData):
     45        (WebCore::RTCDataChannelRemoteSource::sendRawData):
     46        (WebCore::RTCDataChannelRemoteSource::close):
     47        * Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:
     48        (WebCore::LibWebRTCDataChannelHandler::postTask):
     49        * Modules/webaudio/AudioWorkletMessagingProxy.cpp:
     50        (WebCore::AudioWorkletMessagingProxy::createRTCDataChannelRemoteHandlerConnection):
     51        * Modules/webaudio/AudioWorkletMessagingProxy.h:
     52        * Sources.txt:
     53        * WebCore.xcodeproj/project.pbxproj:
     54        * bindings/js/SerializedScriptValue.cpp:
     55        (WebCore::SerializedScriptValue::SerializedScriptValue):
     56        * bindings/js/SerializedScriptValue.h:
     57        (WebCore::SerializedScriptValue::encode const):
     58        (WebCore::SerializedScriptValue::decode):
     59        * dom/Document.cpp:
     60        (WebCore::Document::createRTCDataChannelRemoteHandlerConnection):
     61        * dom/Document.h:
     62        * dom/ScriptExecutionContext.h:
     63        (WebCore::ScriptExecutionContext::createRTCDataChannelRemoteHandlerConnection):
     64        * platform/ScriptExecutionContextIdentifier.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelState.h.
     65        * platform/mediastream/RTCDataChannelHandler.h:
     66        (WebCore::RTCDataChannelInit::encode const):
     67        (WebCore::RTCDataChannelInit::decode):
     68        * platform/mediastream/RTCDataChannelIdentifier.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.
     69        (WebCore::RTCDataChannelIdentifier::encode const):
     70        (WebCore::RTCDataChannelIdentifier::decode):
     71        * platform/mediastream/RTCDataChannelRemoteHandlerConnection.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.
     72        * platform/mediastream/RTCDataChannelRemoteSourceConnection.h: Copied from Source/WebCore/platform/mediastream/RTCDataChannelHandler.h.
     73        * platform/mediastream/RTCDataChannelState.h:
     74        * platform/mediastream/RTCPriorityType.h:
     75        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
     76        * workers/WorkerGlobalScope.cpp:
     77        (WebCore::WorkerGlobalScope::createRTCDataChannelRemoteHandlerConnection):
     78        * workers/WorkerGlobalScope.h:
     79        * workers/WorkerLoaderProxy.h:
     80        * workers/WorkerMessagingProxy.cpp:
     81        (WebCore::WorkerMessagingProxy::createRTCDataChannelRemoteHandlerConnection):
     82        * workers/WorkerMessagingProxy.h:
     83        * workers/service/context/ServiceWorkerThreadProxy.cpp:
     84        (WebCore::ServiceWorkerThreadProxy::createRTCDataChannelRemoteHandlerConnection):
     85        * workers/service/context/ServiceWorkerThreadProxy.h:
     86
    1872021-03-22  Simon Fraser  <simon.fraser@apple.com>
    288
  • trunk/Source/WebCore/Headers.cmake

    r273776 r274758  
    104104    Modules/mediasource/SampleMap.h
    105105
     106    Modules/mediastream/DetachedRTCDataChannel.h
    106107    Modules/mediastream/DoubleRange.h
    107108    Modules/mediastream/LongRange.h
     
    109110    Modules/mediastream/MediaTrackConstraints.h
    110111    Modules/mediastream/RTCController.h
     112    Modules/mediastream/RTCDataChannel.h
     113    Modules/mediastream/RTCDataChannelRemoteHandler.h
     114    Modules/mediastream/RTCDataChannelRemoteSource.h
    111115    Modules/mediastream/STUNMessageParsing.h
    112116    Modules/mediastream/UserMediaClient.h
     
    10811085    platform/SSLKeyGenerator.h
    10821086    platform/ScreenProperties.h
     1087    platform/ScriptExecutionContextIdentifier.h
    10831088    platform/ScrollAnimator.h
    10841089    platform/ScrollTypes.h
     
    13661371    platform/mediastream/MediaStreamRequest.h
    13671372    platform/mediastream/MediaStreamTrackPrivate.h
     1373    platform/mediastream/RTCDataChannelHandler.h
     1374    platform/mediastream/RTCDataChannelHandlerClient.h
     1375    platform/mediastream/RTCDataChannelIdentifier.h
     1376    platform/mediastream/RTCDataChannelRemoteHandlerConnection.h
     1377    platform/mediastream/RTCDataChannelRemoteSourceConnection.h
     1378    platform/mediastream/RTCDataChannelState.h
     1379    platform/mediastream/RTCPriorityType.h
    13681380    platform/mediastream/RealtimeMediaSource.h
    13691381    platform/mediastream/RealtimeMediaSourceCapabilities.h
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp

    r274351 r274758  
    3434#include "Logging.h"
    3535#include "MessageEvent.h"
     36#include "RTCDataChannelRemoteHandler.h"
    3637#include "ScriptExecutionContext.h"
    3738#include "SharedBuffer.h"
     
    9495    : ActiveDOMObject(&context)
    9596    , m_handler(WTFMove(handler))
    96     , m_identifier(RTCDataChannelIdentifier { Process::identifier(), ObjectIdentifier<RTCDataChannelIdentifierType>::generateThreadSafe() })
     97    , m_identifier(RTCDataChannelIdentifier { Process::identifier(), ObjectIdentifier<RTCDataChannelLocalIdentifierType>::generateThreadSafe() })
    9798    , m_contextIdentifier(context.isDocument() ? ScriptExecutionContextIdentifier { } : context.contextIdentifier())
    9899    , m_label(WTFMove(label))
     
    253254
    254255static Lock s_rtcDataChannelLocalMapLock;
    255 static HashMap<ObjectIdentifier<RTCDataChannelIdentifierType>, std::unique_ptr<RTCDataChannelHandler>>& rtcDataChannelLocalMap()
     256static HashMap<RTCDataChannelLocalIdentifier, std::unique_ptr<RTCDataChannelHandler>>& rtcDataChannelLocalMap()
    256257{
    257258    ASSERT(s_rtcDataChannelLocalMapLock.isHeld());
    258     static LazyNeverDestroyed<HashMap<ObjectIdentifier<RTCDataChannelIdentifierType>, std::unique_ptr<RTCDataChannelHandler>>> map;
     259    static LazyNeverDestroyed<HashMap<RTCDataChannelLocalIdentifier, std::unique_ptr<RTCDataChannelHandler>>> map;
    259260    static std::once_flag onceKey;
    260261    std::call_once(onceKey, [&] {
     
    294295}
    295296
     297std::unique_ptr<RTCDataChannelHandler> RTCDataChannel::handlerFromIdentifier(RTCDataChannelLocalIdentifier channelIdentifier)
     298{
     299    auto locker = holdLock(s_rtcDataChannelLocalMapLock);
     300    return rtcDataChannelLocalMap().take(channelIdentifier);
     301}
     302
    296303static Ref<RTCDataChannel> createClosedChannel(ScriptExecutionContext& context, String&& label, RTCDataChannelInit&& options)
    297304{
     
    303310Ref<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext& context, RTCDataChannelIdentifier identifier, String&& label, RTCDataChannelInit&& options, RTCDataChannelState state)
    304311{
    305     if (identifier.processIdentifier != Process::identifier()) {
    306         RELEASE_LOG_ERROR(WebRTC, "Out-of-process data channels are not yet supported");
    307         return createClosedChannel(context, WTFMove(label), WTFMove(options));
    308     }
    309 
    310     auto locker = holdLock(s_rtcDataChannelLocalMapLock);
    311     auto handler = rtcDataChannelLocalMap().take(identifier.channelIdentifier);
     312    RTCDataChannelRemoteHandler* remoteHandlerPtr = nullptr;
     313    std::unique_ptr<RTCDataChannelHandler> handler;
     314    if (identifier.processIdentifier == Process::identifier())
     315        handler = RTCDataChannel::handlerFromIdentifier(identifier.channelIdentifier);
     316    else {
     317        auto remoteHandler = RTCDataChannelRemoteHandler::create(identifier, context.createRTCDataChannelRemoteHandlerConnection());
     318        remoteHandlerPtr = remoteHandler.get();
     319        handler = WTFMove(remoteHandler);
     320    }
     321
    312322    if (!handler)
    313323        return createClosedChannel(context, WTFMove(label), WTFMove(options));
     
    315325    auto channel = RTCDataChannel::create(context, WTFMove(handler), WTFMove(label), WTFMove(options));
    316326    channel->m_readyState = state;
     327
     328    if (remoteHandlerPtr)
     329        remoteHandlerPtr->setLocalIdentifier(channel->identifier());
     330
    317331    return channel;
    318332}
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h

    r274351 r274758  
    2929
    3030#include "ActiveDOMObject.h"
     31#include "DetachedRTCDataChannel.h"
    3132#include "Event.h"
    3233#include "EventTarget.h"
    3334#include "ExceptionOr.h"
    3435#include "NetworkSendQueue.h"
    35 #include "ProcessIdentifier.h"
    3636#include "RTCDataChannelHandler.h"
    3737#include "RTCDataChannelHandlerClient.h"
     38#include "RTCDataChannelIdentifier.h"
    3839#include "ScriptExecutionContext.h"
    3940#include "ScriptWrappable.h"
     
    4950class Blob;
    5051class RTCPeerConnectionHandler;
    51 
    52 enum RTCDataChannelIdentifierType { };
    53 struct RTCDataChannelIdentifier {
    54     ProcessIdentifier processIdentifier;
    55     ObjectIdentifier<RTCDataChannelIdentifierType> channelIdentifier;
    56 
    57     template<class Encoder> void encode(Encoder&) const;
    58     template<class Decoder> static Optional<RTCDataChannelIdentifier> decode(Decoder&);
    59 
    60 #if !LOG_DISABLED
    61     String logString() const;
    62 #endif
    63 };
    64 
    65 struct DetachedRTCDataChannel {
    66     WTF_MAKE_NONCOPYABLE(DetachedRTCDataChannel);
    67     WTF_MAKE_FAST_ALLOCATED;
    68 public:
    69     DetachedRTCDataChannel(RTCDataChannelIdentifier identifier, const String& label, const RTCDataChannelInit& options, RTCDataChannelState state)
    70         : identifier(identifier)
    71         , label(label.isolatedCopy())
    72         , options(options.isolatedCopy())
    73         , state(state)
    74     {
    75     }
    76 
    77     size_t memoryCost() const { return label.sizeInBytes(); }
    78 
    79     RTCDataChannelIdentifier identifier;
    80     String label;
    81     RTCDataChannelInit options;
    82     RTCDataChannelState state { RTCDataChannelState::Closed };
    83 };
    8452
    8553class RTCDataChannel final : public ActiveDOMObject, public RTCDataChannelHandlerClient, public EventTargetWithInlineData {
     
    12088    using RTCDataChannelHandlerClient::ref;
    12189    using RTCDataChannelHandlerClient::deref;
     90
     91    WEBCORE_EXPORT static std::unique_ptr<RTCDataChannelHandler> handlerFromIdentifier(RTCDataChannelLocalIdentifier);
    12292
    12393private:
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannelRemoteSource.cpp

    r274756 r274758  
    11/*
    2  * Copyright (C) 2012 Google Inc. All rights reserved.
    3  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    2423 */
    2524
    26 #pragma once
     25#include "config.h"
     26#include "RTCDataChannelRemoteSource.h"
    2727
    2828#if ENABLE(WEB_RTC)
    2929
    30 #include "RTCPriorityType.h"
    31 #include "ScriptExecutionContext.h"
    32 #include <wtf/Optional.h>
    33 #include <wtf/text/WTFString.h>
     30#include "RTCDataChannelHandler.h"
    3431
    3532namespace WebCore {
    3633
    37 struct RTCDataChannelInit {
    38     Optional<bool> ordered;
    39     Optional<unsigned short> maxPacketLifeTime;
    40     Optional<unsigned short> maxRetransmits;
    41     String protocol;
    42     Optional<bool> negotiated;
    43     Optional<unsigned short> id;
    44     RTCPriorityType priority { RTCPriorityType::Low };
    45 
    46     RTCDataChannelInit isolatedCopy() const;
    47 };
    48 
    49 inline RTCDataChannelInit RTCDataChannelInit::isolatedCopy() const
     34RTCDataChannelRemoteSource::RTCDataChannelRemoteSource(RTCDataChannelIdentifier identifier, UniqueRef<RTCDataChannelHandler>&& handler, Ref<RTCDataChannelRemoteSourceConnection>&& connection)
     35    : m_identifier(identifier)
     36    , m_handler(WTFMove(handler))
     37    , m_connection(WTFMove(connection))
    5038{
    51     auto copy = *this;
    52     copy.protocol = protocol.isolatedCopy();
    53     return copy;
     39    // FIXME: We should ask m_handler to call us on its own background thread.
     40    m_handler->setClient(*this, { });
    5441}
    5542
    56 class RTCDataChannelHandlerClient;
    57 
    58 class RTCDataChannelHandler {
    59 public:
    60     virtual ~RTCDataChannelHandler() = default;
    61 
    62     virtual void setClient(RTCDataChannelHandlerClient&, ScriptExecutionContextIdentifier) = 0;
    63 
    64     virtual bool sendStringData(const CString&) = 0;
    65     virtual bool sendRawData(const char*, size_t) = 0;
    66     virtual void close() = 0;
    67 };
     43RTCDataChannelRemoteSource::~RTCDataChannelRemoteSource()
     44{
     45}
    6846
    6947} // namespace WebCore
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp

    r274351 r274758  
    193193    ASSERT(m_clientLock.isHeld());
    194194
    195     if (!m_contextIdentifier)
     195    if (!m_contextIdentifier) {
    196196        callOnMainThread(WTFMove(function));
     197        return;
     198    }
    197199    ScriptExecutionContext::postTaskTo(m_contextIdentifier, WTFMove(function));
    198200}
  • trunk/Source/WebCore/Modules/webaudio/AudioWorkletMessagingProxy.cpp

    r270806 r274758  
    3838#include "Document.h"
    3939#include "Frame.h"
     40#include "LibWebRTCProvider.h"
     41#include "Page.h"
    4042#include "Settings.h"
    4143#include "WorkletParameters.h"
     
    8688}
    8789
     90RefPtr<RTCDataChannelRemoteHandlerConnection> AudioWorkletMessagingProxy::createRTCDataChannelRemoteHandlerConnection()
     91{
     92    ASSERT(isMainThread());
     93    if (!m_document->page())
     94        return nullptr;
     95    return m_document->page()->libWebRTCProvider().createRTCDataChannelRemoteHandlerConnection();
     96}
     97
    8898void AudioWorkletMessagingProxy::postTaskToLoader(ScriptExecutionContext::Task&& task)
    8999{
  • trunk/Source/WebCore/Modules/webaudio/AudioWorkletMessagingProxy.h

    r268103 r274758  
    6060    // WorkerLoaderProxy.
    6161    RefPtr<CacheStorageConnection> createCacheStorageConnection() final;
     62    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
    6263    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
    6364    bool postTaskForModeToWorkerOrWorkletGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
  • trunk/Source/WebCore/Sources.txt

    r274750 r274758  
    161161Modules/mediastream/RTCDataChannel.cpp
    162162Modules/mediastream/RTCDataChannelEvent.cpp
     163Modules/mediastream/RTCDataChannelRemoteHandler.cpp
     164Modules/mediastream/RTCDataChannelRemoteSource.cpp
    163165Modules/mediastream/RTCEncodedAudioFrame.cpp
    164166Modules/mediastream/RTCEncodedFrame.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r274755 r274758  
    933933                316DCB4E1E7910A6001B5F87 /* JSRTCIceGatheringState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DCB481E7910A6001B5F87 /* JSRTCIceGatheringState.h */; };
    934934                316DCB501E7910A6001B5F87 /* JSRTCSignalingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DCB4A1E7910A6001B5F87 /* JSRTCSignalingState.h */; };
    935                 316DE7021E83AE1D0084C261 /* RTCDataChannelState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DE7011E83AE1D0084C261 /* RTCDataChannelState.h */; };
     935                316DE7021E83AE1D0084C261 /* RTCDataChannelState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DE7011E83AE1D0084C261 /* RTCDataChannelState.h */; settings = {ATTRIBUTES = (Private, ); }; };
    936936                316FE0720E6CCBEE00BF6088 /* JSCSSKeyframeRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */; };
    937937                316FE0740E6CCBEE00BF6088 /* JSCSSKeyframesRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 316FE0700E6CCBEE00BF6088 /* JSCSSKeyframesRule.h */; };
     
    10371037                41103AAD1E39791000769F03 /* RealtimeIncomingAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA91E39790A00769F03 /* RealtimeIncomingAudioSource.h */; };
    10381038                41103AAD1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA91E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.h */; };
     1039                411223BA260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 411223B8260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1040                411223BE26025BC100B0A0B6 /* RTCDataChannelRemoteSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDBEF25FFB22400092675 /* RTCDataChannelRemoteSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1041                411223C52603567D00B0A0B6 /* DetachedRTCDataChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 411223C32603567C00B0A0B6 /* DetachedRTCDataChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10391042                4112B5431F9F9CA000E67875 /* ServiceWorkerThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10401043                4114FE3225BEBD19009D9F20 /* RTCRtcpParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 4114FE2F25BEBD18009D9F20 /* RTCRtcpParameters.h */; };
     
    10621065                413C8B342552F27D00E65055 /* RTCRtpTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = 413C8B2F2552F27B00E65055 /* RTCRtpTransform.h */; };
    10631066                413C8B352552F27D00E65055 /* RTCRtpReceiverWithTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = 413C8B302552F27C00E65055 /* RTCRtpReceiverWithTransform.h */; };
    1064                 413CC11D25E7D98E00D59C4B /* RTCPriorityType.h in Headers */ = {isa = PBXBuildFile; fileRef = 413CC11C25E7D98D00D59C4B /* RTCPriorityType.h */; };
     1067                413CC11D25E7D98E00D59C4B /* RTCPriorityType.h in Headers */ = {isa = PBXBuildFile; fileRef = 413CC11C25E7D98D00D59C4B /* RTCPriorityType.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10651068                413CCD4A20DE034F0065A21A /* MockMediaDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 413CCD4820DE013C0065A21A /* MockMediaDevice.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10661069                413E00791DB0E4F2002341D2 /* MemoryRelease.h in Headers */ = {isa = PBXBuildFile; fileRef = 413E00781DB0E4DE002341D2 /* MemoryRelease.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    10991102                416E6FE91BBD12E5000A6053 /* WritableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11001103                416ECAE525B58CC400B34DA5 /* MediaSessionGroupIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 416ECAE325B58CC400B34DA5 /* MediaSessionGroupIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1104                416EDBF62600D67900092675 /* RTCDataChannelRemoteHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDBF42600D67800092675 /* RTCDataChannelRemoteHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1105                416EDC002600E78800092675 /* RTCDataChannelIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDBFF2600E78700092675 /* RTCDataChannelIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1106                416EDC022600E7B000092675 /* RTCDataChannelRemoteHandlerConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDC012600E7B000092675 /* RTCDataChannelRemoteHandlerConnection.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1107                416EDC042600E81000092675 /* RTCDataChannelRemoteSourceConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDC032600E80F00092675 /* RTCDataChannelRemoteSourceConnection.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11011108                416FD25F240FA4E5006661D8 /* NowPlayingInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 416FD25D240EE1AE006661D8 /* NowPlayingInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11021109                417253AB1354BBBC00360F2A /* MediaControlTextTrackContainerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 417253A91354BBBC00360F2A /* MediaControlTextTrackContainerElement.h */; };
     
    76487655                41114A7A2317B39E00B56007 /* WorkerMessagePortChannelProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WorkerMessagePortChannelProvider.h; sourceTree = "<group>"; };
    76497656                41114A7C2317B39E00B56007 /* WorkerMessagePortChannelProvider.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerMessagePortChannelProvider.cpp; sourceTree = "<group>"; };
     7657                411223B8260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptExecutionContextIdentifier.h; sourceTree = "<group>"; };
     7658                411223C32603567C00B0A0B6 /* DetachedRTCDataChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedRTCDataChannel.h; sourceTree = "<group>"; };
    76507659                4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerThreadProxy.h; sourceTree = "<group>"; };
    76517660                4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerThreadProxy.cpp; sourceTree = "<group>"; };
     
    77947803                416E29A5102FA962007FC14E /* WorkerReportingProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerReportingProxy.h; sourceTree = "<group>"; };
    77957804                416ECAE325B58CC400B34DA5 /* MediaSessionGroupIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionGroupIdentifier.h; sourceTree = "<group>"; };
     7805                416EDBED25FFB22400092675 /* RTCDataChannelRemoteSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCDataChannelRemoteSource.cpp; sourceTree = "<group>"; };
     7806                416EDBEF25FFB22400092675 /* RTCDataChannelRemoteSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelRemoteSource.h; sourceTree = "<group>"; };
     7807                416EDBF42600D67800092675 /* RTCDataChannelRemoteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelRemoteHandler.h; sourceTree = "<group>"; };
     7808                416EDBF72600D76300092675 /* RTCDataChannelRemoteHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCDataChannelRemoteHandler.cpp; sourceTree = "<group>"; };
     7809                416EDBFF2600E78700092675 /* RTCDataChannelIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelIdentifier.h; sourceTree = "<group>"; };
     7810                416EDC012600E7B000092675 /* RTCDataChannelRemoteHandlerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelRemoteHandlerConnection.h; sourceTree = "<group>"; };
     7811                416EDC032600E80F00092675 /* RTCDataChannelRemoteSourceConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelRemoteSourceConnection.h; sourceTree = "<group>"; };
    77967812                416F807924509F3200B68F02 /* WindowDisplayCapturerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowDisplayCapturerMac.h; sourceTree = "<group>"; };
    77977813                416F807A24509F3200B68F02 /* ScreenDisplayCapturerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScreenDisplayCapturerMac.mm; sourceTree = "<group>"; };
     
    1724217258                                41C7E1061E6A54360027B4DE /* CanvasCaptureMediaStreamTrack.h */,
    1724317259                                41C7E1081E6AA37C0027B4DE /* CanvasCaptureMediaStreamTrack.idl */,
     17260                                411223C32603567C00B0A0B6 /* DetachedRTCDataChannel.h */,
    1724417261                                93A806111E03B51C008A1F26 /* DoubleRange.h */,
    1724517262                                93A806121E03B51C008A1F26 /* DoubleRange.idl */,
     
    1729117308                                07221B6717CEC32700848E51 /* RTCDataChannelEvent.h */,
    1729217309                                07221B6817CEC32700848E51 /* RTCDataChannelEvent.idl */,
     17310                                416EDBF72600D76300092675 /* RTCDataChannelRemoteHandler.cpp */,
     17311                                416EDBF42600D67800092675 /* RTCDataChannelRemoteHandler.h */,
     17312                                416EDBED25FFB22400092675 /* RTCDataChannelRemoteSource.cpp */,
     17313                                416EDBEF25FFB22400092675 /* RTCDataChannelRemoteSource.h */,
    1729317314                                41FCB75D214866FE0038ADC6 /* RTCDegradationPreference.h */,
    1729417315                                41FCB755214865CF0038ADC6 /* RTCDegradationPreference.idl */,
     
    1748617507                                07221BA217CF0AD400848E51 /* RTCDataChannelHandler.h */,
    1748717508                                07221BA317CF0AD400848E51 /* RTCDataChannelHandlerClient.h */,
     17509                                416EDBFF2600E78700092675 /* RTCDataChannelIdentifier.h */,
     17510                                416EDC012600E7B000092675 /* RTCDataChannelRemoteHandlerConnection.h */,
     17511                                416EDC032600E80F00092675 /* RTCDataChannelRemoteSourceConnection.h */,
    1748817512                                316DE7011E83AE1D0084C261 /* RTCDataChannelState.h */,
    1748917513                                41F2354422F5503300B4FCDB /* RTCDTMFSenderBackend.h */,
     
    2781227836                                293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */,
    2781327837                                C1E1D235203DF15400584665 /* ScreenProperties.h */,
     27838                                411223B8260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h */,
    2781427839                                BC8AE34C12EA096A00EB3AE6 /* ScrollableArea.cpp */,
    2781527840                                BC8AE34D12EA096A00EB3AE6 /* ScrollableArea.h */,
     
    3199232017                                9479493D1E0463B600018D85 /* DeprecatedCSSOMValueList.h in Headers */,
    3199332018                                7CBD129E1F98B90E00127D29 /* DeprecatedGlobalSettings.h in Headers */,
     32019                                411223C52603567D00B0A0B6 /* DetachedRTCDataChannel.h in Headers */,
    3199432020                                A7C9ABF91357A3BF00F5503F /* DetailsMarkerControl.h in Headers */,
    3199532021                                A1ED778D1BE3294000DC1791 /* Device.h in Headers */,
     
    3462034646                                078E093D17D16E1C00420AA1 /* RTCDataChannelHandlerClient.h in Headers */,
    3462134647                                073794FA19F5864E00E5A045 /* RTCDataChannelHandlerMock.h in Headers */,
     34648                                416EDC002600E78800092675 /* RTCDataChannelIdentifier.h in Headers */,
     34649                                416EDBF62600D67900092675 /* RTCDataChannelRemoteHandler.h in Headers */,
     34650                                416EDC022600E7B000092675 /* RTCDataChannelRemoteHandlerConnection.h in Headers */,
     34651                                411223BE26025BC100B0A0B6 /* RTCDataChannelRemoteSource.h in Headers */,
     34652                                416EDC042600E81000092675 /* RTCDataChannelRemoteSourceConnection.h in Headers */,
    3462234653                                316DE7021E83AE1D0084C261 /* RTCDataChannelState.h in Headers */,
    3462334654                                078E092017D14D1C00420AA1 /* RTCDTMFSender.h in Headers */,
     
    3468834719                                E3E4E2A81E3B17100023BB8A /* ScriptElementCachedScriptFetcher.h in Headers */,
    3468934720                                E11C9D9B0EB3681200E409DB /* ScriptExecutionContext.h in Headers */,
     34721                                411223BA260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h in Headers */,
    3469034722                                372D3E55216578AE00C5E021 /* ScriptModuleLoader.h in Headers */,
    3469134723                                FD31603612B0267600C1A359 /* ScriptProcessorNode.h in Headers */,
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r274351 r274758  
    38273827}
    38283828
    3829 SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray)
     3829SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, std::unique_ptr<ArrayBufferContentsArray>&& arrayBufferContentsArray
     3830#if ENABLE(WEB_RTC)
     3831        , Vector<std::unique_ptr<DetachedRTCDataChannel>>&& detachedRTCDataChannels
     3832#endif
     3833        )
    38303834    : m_data(WTFMove(buffer))
    38313835    , m_arrayBufferContentsArray(WTFMove(arrayBufferContentsArray))
     3836#if ENABLE(WEB_RTC)
     3837    , m_detachedRTCDataChannels(WTFMove(detachedRTCDataChannels))
     3838#endif
    38323839{
    38333840    m_memoryCost = computeMemoryCost();
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.h

    r274351 r274758  
    2727#pragma once
    2828
     29#include "DetachedRTCDataChannel.h"
    2930#include "ExceptionOr.h"
    3031#include <JavaScriptCore/ArrayBuffer.h>
     
    5152class DetachedOffscreenCanvas;
    5253#endif
    53 #if ENABLE(WEB_RTC)
    54 struct DetachedRTCDataChannel;
    55 #endif
    5654class IDBValue;
    5755class MessagePort;
     
    121119private:
    122120    WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&);
    123     WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&, std::unique_ptr<ArrayBufferContentsArray>);
     121    WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&, std::unique_ptr<ArrayBufferContentsArray>&&
     122#if ENABLE(WEB_RTC)
     123        , Vector<std::unique_ptr<DetachedRTCDataChannel>>&&
     124#endif
     125        );
     126
    124127    SerializedScriptValue(Vector<unsigned char>&&, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers, Vector<Optional<ImageBitmapBacking>>&& backingStores
    125128#if ENABLE(OFFSCREEN_CANVAS)
     
    163166    encoder << hasArray;
    164167
    165     if (!hasArray)
    166         return;
    167 
    168     encoder << static_cast<uint64_t>(m_arrayBufferContentsArray->size());
    169     for (const auto &arrayBufferContents : *m_arrayBufferContentsArray) {
    170         encoder << arrayBufferContents.sizeInBytes();
    171         encoder.encodeFixedLengthData(static_cast<const uint8_t*>(arrayBufferContents.data()), arrayBufferContents.sizeInBytes(), 1);
    172     }
     168    if (hasArray) {
     169        encoder << static_cast<uint64_t>(m_arrayBufferContentsArray->size());
     170        for (const auto &arrayBufferContents : *m_arrayBufferContentsArray) {
     171            encoder << arrayBufferContents.sizeInBytes();
     172            encoder.encodeFixedLengthData(static_cast<const uint8_t*>(arrayBufferContents.data()), arrayBufferContents.sizeInBytes(), 1);
     173        }
     174    }
     175
     176#if ENABLE(WEB_RTC)
     177    encoder << static_cast<uint64_t>(m_detachedRTCDataChannels.size());
     178    for (const auto &channel : m_detachedRTCDataChannels)
     179        encoder << *channel;
     180#endif
    173181}
    174182
     
    184192        return nullptr;
    185193
    186     if (!hasArray)
    187         return adoptRef(*new SerializedScriptValue(WTFMove(data)));
    188 
    189     uint64_t arrayLength;
    190     if (!decoder.decode(arrayLength))
     194    std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray;
     195    if (hasArray) {
     196        uint64_t arrayLength;
     197        if (!decoder.decode(arrayLength))
     198            return nullptr;
     199        ASSERT(arrayLength);
     200
     201        arrayBufferContentsArray = makeUnique<ArrayBufferContentsArray>();
     202        while (arrayLength--) {
     203            unsigned bufferSize;
     204            if (!decoder.decode(bufferSize))
     205                return nullptr;
     206            if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(bufferSize))
     207                return nullptr;
     208
     209            auto buffer = Gigacage::tryMalloc(Gigacage::Primitive, bufferSize);
     210            if (!buffer)
     211                return nullptr;
     212            if (!decoder.decodeFixedLengthData(static_cast<uint8_t*>(buffer), bufferSize, 1)) {
     213                Gigacage::free(Gigacage::Primitive, buffer);
     214                return nullptr;
     215            }
     216            arrayBufferContentsArray->append({ buffer, bufferSize, ArrayBuffer::primitiveGigacageDestructor() });
     217        }
     218    }
     219
     220#if ENABLE(WEB_RTC)
     221    uint64_t detachedRTCDataChannelsSize;
     222    if (!decoder.decode(detachedRTCDataChannelsSize))
    191223        return nullptr;
    192     ASSERT(arrayLength);
    193 
    194     auto arrayBufferContentsArray = makeUnique<ArrayBufferContentsArray>();
    195     while (arrayLength--) {
    196         unsigned bufferSize;
    197         if (!decoder.decode(bufferSize))
     224
     225    Vector<std::unique_ptr<DetachedRTCDataChannel>> detachedRTCDataChannels;
     226    while (detachedRTCDataChannelsSize--) {
     227        auto detachedRTCDataChannel = DetachedRTCDataChannel::decode(decoder);
     228        if (!detachedRTCDataChannel)
    198229            return nullptr;
    199         if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(bufferSize))
    200             return nullptr;
    201 
    202         auto buffer = Gigacage::tryMalloc(Gigacage::Primitive, bufferSize);
    203         if (!buffer)
    204             return nullptr;
    205         if (!decoder.decodeFixedLengthData(static_cast<uint8_t*>(buffer), bufferSize, 1)) {
    206             Gigacage::free(Gigacage::Primitive, buffer);
    207             return nullptr;
    208         }
    209         arrayBufferContentsArray->append({ buffer, bufferSize, ArrayBuffer::primitiveGigacageDestructor() });
    210     }
    211 
    212     return adoptRef(*new SerializedScriptValue(WTFMove(data), WTFMove(arrayBufferContentsArray)));
     230        detachedRTCDataChannels.append(WTFMove(detachedRTCDataChannel));
     231    }
     232#endif
     233
     234    return adoptRef(*new SerializedScriptValue(WTFMove(data), WTFMove(arrayBufferContentsArray)
     235#if ENABLE(WEB_RTC)
     236        , WTFMove(detachedRTCDataChannels)
     237#endif
     238        ));
    213239}
    214240
  • trunk/Source/WebCore/dom/Document.cpp

    r274436 r274758  
    34923492    return m_socketProvider.get();
    34933493}
    3494    
     3494
     3495RefPtr<RTCDataChannelRemoteHandlerConnection> Document::createRTCDataChannelRemoteHandlerConnection()
     3496{
     3497    ASSERT(isMainThread());
     3498    auto* page = this->page();
     3499    if (!page)
     3500        return nullptr;
     3501    return page->libWebRTCProvider().createRTCDataChannelRemoteHandlerConnection();
     3502}
     3503
    34953504bool Document::canNavigate(Frame* targetFrame, const URL& destinationURL)
    34963505{
  • trunk/Source/WebCore/dom/Document.h

    r274436 r274758  
    706706#endif
    707707    SocketProvider* socketProvider() final;
     708    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
    708709
    709710    bool canNavigate(Frame* targetFrame, const URL& destinationURL = URL());
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r274143 r274758  
    3030#include "ActiveDOMObject.h"
    3131#include "DOMTimer.h"
     32#include "RTCDataChannelRemoteHandlerConnection.h"
     33#include "ScriptExecutionContextIdentifier.h"
    3234#include "SecurityContext.h"
    3335#include "ServiceWorkerTypes.h"
     
    8183}
    8284
    83 enum ScriptExecutionContextIdentifierType { };
    84 using ScriptExecutionContextIdentifier = ObjectIdentifier<ScriptExecutionContextIdentifierType>;
    85 
    8685class ScriptExecutionContext : public SecurityContext, public CanMakeWeakPtr<ScriptExecutionContext> {
    8786public:
     
    115114#endif
    116115    virtual SocketProvider* socketProvider() = 0;
     116
     117    virtual RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() { return nullptr; }
    117118
    118119    virtual String resourceRequestIdentifier() const { return String(); };
  • trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h

    r274756 r274758  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
    28 #if ENABLE(WEB_RTC)
     28#include <wtf/ObjectIdentifier.h>
    2929
    3030namespace WebCore {
    3131
    32 enum class RTCDataChannelState {
    33     Connecting,
    34     Open,
    35     Closing,
    36     Closed
    37 };
     32enum ScriptExecutionContextIdentifierType { };
     33using ScriptExecutionContextIdentifier = ObjectIdentifier<ScriptExecutionContextIdentifierType>;
    3834
    39 }; // namespace WebCore
    40 
    41 #endif
     35}
  • trunk/Source/WebCore/platform/mediastream/RTCDataChannelHandler.h

    r274351 r274758  
    2929
    3030#include "RTCPriorityType.h"
    31 #include "ScriptExecutionContext.h"
     31#include "ScriptExecutionContextIdentifier.h"
    3232#include <wtf/Optional.h>
    3333#include <wtf/text/WTFString.h>
     
    4545
    4646    RTCDataChannelInit isolatedCopy() const;
     47
     48    template<class Encoder> void encode(Encoder&) const;
     49    template<class Decoder> static Optional<RTCDataChannelInit> decode(Decoder&);
    4750};
    4851
     
    5255    copy.protocol = protocol.isolatedCopy();
    5356    return copy;
     57}
     58
     59template<class Encoder> void RTCDataChannelInit::encode(Encoder& encoder) const
     60{
     61    encoder << ordered << maxPacketLifeTime << maxRetransmits << protocol << negotiated << id << priority;
     62}
     63
     64template<class Decoder> Optional<RTCDataChannelInit> RTCDataChannelInit::decode(Decoder& decoder)
     65{
     66    Optional<bool> ordered;
     67    decoder >> ordered;
     68    if (!ordered)
     69        return { };
     70
     71    Optional<unsigned short> maxPacketLifeTime;
     72    decoder >> maxPacketLifeTime;
     73    if (!maxPacketLifeTime)
     74        return { };
     75
     76    Optional<unsigned short> maxRetransmits;
     77    decoder >> maxRetransmits;
     78    if (!maxRetransmits)
     79        return { };
     80
     81    String protocol;
     82    if (!decoder.decode(protocol))
     83        return { };
     84
     85    Optional<bool> negotiated;
     86    decoder >> negotiated;
     87    if (!negotiated)
     88        return { };
     89
     90    Optional<unsigned short> id;
     91    decoder >> id;
     92    if (!id)
     93        return { };
     94
     95    Optional<RTCPriorityType> priority;
     96    decoder >> priority;
     97    if (!priority)
     98        return { };
     99
     100    return RTCDataChannelInit { *ordered, *maxPacketLifeTime, *maxRetransmits, WTFMove(protocol), *negotiated, *id, *priority };
    54101}
    55102
  • trunk/Source/WebCore/platform/mediastream/RTCDataChannelIdentifier.h

    r274756 r274758  
    11/*
    2  * Copyright (C) 2012 Google Inc. All rights reserved.
    3  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    2625#pragma once
    2726
    28 #if ENABLE(WEB_RTC)
    29 
    30 #include "RTCPriorityType.h"
    31 #include "ScriptExecutionContext.h"
    32 #include <wtf/Optional.h>
    33 #include <wtf/text/WTFString.h>
     27#include "ProcessIdentifier.h"
     28#include <wtf/ObjectIdentifier.h>
    3429
    3530namespace WebCore {
    3631
    37 struct RTCDataChannelInit {
    38     Optional<bool> ordered;
    39     Optional<unsigned short> maxPacketLifeTime;
    40     Optional<unsigned short> maxRetransmits;
    41     String protocol;
    42     Optional<bool> negotiated;
    43     Optional<unsigned short> id;
    44     RTCPriorityType priority { RTCPriorityType::Low };
     32enum RTCDataChannelLocalIdentifierType { };
     33using RTCDataChannelLocalIdentifier = ObjectIdentifier<RTCDataChannelLocalIdentifierType>;
     34struct RTCDataChannelIdentifier {
     35    ProcessIdentifier processIdentifier;
     36    RTCDataChannelLocalIdentifier channelIdentifier;
    4537
    46     RTCDataChannelInit isolatedCopy() const;
     38    template<class Encoder> void encode(Encoder&) const;
     39    template<class Decoder> static Optional<RTCDataChannelIdentifier> decode(Decoder&);
    4740};
    4841
    49 inline RTCDataChannelInit RTCDataChannelInit::isolatedCopy() const
     42template<class Encoder>
     43inline void RTCDataChannelIdentifier::encode(Encoder& encoder) const
    5044{
    51     auto copy = *this;
    52     copy.protocol = protocol.isolatedCopy();
    53     return copy;
     45    encoder << processIdentifier << channelIdentifier;
    5446}
    5547
    56 class RTCDataChannelHandlerClient;
     48template<class Decoder>
     49inline Optional<RTCDataChannelIdentifier> RTCDataChannelIdentifier::decode(Decoder& decoder)
     50{
     51    Optional<ProcessIdentifier> processIdentifier;
     52    decoder >> processIdentifier;
     53    if (!processIdentifier)
     54        return WTF::nullopt;
    5755
    58 class RTCDataChannelHandler {
    59 public:
    60     virtual ~RTCDataChannelHandler() = default;
    61 
    62     virtual void setClient(RTCDataChannelHandlerClient&, ScriptExecutionContextIdentifier) = 0;
    63 
    64     virtual bool sendStringData(const CString&) = 0;
    65     virtual bool sendRawData(const char*, size_t) = 0;
    66     virtual void close() = 0;
    67 };
     56    Optional<RTCDataChannelLocalIdentifier> channelIdentifier;
     57    decoder >> channelIdentifier;
     58    if (!channelIdentifier)
     59        return WTF::nullopt;
     60    return RTCDataChannelIdentifier { *processIdentifier, *channelIdentifier };
     61}
    6862
    6963} // namespace WebCore
    70 
    71 #endif // ENABLE(WEB_RTC)
  • trunk/Source/WebCore/platform/mediastream/RTCDataChannelRemoteHandlerConnection.h

    r274756 r274758  
    11/*
    2  * Copyright (C) 2012 Google Inc. All rights reserved.
    3  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    2625#pragma once
    2726
    28 #if ENABLE(WEB_RTC)
    29 
    30 #include "RTCPriorityType.h"
    31 #include "ScriptExecutionContext.h"
    32 #include <wtf/Optional.h>
     27#include "RTCDataChannelIdentifier.h"
     28#include "ScriptExecutionContextIdentifier.h"
     29#include <wtf/ThreadSafeRefCounted.h>
    3330#include <wtf/text/WTFString.h>
    3431
    3532namespace WebCore {
    3633
    37 struct RTCDataChannelInit {
    38     Optional<bool> ordered;
    39     Optional<unsigned short> maxPacketLifeTime;
    40     Optional<unsigned short> maxRetransmits;
    41     String protocol;
    42     Optional<bool> negotiated;
    43     Optional<unsigned short> id;
    44     RTCPriorityType priority { RTCPriorityType::Low };
     34class RTCDataChannelRemoteHandler;
    4535
    46     RTCDataChannelInit isolatedCopy() const;
    47 };
     36class RTCDataChannelRemoteHandlerConnection : public ThreadSafeRefCounted<RTCDataChannelRemoteHandlerConnection, WTF::DestructionThread::Main> {
     37public:
     38    virtual ~RTCDataChannelRemoteHandlerConnection() = default;
    4839
    49 inline RTCDataChannelInit RTCDataChannelInit::isolatedCopy() const
    50 {
    51     auto copy = *this;
    52     copy.protocol = protocol.isolatedCopy();
    53     return copy;
    54 }
    55 
    56 class RTCDataChannelHandlerClient;
    57 
    58 class RTCDataChannelHandler {
    59 public:
    60     virtual ~RTCDataChannelHandler() = default;
    61 
    62     virtual void setClient(RTCDataChannelHandlerClient&, ScriptExecutionContextIdentifier) = 0;
    63 
    64     virtual bool sendStringData(const CString&) = 0;
    65     virtual bool sendRawData(const char*, size_t) = 0;
    66     virtual void close() = 0;
     40    virtual void connectToSource(RTCDataChannelRemoteHandler&, ScriptExecutionContextIdentifier, RTCDataChannelIdentifier, RTCDataChannelIdentifier) = 0;
     41    virtual void sendData(RTCDataChannelIdentifier, bool isRaw, const unsigned char*, size_t) = 0;
     42    virtual void close(RTCDataChannelIdentifier) = 0;
    6743};
    6844
    6945} // namespace WebCore
    70 
    71 #endif // ENABLE(WEB_RTC)
  • trunk/Source/WebCore/platform/mediastream/RTCDataChannelRemoteSourceConnection.h

    r274756 r274758  
    11/*
    2  * Copyright (C) 2012 Google Inc. All rights reserved.
    3  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    2827#if ENABLE(WEB_RTC)
    2928
    30 #include "RTCPriorityType.h"
    31 #include "ScriptExecutionContext.h"
    32 #include <wtf/Optional.h>
     29#include "RTCDataChannelIdentifier.h"
     30#include "RTCDataChannelState.h"
     31#include <wtf/ThreadSafeRefCounted.h>
    3332#include <wtf/text/WTFString.h>
    3433
    3534namespace WebCore {
    3635
    37 struct RTCDataChannelInit {
    38     Optional<bool> ordered;
    39     Optional<unsigned short> maxPacketLifeTime;
    40     Optional<unsigned short> maxRetransmits;
    41     String protocol;
    42     Optional<bool> negotiated;
    43     Optional<unsigned short> id;
    44     RTCPriorityType priority { RTCPriorityType::Low };
     36class RTCDataChannelRemoteSourceConnection : public ThreadSafeRefCounted<RTCDataChannelRemoteSourceConnection, WTF::DestructionThread::Main> {
     37public:
     38    virtual ~RTCDataChannelRemoteSourceConnection() = default;
    4539
    46     RTCDataChannelInit isolatedCopy() const;
    47 };
    48 
    49 inline RTCDataChannelInit RTCDataChannelInit::isolatedCopy() const
    50 {
    51     auto copy = *this;
    52     copy.protocol = protocol.isolatedCopy();
    53     return copy;
    54 }
    55 
    56 class RTCDataChannelHandlerClient;
    57 
    58 class RTCDataChannelHandler {
    59 public:
    60     virtual ~RTCDataChannelHandler() = default;
    61 
    62     virtual void setClient(RTCDataChannelHandlerClient&, ScriptExecutionContextIdentifier) = 0;
    63 
    64     virtual bool sendStringData(const CString&) = 0;
    65     virtual bool sendRawData(const char*, size_t) = 0;
    66     virtual void close() = 0;
     40    virtual void didChangeReadyState(RTCDataChannelIdentifier, RTCDataChannelState) = 0;
     41    virtual void didReceiveStringData(RTCDataChannelIdentifier, const String&) = 0;
     42    virtual void didReceiveRawData(RTCDataChannelIdentifier, const char*, size_t) = 0;
     43    virtual void didDetectError(RTCDataChannelIdentifier) = 0;
     44    virtual void bufferedAmountIsDecreasing(RTCDataChannelIdentifier, size_t) = 0;
    6745};
    6846
  • trunk/Source/WebCore/platform/mediastream/RTCDataChannelState.h

    r214627 r274758  
    2828#if ENABLE(WEB_RTC)
    2929
     30#include <wtf/EnumTraits.h>
     31
    3032namespace WebCore {
    3133
    32 enum class RTCDataChannelState {
     34enum class RTCDataChannelState : uint8_t {
    3335    Connecting,
    3436    Open,
     
    3941}; // namespace WebCore
    4042
     43
     44namespace WTF {
     45
     46template<> struct EnumTraits<WebCore::RTCDataChannelState> {
     47    using values = EnumValues<
     48        WebCore::RTCDataChannelState,
     49        WebCore::RTCDataChannelState::Connecting,
     50        WebCore::RTCDataChannelState::Open,
     51        WebCore::RTCDataChannelState::Closing,
     52        WebCore::RTCDataChannelState::Closed
     53    >;
     54};
     55
     56}
     57
    4158#endif
  • trunk/Source/WebCore/platform/mediastream/RTCPriorityType.h

    r273550 r274758  
    2828#if ENABLE(WEB_RTC)
    2929
     30#include <wtf/EnumTraits.h>
     31
    3032namespace WebCore {
    3133
     
    3436} // namespace WebCore
    3537
     38namespace WTF {
     39
     40template<> struct EnumTraits<WebCore::RTCPriorityType> {
     41    using values = EnumValues<
     42        WebCore::RTCPriorityType,
     43        WebCore::RTCPriorityType::VeryLow,
     44        WebCore::RTCPriorityType::Low,
     45        WebCore::RTCPriorityType::Medium,
     46        WebCore::RTCPriorityType::High
     47    >;
     48};
     49
     50}
     51
    3652#endif // ENABLE(WEB_RTC)
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h

    r270720 r274758  
    2828#include "DocumentIdentifier.h"
    2929#include "LibWebRTCMacros.h"
     30#include "RTCDataChannelRemoteHandlerConnection.h"
    3031#include <wtf/CompletionHandler.h>
    3132#include <wtf/Expected.h>
     
    9192        callback(makeUnexpected(MDNSRegisterError::NotImplemented));
    9293    }
     94
     95    virtual RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() { return nullptr; }
    9396
    9497#if USE(LIBWEBRTC)
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r273203 r274758  
    162162}
    163163
     164RefPtr<RTCDataChannelRemoteHandlerConnection> WorkerGlobalScope::createRTCDataChannelRemoteHandlerConnection()
     165{
     166    RefPtr<RTCDataChannelRemoteHandlerConnection> connection;
     167    callOnMainThreadAndWait([workerThread = makeRef(thread()), &connection]() mutable {
     168        connection = workerThread->workerLoaderProxy().createRTCDataChannelRemoteHandlerConnection();
     169    });
     170    ASSERT(connection);
     171
     172    return connection;
     173}
     174
    164175#if ENABLE(INDEXED_DATABASE)
    165176
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r273203 r274758  
    147147    String resourceRequestIdentifier() const final { return m_identifier; }
    148148    SocketProvider* socketProvider() final;
     149    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
    149150
    150151    bool shouldBypassMainWorldContentSecurityPolicy() const final { return m_shouldBypassMainWorldContentSecurityPolicy; }
  • trunk/Source/WebCore/workers/WorkerLoaderProxy.h

    r268057 r274758  
    5151    virtual RefPtr<CacheStorageConnection> createCacheStorageConnection() = 0;
    5252
     53    virtual RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() = 0;
     54
    5355    // Posts a task to the thread which runs the loading code (normally, the main thread).
    5456    virtual void postTaskToLoader(ScriptExecutionContext::Task&&) = 0;
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp

    r273299 r274758  
    3838#include "EventNames.h"
    3939#include "FetchRequestCredentials.h"
     40#include "LibWebRTCProvider.h"
    4041#include "MessageEvent.h"
    4142#include "Page.h"
     
    176177}
    177178
     179RefPtr<RTCDataChannelRemoteHandlerConnection> WorkerMessagingProxy::createRTCDataChannelRemoteHandlerConnection()
     180{
     181    ASSERT(isMainThread());
     182    auto& document = downcast<Document>(*m_scriptExecutionContext);
     183    if (!document.page())
     184        return nullptr;
     185    return document.page()->libWebRTCProvider().createRTCDataChannelRemoteHandlerConnection();
     186}
     187
    178188bool WorkerMessagingProxy::postTaskForModeToWorkerOrWorkletGlobalScope(ScriptExecutionContext::Task&& task, const String& mode)
    179189{
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.h

    r273203 r274758  
    8282    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
    8383    RefPtr<CacheStorageConnection> createCacheStorageConnection() final;
     84    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
    8485
    8586    void workerThreadCreated(DedicatedWorkerThread&);
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp

    r270762 r274758  
    3535#include "Frame.h"
    3636#include "FrameLoader.h"
     37#include "LibWebRTCProvider.h"
    3738#include "LoaderStrategy.h"
    3839#include "Logging.h"
     
    164165}
    165166
     167RefPtr<RTCDataChannelRemoteHandlerConnection> ServiceWorkerThreadProxy::createRTCDataChannelRemoteHandlerConnection()
     168{
     169    ASSERT(isMainThread());
     170    return m_page->libWebRTCProvider().createRTCDataChannelRemoteHandlerConnection();
     171}
     172
    166173std::unique_ptr<FetchLoader> ServiceWorkerThreadProxy::createBlobLoader(FetchLoaderClient& client, const URL& blobURL)
    167174{
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h

    r269888 r274758  
    8989    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
    9090    RefPtr<CacheStorageConnection> createCacheStorageConnection() final;
     91    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
    9192
    9293    // WorkerDebuggerProxy
  • trunk/Source/WebKit/CMakeLists.txt

    r274476 r274758  
    172172    NetworkProcess/webrtc/NetworkRTCMonitor
    173173    NetworkProcess/webrtc/NetworkRTCProvider
     174    NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy
    174175
    175176    PluginProcess/PluginControllerProxy
     
    246247
    247248    WebProcess/Network/webrtc/LibWebRTCNetwork
     249    WebProcess/Network/webrtc/RTCDataChannelRemoteManager
    248250    WebProcess/Network/webrtc/WebMDNSRegister
    249251    WebProcess/Network/webrtc/WebRTCMonitor
  • trunk/Source/WebKit/ChangeLog

    r274746 r274758  
     12021-03-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Implement RTCDataChannel transfer out of process
     4        https://bugs.webkit.org/show_bug.cgi?id=223443
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add support for connecting remote sources to remote data channels.
     9        This is done by connection detached data channels to remote source that will send messages to network process.
     10        Network process then sends to the process in which was reattached the data channel.
     11        Pairing of data channels is done in main thread through connectToSource message.
     12        The data then flows in background threads, network process being the proxy between web processes.
     13        RTCDataChannelRemoteManagerProxy is the forwarding entity in NetworkProcess.
     14        RTCDataChannelRemoteManager is the entity in WebProcess doing the messaging from and to data channels.
     15
     16        * CMakeLists.txt:
     17        * DerivedSources-input.xcfilelist:
     18        * DerivedSources-output.xcfilelist:
     19        * DerivedSources.make:
     20        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     21        (WebKit::NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess):
     22        (WebKit::NetworkConnectionToWebProcess::connectToRTCDataChannelRemoteSource):
     23        (WebKit::NetworkConnectionToWebProcess::registerToRTCDataChannelProxy):
     24        (WebKit::NetworkConnectionToWebProcess::unregisterToRTCDataChannelProxy):
     25        * NetworkProcess/NetworkConnectionToWebProcess.h:
     26        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
     27        * NetworkProcess/NetworkProcess.cpp:
     28        (WebKit::NetworkProcess::rtcDataChannelProxy):
     29        * NetworkProcess/NetworkProcess.h:
     30        * NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.cpp: Added.
     31        (WebKit::RTCDataChannelRemoteManagerProxy::RTCDataChannelRemoteManagerProxy):
     32        (WebKit::RTCDataChannelRemoteManagerProxy::registerConnectionToWebProcess):
     33        (WebKit::RTCDataChannelRemoteManagerProxy::unregisterConnectionToWebProcess):
     34        (WebKit::RTCDataChannelRemoteManagerProxy::sendData):
     35        (WebKit::RTCDataChannelRemoteManagerProxy::close):
     36        (WebKit::RTCDataChannelRemoteManagerProxy::changeReadyState):
     37        (WebKit::RTCDataChannelRemoteManagerProxy::receiveData):
     38        (WebKit::RTCDataChannelRemoteManagerProxy::detectError):
     39        (WebKit::RTCDataChannelRemoteManagerProxy::bufferedAmountIsDecreasing):
     40        * NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.h: Added.
     41        * NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.messages.in: Added.
     42        * Sources.txt:
     43        * WebKit.xcodeproj/project.pbxproj:
     44        * WebProcess/Network/NetworkProcessConnection.cpp:
     45        (WebKit::NetworkProcessConnection::connectToRTCDataChannelRemoteSource):
     46        * WebProcess/Network/NetworkProcessConnection.h:
     47        * WebProcess/Network/NetworkProcessConnection.messages.in:
     48        * WebProcess/Network/webrtc/LibWebRTCProvider.cpp:
     49        (WebKit::LibWebRTCProvider::createRTCDataChannelRemoteHandlerConnection):
     50        * WebProcess/Network/webrtc/LibWebRTCProvider.h:
     51        * WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp: Added.
     52        (WebKit::RTCDataChannelRemoteManager::sharedManager):
     53        (WebKit::RTCDataChannelRemoteManager::RTCDataChannelRemoteManager):
     54        (WebKit::RTCDataChannelRemoteManager::setConnection):
     55        (WebKit::RTCDataChannelRemoteManager::connectToRemoteSource):
     56        (WebKit::RTCDataChannelRemoteManager::remoteHandlerConnection):
     57        (WebKit::RTCDataChannelRemoteManager::remoteSourceConnection):
     58        (WebKit::RTCDataChannelRemoteManager::postTaskToHandler):
     59        (WebKit::RTCDataChannelRemoteManager::sourceFromIdentifier):
     60        (WebKit::RTCDataChannelRemoteManager::sendData):
     61        (WebKit::RTCDataChannelRemoteManager::close):
     62        (WebKit::RTCDataChannelRemoteManager::changeReadyState):
     63        (WebKit::RTCDataChannelRemoteManager::receiveData):
     64        (WebKit::RTCDataChannelRemoteManager::detectError):
     65        (WebKit::RTCDataChannelRemoteManager::bufferedAmountIsDecreasing):
     66        (WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::create):
     67        (WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::RemoteHandlerConnection):
     68        (WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::connectToSource):
     69        (WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::sendData):
     70        (WebKit::RTCDataChannelRemoteManager::RemoteHandlerConnection::close):
     71        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::create):
     72        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::RemoteSourceConnection):
     73        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didChangeReadyState):
     74        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didReceiveStringData):
     75        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didReceiveRawData):
     76        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didDetectError):
     77        (WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::bufferedAmountIsDecreasing):
     78        * WebProcess/Network/webrtc/RTCDataChannelRemoteManager.h: Added.
     79        * WebProcess/Network/webrtc/RTCDataChannelRemoteManager.messages.in: Copied from Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in.
     80        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
     81        (WebKit::WebSWContextManagerConnection::installServiceWorker):
     82
    1832021-03-19  Kate Cheney  <katherine_cheney@apple.com>
    284
  • trunk/Source/WebKit/DerivedSources-input.xcfilelist

    r272748 r274758  
    7171$(PROJECT_DIR)/NetworkProcess/webrtc/NetworkRTCMonitor.messages.in
    7272$(PROJECT_DIR)/NetworkProcess/webrtc/NetworkRTCProvider.messages.in
     73$(PROJECT_DIR)/NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.messages.in
    7374$(PROJECT_DIR)/PluginProcess/PluginControllerProxy.messages.in
    7475$(PROJECT_DIR)/PluginProcess/PluginProcess.messages.in
     
    169170$(PROJECT_DIR)/WebProcess/Network/WebSocketStream.messages.in
    170171$(PROJECT_DIR)/WebProcess/Network/webrtc/LibWebRTCNetwork.messages.in
     172$(PROJECT_DIR)/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.messages.in
    171173$(PROJECT_DIR)/WebProcess/Network/webrtc/WebMDNSRegister.messages.in
    172174$(PROJECT_DIR)/WebProcess/Network/webrtc/WebRTCMonitor.messages.in
  • trunk/Source/WebKit/DerivedSources-output.xcfilelist

    r273949 r274758  
    134134$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PluginProxyMessages.h
    135135$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PluginProxyMessagesReplies.h
     136$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RTCDataChannelRemoteManagerMessageReceiver.cpp
     137$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RTCDataChannelRemoteManagerMessages.h
     138$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RTCDataChannelRemoteManagerMessagesReplies.h
     139$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RTCDataChannelRemoteManagerProxyMessageReceiver.cpp
     140$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RTCDataChannelRemoteManagerProxyMessages.h
     141$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RTCDataChannelRemoteManagerProxyMessagesReplies.h
    136142$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteAudioDestinationManagerMessageReceiver.cpp
    137143$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteAudioDestinationManagerMessages.cpp
  • trunk/Source/WebKit/DerivedSources.make

    r273946 r274758  
    133133        NetworkProcess/webrtc/NetworkRTCProvider \
    134134        NetworkProcess/webrtc/NetworkRTCMonitor \
     135        NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy \
    135136        NetworkProcess/Cookies/WebCookieManager \
    136137        Shared/Plugins/NPObjectMessageReceiver \
     
    204205        WebProcess/Network/WebSocketStream \
    205206        WebProcess/Network/WebResourceLoader \
     207        WebProcess/Network/webrtc/LibWebRTCNetwork \
     208        WebProcess/Network/webrtc/RTCDataChannelRemoteManager \
    206209        WebProcess/Network/webrtc/WebRTCMonitor \
    207         WebProcess/Network/webrtc/LibWebRTCNetwork \
    208210        WebProcess/Network/webrtc/WebMDNSRegister \
    209211        WebProcess/Network/webrtc/WebRTCResolver \
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r274189 r274758  
    5353#include "PingLoad.h"
    5454#include "PreconnectTask.h"
     55#include "RTCDataChannelRemoteManagerProxy.h"
    5556#include "ServiceWorkerFetchTaskMessages.h"
    5657#include "WebCoreArgumentCoders.h"
     
    148149        m_rtcProvider->close();
    149150#endif
     151#if ENABLE(WEB_RTC)
     152    unregisterToRTCDataChannelProxy();
     153#endif
    150154
    151155#if ENABLE(SERVICE_WORKER)
     
    278282    callback();
    279283}
     284
     285#if ENABLE(WEB_RTC)
     286void NetworkConnectionToWebProcess::connectToRTCDataChannelRemoteSource(WebCore::RTCDataChannelIdentifier localIdentifier, WebCore::RTCDataChannelIdentifier remoteIdentifier, CompletionHandler<void(Optional<bool>)>&& callback)
     287{
     288    auto* connectionToWebProcess = m_networkProcess->webProcessConnection(remoteIdentifier.processIdentifier);
     289    if (!connectionToWebProcess) {
     290        callback(false);
     291        return;
     292    }
     293    registerToRTCDataChannelProxy();
     294    connectionToWebProcess->registerToRTCDataChannelProxy();
     295    connectionToWebProcess->connection().sendWithAsyncReply(Messages::NetworkProcessConnection::ConnectToRTCDataChannelRemoteSource { remoteIdentifier, localIdentifier }, WTFMove(callback), 0);
     296}
     297
     298void NetworkConnectionToWebProcess::registerToRTCDataChannelProxy()
     299{
     300    if (m_isRegisteredToRTCDataChannelProxy)
     301        return;
     302    m_isRegisteredToRTCDataChannelProxy = true;
     303    m_networkProcess->rtcDataChannelProxy().registerConnectionToWebProcess(*this);
     304}
     305
     306void NetworkConnectionToWebProcess::unregisterToRTCDataChannelProxy()
     307{
     308    if (m_isRegisteredToRTCDataChannelProxy)
     309        m_networkProcess->rtcDataChannelProxy().unregisterConnectionToWebProcess(*this);
     310}
     311#endif
    280312
    281313CacheStorageEngineConnection& NetworkConnectionToWebProcess::cacheStorageConnection()
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

    r274189 r274758  
    4949#include <WebCore/PageIdentifier.h>
    5050#include <WebCore/ProcessIdentifier.h>
     51#include <WebCore/RTCDataChannelIdentifier.h>
    5152#include <WebCore/RegistrableDomain.h>
    5253#include <WebCore/WebSocketIdentifier.h>
     
    251252
    252253    void createRTCProvider(CompletionHandler<void()>&&);
     254#if ENABLE(WEB_RTC)
     255    void connectToRTCDataChannelRemoteSource(WebCore::RTCDataChannelIdentifier source, WebCore::RTCDataChannelIdentifier handler, CompletionHandler<void(Optional<bool>)>&&);
     256#endif
    253257
    254258    void createNewMessagePortChannel(const WebCore::MessagePortIdentifier& port1, const WebCore::MessagePortIdentifier& port2);
     
    272276#if ENABLE(WEB_RTC)
    273277    NetworkMDNSRegister& mdnsRegister() { return m_mdnsRegister; }
     278    void registerToRTCDataChannelProxy();
     279    void unregisterToRTCDataChannelProxy();
    274280#endif
    275281
     
    386392#endif
    387393
     394#if ENABLE(WEB_RTC)
     395    bool m_isRegisteredToRTCDataChannelProxy { false };
     396#endif
     397
    388398#if ENABLE(APPLE_PAY_REMOTE_UI)
    389399    std::unique_ptr<WebPaymentCoordinatorProxy> m_paymentCoordinator;
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in

    r271946 r274758  
    8888
    8989    CreateRTCProvider() -> () Async
     90#if ENABLE(WEB_RTC)
     91    ConnectToRTCDataChannelRemoteSource(struct WebCore::RTCDataChannelIdentifier source, struct WebCore::RTCDataChannelIdentifier handler) -> (Optional<bool> result) Async
     92#endif
    9093
    9194    UpdateQuotaBasedOnSpaceUsageForTesting(struct WebCore::ClientOrigin origin)
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r274513 r274758  
    28232823#endif
    28242824
     2825#if ENABLE(WEB_RTC)
     2826RTCDataChannelRemoteManagerProxy& NetworkProcess::rtcDataChannelProxy()
     2827{
     2828    ASSERT(isMainRunLoop());
     2829    if (!m_rtcDataChannelProxy)
     2830        m_rtcDataChannelProxy = RTCDataChannelRemoteManagerProxy::create();
     2831    return *m_rtcDataChannelProxy;
     2832}
     2833#endif
     2834
    28252835} // namespace WebKit
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r274513 r274758  
    3333#include "LocalStorageDatabaseTracker.h"
    3434#include "NetworkContentRuleListManager.h"
     35#include "RTCDataChannelRemoteManagerProxy.h"
    3536#include "SandboxExtension.h"
    3637#include "WebIDBServer.h"
     
    381382#endif
    382383
     384#if ENABLE(WEB_RTC)
     385    RTCDataChannelRemoteManagerProxy& rtcDataChannelProxy();
     386#endif
     387
    383388private:
    384389    void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
     
    585590#endif
    586591   
     592#if ENABLE(WEB_RTC)
     593    RefPtr<RTCDataChannelRemoteManagerProxy> m_rtcDataChannelProxy;
     594#endif
     595
    587596    Lock m_sessionStorageQuotaManagersLock;
    588597    HashMap<PAL::SessionID, std::unique_ptr<SessionStorageQuotaManager>> m_sessionStorageQuotaManagers;
  • trunk/Source/WebKit/NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.messages.in

    r274756 r274758  
    1 # Copyright (C) 2012 Apple Inc. All rights reserved.
     1# Copyright (C) 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 messages -> NetworkProcessConnection LegacyReceiver {
     23#if ENABLE(WEB_RTC)
    2424
    25 #if ENABLE(SHAREABLE_RESOURCE)
    26     DidCacheResource(WebCore::ResourceRequest request, WebKit::ShareableResource::Handle resource)
    27 #endif
     25messages -> RTCDataChannelRemoteManagerProxy NotRefCounted {
     26    // To source
     27    SendData(struct WebCore::RTCDataChannelIdentifier source, bool isRaw, IPC::DataReference text);
     28    Close(struct WebCore::RTCDataChannelIdentifier source);
    2829
    29     DidFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError error, WebCore::ResourceResponse response)
    30     DidFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError error)
    31     SetOnLineState(bool isOnLine);
    32     CookieAcceptPolicyChanged(enum:uint8_t WebCore::HTTPCookieAcceptPolicy policy);
     30    // To handler
     31    ChangeReadyState(struct WebCore::RTCDataChannelIdentifier handler, enum:uint8_t WebCore::RTCDataChannelState state);
     32    ReceiveData(struct WebCore::RTCDataChannelIdentifier handler, bool isRaw, IPC::DataReference data);
     33    DetectError(struct WebCore::RTCDataChannelIdentifier handler);
     34    BufferedAmountIsDecreasing(struct WebCore::RTCDataChannelIdentifier handler, size_t amount);
     35}
    3336
    34 #if HAVE(COOKIE_CHANGE_LISTENER_API)
    35     CookiesAdded(String host, Vector<struct WebCore::Cookie> cookies);
    36     CookiesDeleted(String host, Vector<struct WebCore::Cookie> cookies);
    37     AllCookiesDeleted();
    38 #endif
    39 
    40     CheckProcessLocalPortForActivity(struct WebCore::MessagePortIdentifier port) -> (WebCore::MessagePortChannelProvider::HasActivity hasActivity) Async
    41     MessagesAvailableForPort(struct WebCore::MessagePortIdentifier port)
    42 
    43     BroadcastConsoleMessage(enum:uint8_t JSC::MessageSource messageSource, enum:uint8_t JSC::MessageLevel messageLevel, String message)
    44 }
     37#endif // ENABLE(WEB_RTC)
  • trunk/Source/WebKit/Sources.txt

    r273916 r274758  
    131131
    132132NetworkProcess/webrtc/NetworkMDNSRegister.cpp
     133NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.cpp
    133134
    134135// TODO: We should unify these files once GTK's PluginProcess2 is removed.
     
    631632WebProcess/Network/webrtc/LibWebRTCSocket.cpp
    632633WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp
     634WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp
    633635WebProcess/Network/webrtc/WebMDNSRegister.cpp
    634636WebProcess/Network/webrtc/WebRTCMonitor.cpp
     
    719721WebProcess/WebStorage/WebStorageNamespaceProvider.cpp
    720722
     723RTCDataChannelRemoteManagerMessageReceiver.cpp
     724RTCDataChannelRemoteManagerProxyMessageReceiver.cpp
    721725RemoteGraphicsContextGLMessageReceiver.cpp
    722726RemoteGraphicsContextGLProxyMessageReceiver.cpp
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r274697 r274758  
    36523652                410BA13A257135F2002E2F8A /* NetworkRTCSocketCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetworkRTCSocketCocoa.h; sourceTree = "<group>"; };
    36533653                4111436320F677B10026F912 /* InjectUserScriptImmediately.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectUserScriptImmediately.h; sourceTree = "<group>"; };
     3654                411223B72602152B00B0A0B6 /* RTCDataChannelRemoteManager.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = RTCDataChannelRemoteManager.messages.in; path = Network/webrtc/RTCDataChannelRemoteManager.messages.in; sourceTree = "<group>"; };
     3655                411223BB26024E8000B0A0B6 /* RTCDataChannelRemoteManagerProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RTCDataChannelRemoteManagerProxy.h; sourceTree = "<group>"; };
     3656                411223BC26024E8100B0A0B6 /* RTCDataChannelRemoteManagerProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RTCDataChannelRemoteManagerProxy.cpp; sourceTree = "<group>"; };
     3657                411223BD26024E8100B0A0B6 /* RTCDataChannelRemoteManagerProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = RTCDataChannelRemoteManagerProxy.messages.in; sourceTree = "<group>"; };
    36543658                411286EF21C8A90C003A8550 /* MediaUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaUtilities.h; sourceTree = "<group>"; };
    36553659                411286F021C8A90D003A8550 /* MediaUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaUtilities.mm; sourceTree = "<group>"; };
     
    37133717                41684C51246450FD001CE8ED /* RemoteRealtimeVideoSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteRealtimeVideoSource.h; sourceTree = "<group>"; };
    37143718                416CD74523FB178B00661D99 /* MDNSRegisterIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MDNSRegisterIdentifier.h; path = Network/webrtc/MDNSRegisterIdentifier.h; sourceTree = "<group>"; };
     3719                416EDC052600F6B000092675 /* RTCDataChannelRemoteManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = RTCDataChannelRemoteManager.cpp; path = Network/webrtc/RTCDataChannelRemoteManager.cpp; sourceTree = "<group>"; };
     3720                416EDC062600F6B000092675 /* RTCDataChannelRemoteManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RTCDataChannelRemoteManager.h; path = Network/webrtc/RTCDataChannelRemoteManager.h; sourceTree = "<group>"; };
    37153721                416F8086245B397400B68F02 /* LibWebRTCNetwork.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LibWebRTCNetwork.messages.in; path = Network/webrtc/LibWebRTCNetwork.messages.in; sourceTree = "<group>"; };
    37163722                416F8089245C7FF500B68F02 /* LibWebRTCNetwork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCNetwork.cpp; path = Network/webrtc/LibWebRTCNetwork.cpp; sourceTree = "<group>"; };
     
    82478253                                410BA13A257135F2002E2F8A /* NetworkRTCSocketCocoa.h */,
    82488254                                410BA139257135F2002E2F8A /* NetworkRTCSocketCocoa.mm */,
     8255                                411223BC26024E8100B0A0B6 /* RTCDataChannelRemoteManagerProxy.cpp */,
     8256                                411223BB26024E8000B0A0B6 /* RTCDataChannelRemoteManagerProxy.h */,
     8257                                411223BD26024E8100B0A0B6 /* RTCDataChannelRemoteManagerProxy.messages.in */,
    82498258                        );
    82508259                        path = webrtc;
     
    82678276                                413075A61DE85EE70039EC69 /* LibWebRTCSocketFactory.h */,
    82688277                                416CD74523FB178B00661D99 /* MDNSRegisterIdentifier.h */,
     8278                                416EDC052600F6B000092675 /* RTCDataChannelRemoteManager.cpp */,
     8279                                416EDC062600F6B000092675 /* RTCDataChannelRemoteManager.h */,
     8280                                411223B72602152B00B0A0B6 /* RTCDataChannelRemoteManager.messages.in */,
    82698281                                41B7ED6E20681DCF0087D853 /* WebMDNSRegister.cpp */,
    82708282                                41B7ED6C20681DCE0087D853 /* WebMDNSRegister.h */,
  • trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp

    r274189 r274758  
    3030#include "LibWebRTCNetwork.h"
    3131#include "NetworkConnectionToWebProcessMessages.h"
     32#include "RTCDataChannelRemoteManager.h"
    3233#include "StorageAreaMap.h"
    3334#include "StorageAreaMapMessages.h"
     
    321322}
    322323
     324#if ENABLE(WEB_RTC)
     325void NetworkProcessConnection::connectToRTCDataChannelRemoteSource(WebCore::RTCDataChannelIdentifier localIdentifier, WebCore::RTCDataChannelIdentifier remoteIdentifier, CompletionHandler<void(Optional<bool>)>&& callback)
     326{
     327    callback(RTCDataChannelRemoteManager::sharedManager().connectToRemoteSource(localIdentifier, remoteIdentifier));
     328}
     329#endif
     330
    323331} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h

    r274189 r274758  
    3131#include <JavaScriptCore/ConsoleTypes.h>
    3232#include <WebCore/MessagePortChannelProvider.h>
     33#include <WebCore/RTCDataChannelIdentifier.h>
    3334#include <WebCore/ServiceWorkerTypes.h>
    3435#include <wtf/RefCounted.h>
     
    110111    void didCacheResource(const WebCore::ResourceRequest&, const ShareableResource::Handle&);
    111112#endif
     113#if ENABLE(SHAREABLE_RESOURCE)
     114    void connectToRTCDataChannelRemoteSource(WebCore::RTCDataChannelIdentifier source, WebCore::RTCDataChannelIdentifier handler, CompletionHandler<void(Optional<bool>)>&&);
     115#endif
    112116
    113117    void broadcastConsoleMessage(MessageSource, MessageLevel, const String& message);
  • trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in

    r259236 r274758  
    3838#endif
    3939
     40#if ENABLE(WEB_RTC)
     41    ConnectToRTCDataChannelRemoteSource(struct WebCore::RTCDataChannelIdentifier source, struct WebCore::RTCDataChannelIdentifier handler) -> (Optional<bool> result) Async
     42#endif
     43
    4044    CheckProcessLocalPortForActivity(struct WebCore::MessagePortIdentifier port) -> (WebCore::MessagePortChannelProvider::HasActivity hasActivity) Async
    4145    MessagesAvailableForPort(struct WebCore::MessagePortIdentifier port)
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp

    r272858 r274758  
    3434
    3535#include "LibWebRTCNetwork.h"
     36#include "RTCDataChannelRemoteManager.h"
    3637#include "WebPage.h"
    3738#include "WebProcess.h"
     
    153154}
    154155
     156RefPtr<RTCDataChannelRemoteHandlerConnection> LibWebRTCProvider::createRTCDataChannelRemoteHandlerConnection()
     157{
     158    return &RTCDataChannelRemoteManager::sharedManager().remoteHandlerConnection();
     159}
     160
    155161} // namespace WebKit
    156162
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.h

    r272858 r274758  
    6161    void disableNonLocalhostConnections() final;
    6262    void startedNetworkThread() final;
     63    RefPtr<WebCore::RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
    6364
    6465#if ENABLE(GPU_PROCESS) && PLATFORM(COCOA) && !PLATFORM(MACCATALYST)
  • trunk/Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.messages.in

    r274756 r274758  
    1 # Copyright (C) 2012 Apple Inc. All rights reserved.
     1# Copyright (C) 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 messages -> NetworkProcessConnection LegacyReceiver {
     23#if ENABLE(WEB_RTC)
    2424
    25 #if ENABLE(SHAREABLE_RESOURCE)
    26     DidCacheResource(WebCore::ResourceRequest request, WebKit::ShareableResource::Handle resource)
    27 #endif
     25messages -> RTCDataChannelRemoteManager NotRefCounted {
     26    // To source
     27    SendData(struct WebCore::RTCDataChannelIdentifier source, bool isRaw, IPC::DataReference text);
     28    Close(struct WebCore::RTCDataChannelIdentifier source);
    2829
    29     DidFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError error, WebCore::ResourceResponse response)
    30     DidFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError error)
    31     SetOnLineState(bool isOnLine);
    32     CookieAcceptPolicyChanged(enum:uint8_t WebCore::HTTPCookieAcceptPolicy policy);
     30    // To handler
     31    ChangeReadyState(struct WebCore::RTCDataChannelIdentifier handler, enum:uint8_t WebCore::RTCDataChannelState state);
     32    ReceiveData(struct WebCore::RTCDataChannelIdentifier handler, bool isRaw, IPC::DataReference data);
     33    DetectError(struct WebCore::RTCDataChannelIdentifier handler);
     34    BufferedAmountIsDecreasing(struct WebCore::RTCDataChannelIdentifier handler, size_t amount);
     35}
    3336
    34 #if HAVE(COOKIE_CHANGE_LISTENER_API)
    35     CookiesAdded(String host, Vector<struct WebCore::Cookie> cookies);
    36     CookiesDeleted(String host, Vector<struct WebCore::Cookie> cookies);
    37     AllCookiesDeleted();
    38 #endif
    39 
    40     CheckProcessLocalPortForActivity(struct WebCore::MessagePortIdentifier port) -> (WebCore::MessagePortChannelProvider::HasActivity hasActivity) Async
    41     MessagesAvailableForPort(struct WebCore::MessagePortIdentifier port)
    42 
    43     BroadcastConsoleMessage(enum:uint8_t JSC::MessageSource messageSource, enum:uint8_t JSC::MessageLevel messageLevel, String message)
    44 }
     37#endif // ENABLE(WEB_RTC)
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp

    r272550 r274758  
    3434#include "NetworkConnectionToWebProcessMessages.h"
    3535#include "NetworkProcessMessages.h"
     36#include "RTCDataChannelRemoteManager.h"
    3637#include "ServiceWorkerFetchTaskMessages.h"
    3738#include "ServiceWorkerInitializationData.h"
     
    7576
    7677
     78#if ENABLE(WEB_RTC)
     79class ServiceWorkerLibWebRTCProvider final : public WebCore::LibWebRTCProvider {
     80public:
     81    ServiceWorkerLibWebRTCProvider() = default;
     82
     83private:
     84    RefPtr<WebCore::RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final { return &RTCDataChannelRemoteManager::sharedManager().remoteHandlerConnection(); }
     85};
     86#endif
     87
    7788ServiceWorkerFrameLoaderClient::ServiceWorkerFrameLoaderClient(WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, FrameIdentifier frameID, const String& userAgent)
    7889    : m_webPageProxyID(webPageProxyID)
     
    134145    pageConfiguration.socketProvider = WebSocketProvider::create();
    135146    pageConfiguration.userContentProvider = m_userContentController;
     147#if ENABLE(WEB_RTC)
     148    pageConfiguration.libWebRTCProvider = makeUniqueRef<ServiceWorkerLibWebRTCProvider>();
     149#endif
    136150
    137151    auto effectiveUserAgent =  WTFMove(userAgent);
  • trunk/Tools/ChangeLog

    r274754 r274758  
     12021-03-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Implement RTCDataChannel transfer out of process
     4        https://bugs.webkit.org/show_bug.cgi?id=223443
     5
     6        Reviewed by Eric Carlson.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9
    1102021-03-22  Youenn Fablet  <youenn@apple.com>
    211
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r274460 r274758  
    236236                3FCC4FE51EC4E8520076E37C /* PictureInPictureDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3FCC4FE41EC4E8520076E37C /* PictureInPictureDelegate.mm */; };
    237237                3FCC4FE81EC4E8CA0076E37C /* PictureInPictureDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3FCC4FE61EC4E87E0076E37C /* PictureInPictureDelegate.html */; };
     238                411223C726035FBF00B0A0B6 /* WebRTC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 411223C626035FBE00B0A0B6 /* WebRTC.mm */; };
    238239                41157237234B240C0050A1D1 /* GetUserMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41157236234B24040050A1D1 /* GetUserMedia.mm */; };
    239240                4135FB842011FAA700332139 /* InjectInternals_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4135FB832011FAA300332139 /* InjectInternals_Bundle.cpp */; };
     
    19981999                3FCC4FE41EC4E8520076E37C /* PictureInPictureDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PictureInPictureDelegate.mm; sourceTree = "<group>"; };
    19992000                3FCC4FE61EC4E87E0076E37C /* PictureInPictureDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = PictureInPictureDelegate.html; sourceTree = "<group>"; };
     2001                411223C626035FBE00B0A0B6 /* WebRTC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebRTC.mm; sourceTree = "<group>"; };
    20002002                41157236234B24040050A1D1 /* GetUserMedia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetUserMedia.mm; sourceTree = "<group>"; };
    20012003                4135FB832011FAA300332139 /* InjectInternals_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InjectInternals_Bundle.cpp; path = Tests/InjectInternals_Bundle.cpp; sourceTree = SOURCE_ROOT; };
     
    42734275                                520BCF4B141EB09E00937EA8 /* WebArchive.cpp */,
    42744276                                520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */,
     4277                                411223C626035FBE00B0A0B6 /* WebRTC.mm */,
    42754278                                7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */,
    42764279                                7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */,
     
    56795682                                448110C2253F40300097FC33 /* WebPreferencesTest.mm in Sources */,
    56805683                                51714EB81CF8CA17004723C4 /* WebProcessKillIDBCleanup.mm in Sources */,
     5684                                411223C726035FBF00B0A0B6 /* WebRTC.mm in Sources */,
    56815685                                536770341CC8022800D425B1 /* WebScriptObjectDescription.mm in Sources */,
    56825686                                5120C83D1E6751290025B250 /* WebsiteDataStoreCustomPaths.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.