Skip to content

Commit 409a45f

Browse files
committed
Bug 1974444: Move RTCDataChannel's const attrs to the DOM object, and associated cleanup. r=mjf
Differential Revision: https://phabricator.services.mozilla.com/D255376
1 parent 7b1e3cd commit 409a45f

File tree

10 files changed

+97
-94
lines changed

10 files changed

+97
-94
lines changed

dom/base/nsDOMDataChannel.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,23 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMDataChannel)
7171
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
7272

7373
nsDOMDataChannel::nsDOMDataChannel(
74+
const nsAString& aLabel, bool aOrdered,
75+
mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
76+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
77+
const nsAString& aProtocol, bool aNegotiated,
7478
already_AddRefed<mozilla::DataChannel>& aDataChannel,
7579
nsPIDOMWindowInner* aWindow)
7680
: DOMEventTargetHelper(aWindow),
7781
mDataChannel(aDataChannel),
7882
mBinaryType(DC_BINARY_TYPE_BLOB),
7983
mCheckMustKeepAlive(true),
80-
mSentClose(false) {}
84+
mSentClose(false),
85+
mLabel(aLabel),
86+
mOrdered(aOrdered),
87+
mMaxPacketLifeTime(aMaxLifeTime),
88+
mMaxRetransmits(aMaxRetransmits),
89+
mProtocol(aProtocol),
90+
mNegotiated(aNegotiated) {}
8191

8292
nsresult nsDOMDataChannel::Init(nsPIDOMWindowInner* aDOMWindow) {
8393
nsresult rv;
@@ -111,12 +121,10 @@ nsresult nsDOMDataChannel::Init(nsPIDOMWindowInner* aDOMWindow) {
111121

112122
// Most of the GetFoo()/SetFoo()s don't need to touch shared resources and
113123
// are safe after Close()
114-
void nsDOMDataChannel::GetLabel(nsAString& aLabel) {
115-
mDataChannel->GetLabel(aLabel);
116-
}
124+
void nsDOMDataChannel::GetLabel(nsAString& aLabel) const { aLabel = mLabel; }
117125

118-
void nsDOMDataChannel::GetProtocol(nsAString& aProtocol) {
119-
mDataChannel->GetProtocol(aProtocol);
126+
void nsDOMDataChannel::GetProtocol(nsAString& aProtocol) const {
127+
aProtocol = mProtocol;
120128
}
121129

122130
mozilla::dom::Nullable<uint16_t> nsDOMDataChannel::GetId() const {
@@ -127,26 +135,18 @@ mozilla::dom::Nullable<uint16_t> nsDOMDataChannel::GetId() const {
127135
return result;
128136
}
129137

130-
// XXX should be GetType()? Open question for the spec
131-
bool nsDOMDataChannel::Reliable() const {
132-
return mDataChannel->GetType() ==
133-
mozilla::DataChannelReliabilityPolicy::Reliable;
134-
}
135-
136138
mozilla::dom::Nullable<uint16_t> nsDOMDataChannel::GetMaxPacketLifeTime()
137139
const {
138-
return mDataChannel->GetMaxPacketLifeTime();
140+
return mMaxPacketLifeTime;
139141
}
140142

141143
mozilla::dom::Nullable<uint16_t> nsDOMDataChannel::GetMaxRetransmits() const {
142-
return mDataChannel->GetMaxRetransmits();
144+
return mMaxRetransmits;
143145
}
144146

145-
bool nsDOMDataChannel::Negotiated() const {
146-
return mDataChannel->GetNegotiated();
147-
}
147+
bool nsDOMDataChannel::Negotiated() const { return mNegotiated; }
148148

149-
bool nsDOMDataChannel::Ordered() const { return mDataChannel->GetOrdered(); }
149+
bool nsDOMDataChannel::Ordered() const { return mOrdered; }
150150

151151
RTCDataChannelState nsDOMDataChannel::ReadyState() const {
152152
return static_cast<RTCDataChannelState>(mDataChannel->GetReadyState());
@@ -493,8 +493,14 @@ void nsDOMDataChannel::EventListenerRemoved(nsAtom* aType) {
493493
/* static */
494494
nsresult NS_NewDOMDataChannel(
495495
already_AddRefed<mozilla::DataChannel>&& aDataChannel,
496-
nsPIDOMWindowInner* aWindow, nsDOMDataChannel** aDomDataChannel) {
497-
RefPtr<nsDOMDataChannel> domdc = new nsDOMDataChannel(aDataChannel, aWindow);
496+
const nsAString& aLabel, bool aOrdered,
497+
mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
498+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
499+
const nsAString& aProtocol, bool aNegotiated, nsPIDOMWindowInner* aWindow,
500+
nsDOMDataChannel** aDomDataChannel) {
501+
RefPtr<nsDOMDataChannel> domdc =
502+
new nsDOMDataChannel(aLabel, aOrdered, aMaxLifeTime, aMaxRetransmits,
503+
aProtocol, aNegotiated, aDataChannel, aWindow);
498504

499505
nsresult rv = domdc->Init(aWindow);
500506
NS_ENSURE_SUCCESS(rv, rv);

dom/base/nsDOMDataChannel.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "mozilla/Attributes.h"
1111
#include "mozilla/DOMEventTargetHelper.h"
12+
#include "mozilla/dom/Nullable.h"
1213
#include "mozilla/dom/RTCDataChannelBinding.h"
1314
#include "mozilla/dom/TypedArray.h"
1415
#include "mozilla/net/DataChannelListener.h"
@@ -24,7 +25,11 @@ class DataChannel;
2425
class nsDOMDataChannel final : public mozilla::DOMEventTargetHelper,
2526
public mozilla::DataChannelListener {
2627
public:
27-
nsDOMDataChannel(already_AddRefed<mozilla::DataChannel>& aDataChannel,
28+
nsDOMDataChannel(const nsAString& aLabel, bool aOrdered,
29+
mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
30+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
31+
const nsAString& aProtocol, bool aNegotiated,
32+
already_AddRefed<mozilla::DataChannel>& aDataChannel,
2833
nsPIDOMWindowInner* aWindow);
2934

3035
nsresult Init(nsPIDOMWindowInner* aDOMWindow);
@@ -45,9 +50,8 @@ class nsDOMDataChannel final : public mozilla::DOMEventTargetHelper,
4550
nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
4651

4752
// WebIDL
48-
void GetLabel(nsAString& aLabel);
49-
void GetProtocol(nsAString& aProtocol);
50-
bool Reliable() const;
53+
void GetLabel(nsAString& aLabel) const;
54+
void GetProtocol(nsAString& aProtocol) const;
5155
mozilla::dom::Nullable<uint16_t> GetMaxPacketLifeTime() const;
5256
mozilla::dom::Nullable<uint16_t> GetMaxRetransmits() const;
5357
mozilla::dom::RTCDataChannelState ReadyState() const;
@@ -123,6 +127,13 @@ class nsDOMDataChannel final : public mozilla::DOMEventTargetHelper,
123127
DataChannelBinaryType mBinaryType;
124128
bool mCheckMustKeepAlive;
125129
bool mSentClose;
130+
131+
const nsString mLabel;
132+
const bool mOrdered;
133+
const mozilla::dom::Nullable<uint16_t> mMaxPacketLifeTime;
134+
const mozilla::dom::Nullable<uint16_t> mMaxRetransmits;
135+
const nsString mProtocol;
136+
const bool mNegotiated;
126137
};
127138

128139
#endif // nsDOMDataChannel_h

dom/base/nsDOMDataChannelDeclarations.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@
1111
// gets used with MOZ_INTERNAL_API not set for media/webrtc/signaling/testing
1212

1313
#include "nsCOMPtr.h"
14+
#include "nsStringFwd.h"
15+
#include "mozilla/dom/Nullable.h"
1416

1517
namespace mozilla {
1618
class DataChannel;
17-
}
19+
} // namespace mozilla
1820

1921
class nsDOMDataChannel;
2022
class nsPIDOMWindowInner;
2123

2224
nsresult NS_NewDOMDataChannel(
23-
already_AddRefed<mozilla::DataChannel>&& dataChannel,
24-
nsPIDOMWindowInner* aWindow, nsDOMDataChannel** domDataChannel);
25+
already_AddRefed<mozilla::DataChannel>&& aDataChannel,
26+
const nsAString& aLabel, bool aOrdered,
27+
mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
28+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
29+
const nsAString& aProtocol, bool aNegotiated, nsPIDOMWindowInner* aWindow,
30+
nsDOMDataChannel** aDomDataChannel);
2531

2632
#endif // nsDOMDataChannelDeclarations_h

dom/media/webrtc/jsapi/PeerConnectionImpl.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,15 +1012,19 @@ PeerConnectionImpl::CreateDataChannel(
10121012

10131013
RefPtr<DataChannel> dataChannel;
10141014
DataChannelReliabilityPolicy prPolicy;
1015+
Nullable<uint16_t> maxLifeTime;
1016+
Nullable<uint16_t> maxRetransmits;
10151017
switch (aType) {
10161018
case IPeerConnection::kDataChannelReliable:
10171019
prPolicy = DataChannelReliabilityPolicy::Reliable;
10181020
break;
10191021
case IPeerConnection::kDataChannelPartialReliableRexmit:
10201022
prPolicy = DataChannelReliabilityPolicy::LimitedRetransmissions;
1023+
maxRetransmits.SetValue(aMaxNum);
10211024
break;
10221025
case IPeerConnection::kDataChannelPartialReliableTimed:
10231026
prPolicy = DataChannelReliabilityPolicy::LimitedLifetime;
1027+
maxLifeTime.SetValue(aMaxTime);
10241028
break;
10251029
default:
10261030
MOZ_ASSERT(false);
@@ -1065,8 +1069,9 @@ PeerConnectionImpl::CreateDataChannel(
10651069
}
10661070

10671071
RefPtr<nsDOMDataChannel> retval;
1068-
rv = NS_NewDOMDataChannel(dataChannel.forget(), mWindow,
1069-
getter_AddRefs(retval));
1072+
rv = NS_NewDOMDataChannel(dataChannel.forget(), aLabel, ordered, maxLifeTime,
1073+
maxRetransmits, aProtocol, aExternalNegotiated,
1074+
mWindow, getter_AddRefs(retval));
10701075
if (NS_FAILED(rv)) {
10711076
return rv;
10721077
}
@@ -1350,16 +1355,20 @@ RefPtr<dom::RTCRtpTransceiver> PeerConnectionImpl::GetTransceiver(
13501355
}
13511356

13521357
void PeerConnectionImpl::NotifyDataChannel(
1353-
already_AddRefed<DataChannel> aChannel) {
1358+
already_AddRefed<DataChannel> aChannel, const nsAString& aLabel,
1359+
bool aOrdered, mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
1360+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
1361+
const nsAString& aProtocol, bool aNegotiated) {
13541362
PC_AUTO_ENTER_API_CALL_NO_CHECK();
13551363

13561364
RefPtr<DataChannel> channel(aChannel);
13571365
MOZ_ASSERT(channel);
13581366
CSFLogDebug(LOGTAG, "%s: channel: %p", __FUNCTION__, channel.get());
13591367

13601368
RefPtr<nsDOMDataChannel> domchannel;
1361-
nsresult rv = NS_NewDOMDataChannel(channel.forget(), mWindow,
1362-
getter_AddRefs(domchannel));
1369+
nsresult rv = NS_NewDOMDataChannel(
1370+
channel.forget(), aLabel, aOrdered, aMaxLifeTime, aMaxRetransmits,
1371+
aProtocol, aNegotiated, mWindow, getter_AddRefs(domchannel));
13631372
NS_ENSURE_SUCCESS_VOID(rv);
13641373

13651374
JSErrorResult jrv;

dom/media/webrtc/jsapi/PeerConnectionImpl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ class PeerConnectionImpl final
202202
return DefaultCodecPreferences(aOverrideRtxPreference);
203203
}
204204
// DataConnection observers
205-
void NotifyDataChannel(already_AddRefed<mozilla::DataChannel> aChannel)
205+
void NotifyDataChannel(already_AddRefed<DataChannel> aChannel,
206+
const nsAString& aLabel, bool aOrdered,
207+
mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
208+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
209+
const nsAString& aProtocol, bool aNegotiated)
206210
// PeerConnectionImpl only inherits from mozilla::DataChannelConnection
207211
// inside libxul.
208212
override;

dom/media/webrtc/tests/mochitests/dataChannel.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,6 @@ var commandsCheckDataChannel = [
162162
options.protocol,
163163
result.local + " protocol is:" + result.local.protocol
164164
);
165-
is(
166-
result.local.reliable,
167-
false,
168-
result.local + " reliable is:" + result.local.reliable
169-
);
170165
is(
171166
result.local.ordered,
172167
options.ordered,
@@ -198,11 +193,6 @@ var commandsCheckDataChannel = [
198193
options.protocol,
199194
result.remote + " protocol is:" + result.remote.protocol
200195
);
201-
is(
202-
result.remote.reliable,
203-
false,
204-
result.remote + " reliable is:" + result.remote.reliable
205-
);
206196
is(
207197
result.remote.ordered,
208198
options.ordered,
@@ -254,11 +244,6 @@ var commandsCheckDataChannel = [
254244
"",
255245
result.local + " protocol is:" + result.local.protocol
256246
);
257-
is(
258-
result.local.reliable,
259-
false,
260-
result.local + " reliable is:" + result.local.reliable
261-
);
262247
is(
263248
result.local.ordered,
264249
options.ordered,
@@ -285,11 +270,6 @@ var commandsCheckDataChannel = [
285270
"",
286271
result.remote + " protocol is:" + result.remote.protocol
287272
);
288-
is(
289-
result.remote.reliable,
290-
false,
291-
result.remote + " reliable is:" + result.remote.reliable
292-
);
293273
is(
294274
result.remote.ordered,
295275
options.ordered,

dom/media/webrtc/tests/mochitests/pc.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,6 @@ DataChannelWrapper.prototype = {
764764
return this._channel.id;
765765
},
766766

767-
/**
768-
* Returns the reliable state of the underlying data channel
769-
*
770-
* @returns {bool} The stream's reliable state
771-
*/
772-
get reliable() {
773-
return this._channel.reliable;
774-
},
775-
776767
/**
777768
* Returns the ordered attribute of the data channel
778769
*

netwerk/sctp/datachannel/DataChannel.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ void DataChannelConnection::HandleOpenRequestMessage(
537537
const struct rtcweb_datachannel_open_request* req, uint32_t length,
538538
uint16_t stream) {
539539
MOZ_ASSERT(mSTS->IsOnCurrentThread());
540-
uint32_t prValue;
541540
DataChannelReliabilityPolicy prPolicy;
542541

543542
const size_t requiredLength = (sizeof(*req) - 1) + ntohs(req->label_length) +
@@ -581,7 +580,7 @@ void DataChannelConnection::HandleOpenRequestMessage(
581580
return;
582581
}
583582

584-
prValue = ntohl(req->reliability_param);
583+
const uint32_t prValue = ntohl(req->reliability_param);
585584
const bool ordered = !(req->channel_type & 0x80);
586585
const nsCString label(&req->label[0], ntohs(req->label_length));
587586
const nsCString protocol(&req->label[ntohs(req->label_length)],
@@ -622,9 +621,30 @@ void DataChannelConnection::HandleOpenRequestMessage(
622621

623622
DC_DEBUG(("%s: sending ON_CHANNEL_CREATED for %s/%s: %u", __FUNCTION__,
624623
channel->mLabel.get(), channel->mProtocol.get(), stream));
624+
625+
// Awkward. If we convert over to using Maybe for this in DataChannel,
626+
// we won't need to have this extra conversion, since Nullable converts
627+
// easily to Maybe.
628+
dom::Nullable<uint16_t> maxLifeTime;
629+
dom::Nullable<uint16_t> maxRetransmits;
630+
if (prPolicy == DataChannelReliabilityPolicy::LimitedLifetime) {
631+
maxLifeTime.SetValue(std::min(std::numeric_limits<uint16_t>::max(),
632+
(uint16_t)prValue));
633+
} else if (prPolicy ==
634+
DataChannelReliabilityPolicy::LimitedRetransmissions) {
635+
maxRetransmits.SetValue(std::min(std::numeric_limits<uint16_t>::max(),
636+
(uint16_t)prValue));
637+
}
638+
625639
if (mListener) {
626640
// important to give it an already_AddRefed pointer!
627-
mListener->NotifyDataChannel(do_AddRef(channel));
641+
// TODO(bug 1974443): Have nsDOMDataChannel create the DataChannel
642+
// object, or have DataChannel take an nsDOMDataChannel, to avoid
643+
// passing this param list more than once?
644+
mListener->NotifyDataChannel(do_AddRef(channel),
645+
NS_ConvertUTF8toUTF16(label), ordered,
646+
maxLifeTime, maxRetransmits,
647+
NS_ConvertUTF8toUTF16(protocol), false);
628648
// Spec says to queue this in the queued task for ondatachannel
629649
channel->AnnounceOpen();
630650
}
@@ -1690,20 +1710,6 @@ void DataChannel::SendBinaryBlob(dom::Blob& aBlob, ErrorResult& aRv) {
16901710
}
16911711
}
16921712

1693-
dom::Nullable<uint16_t> DataChannel::GetMaxPacketLifeTime() const {
1694-
if (mPrPolicy == DataChannelReliabilityPolicy::LimitedLifetime) {
1695-
return dom::Nullable<uint16_t>(mPrValue);
1696-
}
1697-
return dom::Nullable<uint16_t>();
1698-
}
1699-
1700-
dom::Nullable<uint16_t> DataChannel::GetMaxRetransmits() const {
1701-
if (mPrPolicy == DataChannelReliabilityPolicy::LimitedRetransmissions) {
1702-
return dom::Nullable<uint16_t>(mPrValue);
1703-
}
1704-
return dom::Nullable<uint16_t>();
1705-
}
1706-
17071713
uint32_t DataChannel::GetBufferedAmountLowThreshold() const {
17081714
return mBufferedThreshold;
17091715
}

netwerk/sctp/datachannel/DataChannel.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ class DataChannelConnection : public net::NeckoTargetHolder {
145145
virtual ~DataConnectionListener() = default;
146146

147147
// Called when a new DataChannel has been opened by the other side.
148-
virtual void NotifyDataChannel(already_AddRefed<DataChannel> channel) = 0;
148+
virtual void NotifyDataChannel(
149+
already_AddRefed<DataChannel> aChannel, const nsAString& aLabel,
150+
bool aOrdered, mozilla::dom::Nullable<uint16_t> aMaxLifeTime,
151+
mozilla::dom::Nullable<uint16_t> aMaxRetransmits,
152+
const nsAString& aProtocol, bool aNegotiated) = 0;
149153

150154
// Called when a DataChannel transitions to state open
151155
virtual void NotifyDataChannelOpen(DataChannel* aChannel) = 0;
@@ -424,16 +428,6 @@ class DataChannel {
424428
// Send a binary blob
425429
void SendBinaryBlob(dom::Blob& aBlob, ErrorResult& aRv);
426430

427-
DataChannelReliabilityPolicy GetType() const { return mPrPolicy; }
428-
429-
dom::Nullable<uint16_t> GetMaxPacketLifeTime() const;
430-
431-
dom::Nullable<uint16_t> GetMaxRetransmits() const;
432-
433-
bool GetNegotiated() const { return mNegotiated; }
434-
435-
bool GetOrdered() const { return mOrdered; }
436-
437431
void IncrementBufferedAmount(uint32_t aSize, ErrorResult& aRv);
438432
void DecrementBufferedAmount(uint32_t aSize);
439433

0 commit comments

Comments
 (0)