Changeset 249722 in webkit


Ignore:
Timestamp:
Sep 10, 2019 10:41:32 AM (5 years ago)
Author:
youenn@apple.com
Message:

RTCPeerConnection can only be instantiated in documents
https://bugs.webkit.org/show_bug.cgi?id=201639

Reviewed by Alex Christensen.

Make it clear that RTCDataChannel expects Document since peer connections
and data channels can only be instantiated in document environments.
We keep one downcast in RTCPeerConnection constructor due to a limitation
in binding generator for JS built-ins.
No change of behavior.

  • Modules/mediastream/RTCDataChannel.cpp:

(WebCore::RTCDataChannel::create):
(WebCore::RTCDataChannel::RTCDataChannel):

  • Modules/mediastream/RTCDataChannel.h:
  • Modules/mediastream/RTCPeerConnection.cpp:

(WebCore::RTCPeerConnection::create):
(WebCore::RTCPeerConnection::RTCPeerConnection):
(WebCore::RTCPeerConnection::certificatesFromConfiguration):
(WebCore::RTCPeerConnection::createDataChannel):
(WebCore::RTCPeerConnection::document):

  • Modules/mediastream/RTCPeerConnection.h:
  • Modules/mediastream/RTCPeerConnection.idl:
  • Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:

(WebCore::LibWebRTCDataChannelHandler::channelEvent):

  • Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h:
  • Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:

