Commit e589565c authored by Steve Anton's avatar Steve Anton Committed by Commit Bot

Add RTCQuicTransport IDL + binding skeleton

Bug: 868068
Change-Id: I55bed5a6a35bec88b76066eb477914eb571104c7
Reviewed-on: https://chromium-review.googlesource.com/1167902
Commit-Queue: Steve Anton <steveanton@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585997}
parent 633a77ea
<!doctype html>
<meta charset=utf-8>
<title>RTCQuicTransport.https.html</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
// These tests are based on the following specification:
// https://w3c.github.io/webrtc-quic/
function makeQuicTransport(t, certificates) {
const iceTransport = new RTCIceTransport();
t.add_cleanup(() => iceTransport.stop());
const quicTransport = new RTCQuicTransport(iceTransport, certificates);
t.add_cleanup(() => quicTransport.stop());
return quicTransport;
}
function generateCertificate(keygenAlgorithm) {
return RTCPeerConnection.generateCertificate({
name: 'ECDSA',
namedCurve: 'P-256',
...keygenAlgorithm,
});
}
test(t => {
// Don't use the makeQuicTransport helper so that the transport property can
// be verified.
const iceTransport = new RTCIceTransport();
const quicTransport = new RTCQuicTransport(iceTransport, []);
t.add_cleanup(() => {
quicTransport.stop();
iceTransport.stop();
});
assert_equals(quicTransport.transport, iceTransport,
'Expect transport to be the same as the one passed in the constructor.');
assert_equals(quicTransport.state, 'new', `Expect state to be 'new'.`);
assert_object_equals(quicTransport.getLocalParameters(),
{ role: 'auto', fingerprints: [] },
'Expect local parameters to be initialized.');
assert_equals(quicTransport.getRemoteParameters(), null,
'Expect no remote parameters.');
assert_array_equals(quicTransport.getCertificates(), [],
'Expect not certificates.');
assert_array_equals(quicTransport.getRemoteCertificates(), [],
'Expect no remote certificates.');
}, 'RTCQuicTransport initial properties are set.');
promise_test(async t => {
const [ firstCertificate, secondCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
const quicTransport =
makeQuicTransport(t, [ firstCertificate, secondCertificate ]);
assert_array_equals(quicTransport.getCertificates(),
[ firstCertificate, secondCertificate ]);
}, 'getCertificates() returns the certificates passed in the constructor.');
promise_test(async t => {
const [ firstCertificate, secondCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
const quicTransport =
makeQuicTransport(t, [ firstCertificate, secondCertificate ]);
assert_object_equals(quicTransport.getLocalParameters(), {
role: 'auto',
fingerprints: [ firstCertificate.getFingerprints()[0],
secondCertificate.getFingerprints()[0] ],
});
assert_array_equals(quicTransport.getCertificates(),
[ firstCertificate, secondCertificate ]);
}, 'getLocalParameters() has fingerprints for all certificates passed in the ' +
'constructor.');
promise_test(async t => {
const expiredCertificate = await generateCertificate({ expires: 0 });
assert_throws(new TypeError(),
() => makeQuicTransport(t, [ expiredCertificate ]));
}, 'RTCQuicTransport constructor throws if passed an expired certificate.');
test(t => {
const iceTransport = new RTCIceTransport();
iceTransport.stop();
assert_throws('InvalidStateError',
() => new RTCQuicTransport(iceTransport, []));
}, 'RTCQuicTransport constructor throws if passed a closed RTCIceTransport.');
test(t => {
const quicTransport = makeQuicTransport(t, []);
quicTransport.stop();
assert_equals(quicTransport.state, 'closed');
}, `stop() changes state to 'closed'.`);
</script>
...@@ -5509,6 +5509,16 @@ interface RTCPeerConnectionIceEvent : Event ...@@ -5509,6 +5509,16 @@ interface RTCPeerConnectionIceEvent : Event
attribute @@toStringTag attribute @@toStringTag
getter candidate getter candidate
method constructor method constructor
interface RTCQuicTransport
attribute @@toStringTag
getter state
getter transport
method constructor
method getCertificates
method getLocalParameters
method getRemoteCertificates
method getRemoteParameters
method stop
interface RTCRtpContributingSource interface RTCRtpContributingSource
attribute @@toStringTag attribute @@toStringTag
getter source getter source
......
...@@ -222,6 +222,7 @@ modules_idl_files = ...@@ -222,6 +222,7 @@ modules_idl_files =
"peerconnection/rtc_legacy_stats_report.idl", "peerconnection/rtc_legacy_stats_report.idl",
"peerconnection/rtc_peer_connection.idl", "peerconnection/rtc_peer_connection.idl",
"peerconnection/rtc_peer_connection_ice_event.idl", "peerconnection/rtc_peer_connection_ice_event.idl",
"peerconnection/rtc_quic_transport.idl",
"peerconnection/rtc_rtp_contributing_source.idl", "peerconnection/rtc_rtp_contributing_source.idl",
"peerconnection/rtc_rtp_receiver.idl", "peerconnection/rtc_rtp_receiver.idl",
"peerconnection/rtc_rtp_sender.idl", "peerconnection/rtc_rtp_sender.idl",
...@@ -597,6 +598,7 @@ modules_dictionary_idl_files = ...@@ -597,6 +598,7 @@ modules_dictionary_idl_files =
"peerconnection/rtc_offer_answer_options.idl", "peerconnection/rtc_offer_answer_options.idl",
"peerconnection/rtc_offer_options.idl", "peerconnection/rtc_offer_options.idl",
"peerconnection/rtc_peer_connection_ice_event_init.idl", "peerconnection/rtc_peer_connection_ice_event_init.idl",
"peerconnection/rtc_quic_parameters.idl",
"peerconnection/rtc_rtcp_parameters.idl", "peerconnection/rtc_rtcp_parameters.idl",
"peerconnection/rtc_rtp_capabilities.idl", "peerconnection/rtc_rtp_capabilities.idl",
"peerconnection/rtc_rtp_codec_capability.idl", "peerconnection/rtc_rtp_codec_capability.idl",
......
...@@ -34,6 +34,8 @@ blink_modules_sources("peerconnection") { ...@@ -34,6 +34,8 @@ blink_modules_sources("peerconnection") {
"rtc_peer_connection.h", "rtc_peer_connection.h",
"rtc_peer_connection_ice_event.cc", "rtc_peer_connection_ice_event.cc",
"rtc_peer_connection_ice_event.h", "rtc_peer_connection_ice_event.h",
"rtc_quic_transport.cc",
"rtc_quic_transport.h",
"rtc_rtp_contributing_source.cc", "rtc_rtp_contributing_source.cc",
"rtc_rtp_contributing_source.h", "rtc_rtp_contributing_source.h",
"rtc_rtp_receiver.cc", "rtc_rtp_receiver.cc",
......
...@@ -52,6 +52,8 @@ class MODULES_EXPORT RTCIceTransport final ...@@ -52,6 +52,8 @@ class MODULES_EXPORT RTCIceTransport final
~RTCIceTransport() override; ~RTCIceTransport() override;
bool IsClosed() const { return state_ == RTCIceTransportState::kClosed; }
// rtc_ice_transport.idl // rtc_ice_transport.idl
String role() const; String role() const;
String state() const; String state() const;
...@@ -99,7 +101,6 @@ class MODULES_EXPORT RTCIceTransport final ...@@ -99,7 +101,6 @@ class MODULES_EXPORT RTCIceTransport final
// password. // password.
void GenerateLocalParameters(); void GenerateLocalParameters();
bool IsClosed() const { return state_ == RTCIceTransportState::kClosed; }
bool RaiseExceptionIfClosed(ExceptionState& exception_state) const; bool RaiseExceptionIfClosed(ExceptionState& exception_state) const;
cricket::IceRole role_ = cricket::ICEROLE_UNKNOWN; cricket::IceRole role_ = cricket::ICEROLE_UNKNOWN;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webrtc-quic/#dom-rtcquicrole
enum RTCQuicRole {
"auto",
"client",
"server",
};
// https://w3c.github.io/webrtc-quic/#rtcquicparameters*
dictionary RTCQuicParameters {
RTCQuicRole role = "auto";
sequence<RTCDtlsFingerprint> fingerprints;
};
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/peerconnection/rtc_quic_transport.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_certificate.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_ice_transport.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_quic_parameters.h"
namespace blink {
RTCQuicTransport* RTCQuicTransport::Create(
RTCIceTransport* transport,
const HeapVector<Member<RTCCertificate>>& certificates,
ExceptionState& exception_state) {
if (transport->IsClosed()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
"Cannot construct an RTCQuicTransport with a closed RTCIceTransport.");
return nullptr;
}
for (const auto& certificate : certificates) {
if (certificate->expires() < ConvertSecondsToDOMTimeStamp(CurrentTime())) {
exception_state.ThrowTypeError(
"Cannot construct an RTCQuicTransport with an expired certificate.");
return nullptr;
}
}
return new RTCQuicTransport(transport, certificates, exception_state);
}
RTCQuicTransport::RTCQuicTransport(
RTCIceTransport* transport,
const HeapVector<Member<RTCCertificate>>& certificates,
ExceptionState& exception_state)
: transport_(transport), certificates_(certificates) {}
RTCQuicTransport::~RTCQuicTransport() = default;
RTCIceTransport* RTCQuicTransport::transport() const {
return transport_;
}
String RTCQuicTransport::state() const {
switch (state_) {
case RTCQuicTransportState::kNew:
return "new";
case RTCQuicTransportState::kConnecting:
return "connecting";
case RTCQuicTransportState::kConnected:
return "connected";
case RTCQuicTransportState::kClosed:
return "closed";
case RTCQuicTransportState::kFailed:
return "failed";
}
return String();
}
void RTCQuicTransport::getLocalParameters(RTCQuicParameters& result) const {
HeapVector<RTCDtlsFingerprint> fingerprints;
for (const auto& certificate : certificates_) {
// TODO(github.com/w3c/webrtc-quic/issues/33): The specification says that
// getLocalParameters should return one fingerprint per certificate but is
// not clear which one to pick if an RTCCertificate has multiple
// fingerprints.
for (const auto& certificate_fingerprint : certificate->getFingerprints()) {
fingerprints.push_back(certificate_fingerprint);
}
}
result.setFingerprints(fingerprints);
}
void RTCQuicTransport::getRemoteParameters(
base::Optional<RTCQuicParameters>& result) const {
result = base::nullopt;
}
const HeapVector<Member<RTCCertificate>>& RTCQuicTransport::getCertificates()
const {
return certificates_;
}
const HeapVector<Member<DOMArrayBuffer>>&
RTCQuicTransport::getRemoteCertificates() const {
return remote_certificates_;
}
void RTCQuicTransport::stop() {
state_ = RTCQuicTransportState::kClosed;
}
void RTCQuicTransport::Trace(blink::Visitor* visitor) {
visitor->Trace(transport_);
visitor->Trace(certificates_);
visitor->Trace(remote_certificates_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_RTC_QUIC_TRANSPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_RTC_QUIC_TRANSPORT_H_
#include "third_party/blink/renderer/modules/peerconnection/rtc_quic_parameters.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
namespace blink {
class DOMArrayBuffer;
class ExceptionState;
class RTCCertificate;
class RTCIceTransport;
class RTCQuicParameters;
enum class RTCQuicTransportState {
kNew,
kConnecting,
kConnected,
kClosed,
kFailed
};
class MODULES_EXPORT RTCQuicTransport final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static RTCQuicTransport* Create(
RTCIceTransport* transport,
const HeapVector<Member<RTCCertificate>>& certificates,
ExceptionState& exception_state);
~RTCQuicTransport() override;
// https://w3c.github.io/webrtc-quic/#quic-transport*
RTCIceTransport* transport() const;
String state() const;
void getLocalParameters(RTCQuicParameters& result) const;
void getRemoteParameters(base::Optional<RTCQuicParameters>& result) const;
const HeapVector<Member<RTCCertificate>>& getCertificates() const;
const HeapVector<Member<DOMArrayBuffer>>& getRemoteCertificates() const;
void stop();
// For garbage collection.
void Trace(blink::Visitor* visitor) override;
private:
RTCQuicTransport(RTCIceTransport* transport,
const HeapVector<Member<RTCCertificate>>& certificates,
ExceptionState& exception_state);
Member<RTCIceTransport> transport_;
RTCQuicTransportState state_ = RTCQuicTransportState::kNew;
HeapVector<Member<RTCCertificate>> certificates_;
HeapVector<Member<DOMArrayBuffer>> remote_certificates_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_RTC_QUIC_TRANSPORT_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webrtc-quic/#dom-rtcquictransportstate
enum RTCQuicTransportState {
"new",
"connecting",
"connected",
"closed",
"failed",
};
// https://w3c.github.io/webrtc-quic/#quic-transport*
[
Constructor(RTCIceTransport transport, sequence<RTCCertificate> certificates),
RaisesException=Constructor,
Exposed=Window,
RuntimeEnabled=RTCQuicTransport
] interface RTCQuicTransport {
readonly attribute RTCIceTransport transport;
readonly attribute RTCQuicTransportState state;
RTCQuicParameters getLocalParameters();
RTCQuicParameters? getRemoteParameters();
sequence<RTCCertificate> getCertificates();
sequence<ArrayBuffer> getRemoteCertificates();
void stop();
// TODO(crbug.com/868068): Implement remaining control methods + events.
};
...@@ -1028,6 +1028,11 @@ ...@@ -1028,6 +1028,11 @@
origin_trial_feature_name: "RtcPeerConnectionId", origin_trial_feature_name: "RtcPeerConnectionId",
status: "experimental", status: "experimental",
}, },
// Enables the use of the RTCQuicTransport object.
{
name: "RTCQuicTransport",
status: "test",
},
{ {
name: "RTCRtpSenderParameters", name: "RTCRtpSenderParameters",
status: "stable", status: "stable",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment