Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: Source/modules/mediastream/RTCPeerConnection.cpp

Issue 170603003: Use nullptr_t for RefPtr, PassRefPtr and RawPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 return false; 82 return false;
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 PassRefPtr<RTCConfiguration> RTCPeerConnection::parseConfiguration(const Diction ary& configuration, ExceptionState& exceptionState) 87 PassRefPtr<RTCConfiguration> RTCPeerConnection::parseConfiguration(const Diction ary& configuration, ExceptionState& exceptionState)
88 { 88 {
89 if (configuration.isUndefinedOrNull()) 89 if (configuration.isUndefinedOrNull())
90 return 0; 90 return nullptr;
91 91
92 ArrayValue iceServers; 92 ArrayValue iceServers;
93 bool ok = configuration.get("iceServers", iceServers); 93 bool ok = configuration.get("iceServers", iceServers);
94 if (!ok || iceServers.isUndefinedOrNull()) { 94 if (!ok || iceServers.isUndefinedOrNull()) {
95 exceptionState.throwTypeError("Malformed RTCConfiguration"); 95 exceptionState.throwTypeError("Malformed RTCConfiguration");
96 return 0; 96 return nullptr;
97 } 97 }
98 98
99 size_t numberOfServers; 99 size_t numberOfServers;
100 ok = iceServers.length(numberOfServers); 100 ok = iceServers.length(numberOfServers);
101 if (!ok) { 101 if (!ok) {
102 exceptionState.throwTypeError("Malformed RTCConfiguration"); 102 exceptionState.throwTypeError("Malformed RTCConfiguration");
103 return 0; 103 return nullptr;
104 } 104 }
105 105
106 RefPtr<RTCConfiguration> rtcConfiguration = RTCConfiguration::create(); 106 RefPtr<RTCConfiguration> rtcConfiguration = RTCConfiguration::create();
107 107
108 for (size_t i = 0; i < numberOfServers; ++i) { 108 for (size_t i = 0; i < numberOfServers; ++i) {
109 Dictionary iceServer; 109 Dictionary iceServer;
110 ok = iceServers.get(i, iceServer); 110 ok = iceServers.get(i, iceServer);
111 if (!ok) { 111 if (!ok) {
112 exceptionState.throwTypeError("Malformed RTCIceServer"); 112 exceptionState.throwTypeError("Malformed RTCIceServer");
113 return 0; 113 return nullptr;
114 } 114 }
115 115
116 Vector<String> names; 116 Vector<String> names;
117 iceServer.getOwnPropertyNames(names); 117 iceServer.getOwnPropertyNames(names);
118 118
119 Vector<String> urlStrings; 119 Vector<String> urlStrings;
120 if (names.contains("urls")) { 120 if (names.contains("urls")) {
121 if (!iceServer.get("urls", urlStrings) || !urlStrings.size()) { 121 if (!iceServer.get("urls", urlStrings) || !urlStrings.size()) {
122 String urlString; 122 String urlString;
123 if (iceServer.get("urls", urlString)) { 123 if (iceServer.get("urls", urlString)) {
124 urlStrings.append(urlString); 124 urlStrings.append(urlString);
125 } else { 125 } else {
126 exceptionState.throwTypeError("Malformed RTCIceServer"); 126 exceptionState.throwTypeError("Malformed RTCIceServer");
127 return 0; 127 return nullptr;
128 } 128 }
129 } 129 }
130 } else if (names.contains("url")) { 130 } else if (names.contains("url")) {
131 String urlString; 131 String urlString;
132 if (iceServer.get("url", urlString)) { 132 if (iceServer.get("url", urlString)) {
133 urlStrings.append(urlString); 133 urlStrings.append(urlString);
134 } else { 134 } else {
135 exceptionState.throwTypeError("Malformed RTCIceServer"); 135 exceptionState.throwTypeError("Malformed RTCIceServer");
136 return 0; 136 return nullptr;
137 } 137 }
138 } else { 138 } else {
139 exceptionState.throwTypeError("Malformed RTCIceServer"); 139 exceptionState.throwTypeError("Malformed RTCIceServer");
140 return 0; 140 return nullptr;
141 } 141 }
142 142
143 String username, credential; 143 String username, credential;
144 iceServer.get("username", username); 144 iceServer.get("username", username);
145 iceServer.get("credential", credential); 145 iceServer.get("credential", credential);
146 146
147 for (Vector<String>::iterator iter = urlStrings.begin(); iter != urlStri ngs.end(); ++iter) { 147 for (Vector<String>::iterator iter = urlStrings.begin(); iter != urlStri ngs.end(); ++iter) {
148 KURL url(KURL(), *iter); 148 KURL url(KURL(), *iter);
149 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) { 149 if (!url.isValid() || !(url.protocolIs("turn") || url.protocolIs("tu rns") || url.protocolIs("stun"))) {
150 exceptionState.throwTypeError("Malformed URL"); 150 exceptionState.throwTypeError("Malformed URL");
151 return 0; 151 return nullptr;
152 } 152 }
153 153
154 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c redential)); 154 rtcConfiguration->appendServer(RTCIceServer::create(url, username, c redential));
155 } 155 }
156 } 156 }
157 157
158 return rtcConfiguration.release(); 158 return rtcConfiguration.release();
159 } 159 }
160 160
161 PassRefPtr<RTCPeerConnection> RTCPeerConnection::create(ExecutionContext* contex t, const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints, Excep tionState& exceptionState) 161 PassRefPtr<RTCPeerConnection> RTCPeerConnection::create(ExecutionContext* contex t, const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints, Excep tionState& exceptionState)
162 { 162 {
163 RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration , exceptionState); 163 RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration , exceptionState);
164 if (exceptionState.hadException()) 164 if (exceptionState.hadException())
165 return 0; 165 return nullptr;
166 166
167 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState); 167 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState);
168 if (exceptionState.hadException()) 168 if (exceptionState.hadException())
169 return 0; 169 return nullptr;
170 170
171 RefPtr<RTCPeerConnection> peerConnection = adoptRef(new RTCPeerConnection(co ntext, configuration.release(), constraints, exceptionState)); 171 RefPtr<RTCPeerConnection> peerConnection = adoptRef(new RTCPeerConnection(co ntext, configuration.release(), constraints, exceptionState));
172 peerConnection->suspendIfNeeded(); 172 peerConnection->suspendIfNeeded();
173 if (exceptionState.hadException()) 173 if (exceptionState.hadException())
174 return 0; 174 return nullptr;
175 175
176 return peerConnection.release(); 176 return peerConnection.release();
177 } 177 }
178 178
179 RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo nfiguration> configuration, blink::WebMediaConstraints constraints, ExceptionSta te& exceptionState) 179 RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo nfiguration> configuration, blink::WebMediaConstraints constraints, ExceptionSta te& exceptionState)
180 : ActiveDOMObject(context) 180 : ActiveDOMObject(context)
181 , m_signalingState(SignalingStateStable) 181 , m_signalingState(SignalingStateStable)
182 , m_iceGatheringState(ICEGatheringStateNew) 182 , m_iceGatheringState(ICEGatheringStateNew)
183 , m_iceConnectionState(ICEConnectionStateNew) 183 , m_iceConnectionState(ICEConnectionStateNew)
184 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled Event) 184 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled Event)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 259 }
260 260
261 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 261 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback);
262 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we bSessionDescription()); 262 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we bSessionDescription());
263 } 263 }
264 264
265 PassRefPtr<RTCSessionDescription> RTCPeerConnection::localDescription(ExceptionS tate& exceptionState) 265 PassRefPtr<RTCSessionDescription> RTCPeerConnection::localDescription(ExceptionS tate& exceptionState)
266 { 266 {
267 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->local Description(); 267 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->local Description();
268 if (webSessionDescription.isNull()) 268 if (webSessionDescription.isNull())
269 return 0; 269 return nullptr;
270 270
271 RefPtr<RTCSessionDescription> sessionDescription = RTCSessionDescription::cr eate(webSessionDescription); 271 RefPtr<RTCSessionDescription> sessionDescription = RTCSessionDescription::cr eate(webSessionDescription);
272 return sessionDescription.release(); 272 return sessionDescription.release();
273 } 273 }
274 274
275 void RTCPeerConnection::setRemoteDescription(PassRefPtr<RTCSessionDescription> p rpSessionDescription, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<RTCEr rorCallback> errorCallback, ExceptionState& exceptionState) 275 void RTCPeerConnection::setRemoteDescription(PassRefPtr<RTCSessionDescription> p rpSessionDescription, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<RTCEr rorCallback> errorCallback, ExceptionState& exceptionState)
276 { 276 {
277 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 277 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
278 return; 278 return;
279 279
280 RefPtr<RTCSessionDescription> sessionDescription = prpSessionDescription; 280 RefPtr<RTCSessionDescription> sessionDescription = prpSessionDescription;
281 if (!sessionDescription) { 281 if (!sessionDescription) {
282 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); 282 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription"));
283 return; 283 return;
284 } 284 }
285 285
286 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 286 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback);
287 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w ebSessionDescription()); 287 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w ebSessionDescription());
288 } 288 }
289 289
290 PassRefPtr<RTCSessionDescription> RTCPeerConnection::remoteDescription(Exception State& exceptionState) 290 PassRefPtr<RTCSessionDescription> RTCPeerConnection::remoteDescription(Exception State& exceptionState)
291 { 291 {
292 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->remot eDescription(); 292 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->remot eDescription();
293 if (webSessionDescription.isNull()) 293 if (webSessionDescription.isNull())
294 return 0; 294 return nullptr;
295 295
296 RefPtr<RTCSessionDescription> desc = RTCSessionDescription::create(webSessio nDescription); 296 RefPtr<RTCSessionDescription> desc = RTCSessionDescription::create(webSessio nDescription);
297 return desc.release(); 297 return desc.release();
298 } 298 }
299 299
300 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict ionary& mediaConstraints, ExceptionState& exceptionState) 300 void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict ionary& mediaConstraints, ExceptionState& exceptionState)
301 { 301 {
302 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 302 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
303 return; 303 return;
304 304
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, P assRefPtr<MediaStreamTrack> selector) 488 void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, P assRefPtr<MediaStreamTrack> selector)
489 { 489 {
490 RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(execution Context(), successCallback, selector); 490 RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(execution Context(), successCallback, selector);
491 // FIXME: Add passing selector as part of the statsRequest. 491 // FIXME: Add passing selector as part of the statsRequest.
492 m_peerHandler->getStats(statsRequest.release()); 492 m_peerHandler->getStats(statsRequest.release());
493 } 493 }
494 494
495 PassRefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String label, co nst Dictionary& options, ExceptionState& exceptionState) 495 PassRefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String label, co nst Dictionary& options, ExceptionState& exceptionState)
496 { 496 {
497 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 497 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
498 return 0; 498 return nullptr;
499 499
500 blink::WebRTCDataChannelInit init; 500 blink::WebRTCDataChannelInit init;
501 options.get("ordered", init.ordered); 501 options.get("ordered", init.ordered);
502 options.get("negotiated", init.negotiated); 502 options.get("negotiated", init.negotiated);
503 503
504 unsigned short value = 0; 504 unsigned short value = 0;
505 if (options.get("id", value)) 505 if (options.get("id", value))
506 init.id = value; 506 init.id = value;
507 if (options.get("maxRetransmits", value)) 507 if (options.get("maxRetransmits", value))
508 init.maxRetransmits = value; 508 init.maxRetransmits = value;
509 if (options.get("maxRetransmitTime", value)) 509 if (options.get("maxRetransmitTime", value))
510 init.maxRetransmitTime = value; 510 init.maxRetransmitTime = value;
511 511
512 String protocolString; 512 String protocolString;
513 options.get("protocol", protocolString); 513 options.get("protocol", protocolString);
514 init.protocol = protocolString; 514 init.protocol = protocolString;
515 515
516 RefPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_peerHandler.get(), label, init, exceptionState); 516 RefPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_peerHandler.get(), label, init, exceptionState);
517 if (exceptionState.hadException()) 517 if (exceptionState.hadException())
518 return 0; 518 return nullptr;
519 m_dataChannels.append(channel); 519 m_dataChannels.append(channel);
520 return channel.release(); 520 return channel.release();
521 } 521 }
522 522
523 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) 523 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId)
524 { 524 {
525 for (MediaStreamVector::iterator iter = m_localStreams.begin(); iter != m_lo calStreams.end(); ++iter) { 525 for (MediaStreamVector::iterator iter = m_localStreams.begin(); iter != m_lo calStreams.end(); ++iter) {
526 if ((*iter)->getTrackById(trackId)) 526 if ((*iter)->getTrackById(trackId))
527 return true; 527 return true;
528 } 528 }
529 return false; 529 return false;
530 } 530 }
531 531
532 PassRefPtr<RTCDTMFSender> RTCPeerConnection::createDTMFSender(PassRefPtr<MediaSt reamTrack> prpTrack, ExceptionState& exceptionState) 532 PassRefPtr<RTCDTMFSender> RTCPeerConnection::createDTMFSender(PassRefPtr<MediaSt reamTrack> prpTrack, ExceptionState& exceptionState)
533 { 533 {
534 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 534 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
535 return 0; 535 return nullptr;
536 536
537 if (!prpTrack) { 537 if (!prpTrack) {
538 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(1, "MediaStreamTrack")); 538 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(1, "MediaStreamTrack"));
539 return 0; 539 return nullptr;
540 } 540 }
541 541
542 RefPtr<MediaStreamTrack> track = prpTrack; 542 RefPtr<MediaStreamTrack> track = prpTrack;
543 543
544 if (!hasLocalStreamWithTrackId(track->id())) { 544 if (!hasLocalStreamWithTrackId(track->id())) {
545 exceptionState.throwDOMException(SyntaxError, "No local stream is availa ble for the track provided."); 545 exceptionState.throwDOMException(SyntaxError, "No local stream is availa ble for the track provided.");
546 return 0; 546 return nullptr;
547 } 547 }
548 548
549 RefPtr<RTCDTMFSender> dtmfSender = RTCDTMFSender::create(executionContext(), m_peerHandler.get(), track.release(), exceptionState); 549 RefPtr<RTCDTMFSender> dtmfSender = RTCDTMFSender::create(executionContext(), m_peerHandler.get(), track.release(), exceptionState);
550 if (exceptionState.hadException()) 550 if (exceptionState.hadException())
551 return 0; 551 return nullptr;
552 return dtmfSender.release(); 552 return dtmfSender.release();
553 } 553 }
554 554
555 void RTCPeerConnection::close(ExceptionState& exceptionState) 555 void RTCPeerConnection::close(ExceptionState& exceptionState)
556 { 556 {
557 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 557 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
558 return; 558 return;
559 559
560 m_peerHandler->stop(); 560 m_peerHandler->stop();
561 561
562 changeIceConnectionState(ICEConnectionStateClosed); 562 changeIceConnectionState(ICEConnectionStateClosed);
563 changeIceGatheringState(ICEGatheringStateComplete); 563 changeIceGatheringState(ICEGatheringStateComplete);
564 changeSignalingState(SignalingStateClosed); 564 changeSignalingState(SignalingStateClosed);
565 } 565 }
566 566
567 void RTCPeerConnection::negotiationNeeded() 567 void RTCPeerConnection::negotiationNeeded()
568 { 568 {
569 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); 569 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded));
570 } 570 }
571 571
572 void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate) 572 void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate)
573 { 573 {
574 ASSERT(executionContext()->isContextThread()); 574 ASSERT(executionContext()->isContextThread());
575 if (webCandidate.isNull()) 575 if (webCandidate.isNull())
576 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, 0)); 576 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr ));
577 else { 577 else {
578 RefPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::create(webCandid ate); 578 RefPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::create(webCandid ate);
579 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand idate.release())); 579 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand idate.release()));
580 } 580 }
581 } 581 }
582 582
583 void RTCPeerConnection::didChangeSignalingState(SignalingState newState) 583 void RTCPeerConnection::didChangeSignalingState(SignalingState newState)
584 { 584 {
585 ASSERT(executionContext()->isContextThread()); 585 ASSERT(executionContext()->isContextThread());
586 changeSignalingState(newState); 586 changeSignalingState(newState);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 events.swap(m_scheduledEvents); 717 events.swap(m_scheduledEvents);
718 718
719 Vector<RefPtr<Event> >::iterator it = events.begin(); 719 Vector<RefPtr<Event> >::iterator it = events.begin();
720 for (; it != events.end(); ++it) 720 for (; it != events.end(); ++it)
721 dispatchEvent((*it).release()); 721 dispatchEvent((*it).release());
722 722
723 events.clear(); 723 events.clear();
724 } 724 }
725 725
726 } // namespace WebCore 726 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/mediastream/RTCIceCandidate.cpp ('k') | Source/modules/mediastream/RTCSessionDescription.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698