(WebCore::LibWebRTCMediaEndpoint::OnDataChannel):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249718 r249722  
     12019-09-10  Youenn Fablet  <youenn@apple.com>
     2
     3        RTCPeerConnection can only be instantiated in documents
     4        https://bugs.webkit.org/show_bug.cgi?id=201639
     5
     6        Reviewed by Alex Christensen.
     7
     8        Make it clear that RTCDataChannel expects Document since peer connections
     9        and data channels can only be instantiated in document environments.
     10        We keep one downcast in RTCPeerConnection constructor due to a limitation
     11        in binding generator for JS built-ins.
     12        No change of behavior.
     13
     14        * Modules/mediastream/RTCDataChannel.cpp:
     15        (WebCore::RTCDataChannel::create):
     16        (WebCore::RTCDataChannel::RTCDataChannel):
     17        * Modules/mediastream/RTCDataChannel.h:
     18        * Modules/mediastream/RTCPeerConnection.cpp:
     19        (WebCore::RTCPeerConnection::create):
     20        (WebCore::RTCPeerConnection::RTCPeerConnection):
     21        (WebCore::RTCPeerConnection::certificatesFromConfiguration):
     22        (WebCore::RTCPeerConnection::createDataChannel):
     23        (WebCore::RTCPeerConnection::document):
     24        * Modules/mediastream/RTCPeerConnection.h:
     25        * Modules/mediastream/RTCPeerConnection.idl:
     26        * Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:
     27        (WebCore::LibWebRTCDataChannelHandler::channelEvent):
     28        * Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h:
     29        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
     30        (WebCore::LibWebRTCMediaEndpoint::OnDataChannel):
     31
    1322019-09-10  Youenn Fablet  <youenn@apple.com>
    233
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp

    r249710 r249722  
    5454}
    5555
    56 Ref<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext& context, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
     56Ref<RTCDataChannel> RTCDataChannel::create(Document& document, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
    5757{
    5858    ASSERT(handler);
    59     auto channel = adoptRef(*new RTCDataChannel(context, WTFMove(handler), WTFMove(label), WTFMove(options)));
     59    auto channel = adoptRef(*new RTCDataChannel(document, WTFMove(handler), WTFMove(label), WTFMove(options)));
    6060    channel->suspendIfNeeded();
    6161    channel->m_handler->setClient(channel.get());
     
    7979}
    8080
    81 RTCDataChannel::RTCDataChannel(ScriptExecutionContext& context, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
    82     : ActiveDOMObject(&context)
     81RTCDataChannel::RTCDataChannel(Document& document, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
     82    : ActiveDOMObject(document)
    8383    , m_handler(WTFMove(handler))
    8484    , m_scheduledEventTimer(*this, &RTCDataChannel::scheduledEventTimerFired)
    8585    , m_label(WTFMove(label))
    8686    , m_options(WTFMove(options))
    87     , m_messageQueue(createMessageQueue(downcast<Document>(context), *this))
     87    , m_messageQueue(createMessageQueue(document, *this))
    8888{
    8989}
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h

    r249710 r249722  
    5151    WTF_MAKE_ISO_ALLOCATED(RTCDataChannel);
    5252public:
    53     static Ref<RTCDataChannel> create(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
     53    static Ref<RTCDataChannel> create(Document&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
    5454
    5555    bool ordered() const { return *m_options.ordered; }
     
    8080
    8181private:
    82     RTCDataChannel(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
     82    RTCDataChannel(Document&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
    8383
    8484    static NetworkSendQueue createMessageQueue(Document&, RTCDataChannel&);
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

    r247438 r249722  
    6868Ref<RTCPeerConnection> RTCPeerConnection::create(ScriptExecutionContext& context)
    6969{
    70     auto peerConnection = adoptRef(*new RTCPeerConnection(context));
     70    auto& document = downcast<Document>(context);
     71    auto peerConnection = adoptRef(*new RTCPeerConnection(document));
    7172    peerConnection->suspendIfNeeded();
    7273    // RTCPeerConnection may send events at about any time during its lifetime.
     
    7475    if (!peerConnection->isClosed()) {
    7576        peerConnection->m_pendingActivity = peerConnection->makePendingActivity(peerConnection.get());
    76         if (auto* page = downcast<Document>(context).page()) {
     77        if (auto* page = document.page()) {
    7778            peerConnection->registerToController(page->rtcController());
    78             page->libWebRTCProvider().setEnableLogging(!context.sessionID().isEphemeral());
     79            page->libWebRTCProvider().setEnableLogging(!document.sessionID().isEphemeral());
    7980        }
    8081    }
     
    8283}
    8384
    84 RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext& context)
    85     : ActiveDOMObject(&context)
     85RTCPeerConnection::RTCPeerConnection(Document& document)
     86    : ActiveDOMObject(document)
    8687#if !RELEASE_LOG_DISABLED
    87     , m_logger(downcast<Document>(context).logger())
     88    , m_logger(document.logger())
    8889    , m_logIdentifier(reinterpret_cast<const void*>(cryptographicallyRandomNumber()))
    8990#endif
     
    9394
    9495#if !RELEASE_LOG_DISABLED
    95     auto* page = downcast<Document>(context).page();
     96    auto* page = document.page();
    9697    if (page && !page->settings().webRTCEncryptionEnabled())
    9798        ALWAYS_LOG(LOGIDENTIFIER, "encryption is disabled");
     
    319320{
    320321    auto currentMilliSeconds = WallTime::now().secondsSinceEpoch().milliseconds();
    321     auto& origin = downcast<Document>(*scriptExecutionContext()).securityOrigin();
     322    auto& origin = document()->securityOrigin();
    322323
    323324    Vector<MediaEndpointConfiguration::CertificatePEM> certificates;
     
    402403}
    403404
    404 ExceptionOr<Ref<RTCDataChannel>> RTCPeerConnection::createDataChannel(ScriptExecutionContext& context, String&& label, RTCDataChannelInit&& options)
     405ExceptionOr<Ref<RTCDataChannel>> RTCPeerConnection::createDataChannel(String&& label, RTCDataChannelInit&& options)
    405406{
    406407    ALWAYS_LOG(LOGIDENTIFIER);
     
    422423        return Exception { NotSupportedError };
    423424
    424     return RTCDataChannel::create(context, WTFMove(channelHandler), WTFMove(label), WTFMove(options));
     425    return RTCDataChannel::create(*document(), WTFMove(channelHandler), WTFMove(label), WTFMove(options));
    425426}
    426427
     
    670671}
    671672
     673Document* RTCPeerConnection::document()
     674{
     675    return downcast<Document>(scriptExecutionContext());
     676}
     677
    672678#if !RELEASE_LOG_DISABLED
    673679WTFLogChannel& RTCPeerConnection::logChannel() const
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h

    r243887 r249722  
    143143
    144144    // 6.1 Peer-to-peer data API
    145     ExceptionOr<Ref<RTCDataChannel>> createDataChannel(ScriptExecutionContext&, String&&, RTCDataChannelInit&&);
     145    ExceptionOr<Ref<RTCDataChannel>> createDataChannel(String&&, RTCDataChannelInit&&);
    146146
    147147    // 8.2 Statistics API
     
    175175    // ActiveDOMObject.
    176176    bool hasPendingActivity() const final;
     177   
     178    Document* document();
    177179
    178180#if !RELEASE_LOG_DISABLED
     
    184186
    185187private:
    186     RTCPeerConnection(ScriptExecutionContext&);
     188    RTCPeerConnection(Document&);
    187189
    188190    ExceptionOr<void> initializeConfiguration(RTCConfiguration&&);
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.idl

    r238100 r249722  
    7474    ActiveDOMObject,
    7575    Conditional=WEB_RTC,
    76     ConstructorCallWith=ScriptExecutionContext,
     76    ConstructorCallWith=Document,
    7777    EnabledAtRuntime=PeerConnection,
    7878    ExportMacro=WEBCORE_EXPORT,
     
    147147    // FIXME 169644: missing sctp
    148148
    149     [CallWith=ScriptExecutionContext, MayThrowException] RTCDataChannel createDataChannel([TreatNullAs=EmptyString] USVString label, optional RTCDataChannelInit options);
     149    [MayThrowException] RTCDataChannel createDataChannel([TreatNullAs=EmptyString] USVString label, optional RTCDataChannelInit options);
    150150    attribute EventHandler ondatachannel;
    151151
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp

    r248846 r249722  
    5757}
    5858
    59 Ref<RTCDataChannelEvent> LibWebRTCDataChannelHandler::channelEvent(ScriptExecutionContext& context, rtc::scoped_refptr<webrtc::DataChannelInterface>&& dataChannel)
     59Ref<RTCDataChannelEvent> LibWebRTCDataChannelHandler::channelEvent(Document& document, rtc::scoped_refptr<webrtc::DataChannelInterface>&& dataChannel)
    6060{
    6161    auto protocol = dataChannel->protocol();
     
    7171
    7272    auto handler =  makeUnique<LibWebRTCDataChannelHandler>(WTFMove(dataChannel));
    73     auto channel = RTCDataChannel::create(context, WTFMove(handler), fromStdString(label), WTFMove(init));
     73    auto channel = RTCDataChannel::create(document, WTFMove(handler), fromStdString(label), WTFMove(init));
    7474
    7575    return RTCDataChannelEvent::create(eventNames().datachannelEvent, Event::CanBubble::No, Event::IsCancelable::No, WTFMove(channel));
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h

    r241183 r249722  
    4242namespace WebCore {
    4343
     44class Document;
    4445class RTCDataChannelEvent;
    4546class RTCDataChannelHandlerClient;
     
    5455
    5556    static webrtc::DataChannelInit fromRTCDataChannelInit(const RTCDataChannelInit&);
    56     static Ref<RTCDataChannelEvent> channelEvent(ScriptExecutionContext&, rtc::scoped_refptr<webrtc::DataChannelInterface>&&);
     57    static Ref<RTCDataChannelEvent> channelEvent(Document&, rtc::scoped_refptr<webrtc::DataChannelInterface>&&);
    5758
    5859private:
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

    r248846 r249722  
    664664            return;
    665665        auto& connection = protectedThis->m_peerConnectionBackend.connection();
    666         connection.fireEvent(LibWebRTCDataChannelHandler::channelEvent(*connection.scriptExecutionContext(), WTFMove(dataChannel)));
     666        connection.fireEvent(LibWebRTCDataChannelHandler::channelEvent(*connection.document(), WTFMove(dataChannel)));
    667667    });
    668668}
Note: See TracChangeset for help on using the changeset viewer.