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

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

Issue 1713953002: Report errors in RTCPeerConnection legacy functions via the the failure callback instead of excepti… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ignore ConstraintErrors produced by the constraints parser Created 4 years, 9 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
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 { 94 {
95 if (state == RTCPeerConnection::SignalingStateClosed) { 95 if (state == RTCPeerConnection::SignalingStateClosed) {
96 exceptionState.throwDOMException(InvalidStateError, kSignalingStateClose dMessage); 96 exceptionState.throwDOMException(InvalidStateError, kSignalingStateClose dMessage);
97 return true; 97 return true;
98 } 98 }
99 99
100 return false; 100 return false;
101 } 101 }
102 102
103 // Helper class for running error callbacks asynchronously 103 // Helper class for running error callbacks asynchronously
104 class ErrorCallbackTask : public WebTaskRunner::Task { 104 class ErrorCallbackTask : public WebTaskRunner::Task {
philipj_slow 2016/03/01 04:53:05 This class is gone, needs rebase.
Guido Urdaneta 2016/03/09 15:04:35 Done.
105 public: 105 public:
106 static PassOwnPtr<ErrorCallbackTask> create(RTCPeerConnectionErrorCallback* errorCallback, DOMException* exception) 106 static PassOwnPtr<ErrorCallbackTask> create(RTCPeerConnectionErrorCallback* errorCallback, DOMException* exception)
107 { 107 {
108 return adoptPtr(new ErrorCallbackTask(errorCallback, exception)); 108 return adoptPtr(new ErrorCallbackTask(errorCallback, exception));
109 } 109 }
110 110
111 ~ErrorCallbackTask() override = default; 111 ~ErrorCallbackTask() override = default;
112 112
113 void run() override 113 void run() override
114 { 114 {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return 0; 352 return 0;
353 } 353 }
354 354
355 rtcConfiguration->appendCertificate(certificate->certificateShallowC opy()); 355 rtcConfiguration->appendCertificate(certificate->certificateShallowC opy());
356 } 356 }
357 } 357 }
358 358
359 return rtcConfiguration; 359 return rtcConfiguration;
360 } 360 }
361 361
362 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options, ExceptionState& exceptionState) 362 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options)
363 { 363 {
364 if (options.isUndefinedOrNull()) 364 if (options.isUndefinedOrNull())
365 return 0; 365 return 0;
366 366
367 Vector<String> propertyNames; 367 Vector<String> propertyNames;
368 options.getPropertyNames(propertyNames); 368 options.getPropertyNames(propertyNames);
369 369
370 // Treat |options| as MediaConstraints if it is empty or has "optional" or " mandatory" properties for compatibility. 370 // Treat |options| as MediaConstraints if it is empty or has "optional" or " mandatory" properties for compatibility.
371 // TODO(jiayl): remove constraints when RTCOfferOptions reaches Stable and c lient code is ready. 371 // TODO(jiayl): remove constraints when RTCOfferOptions reaches Stable and c lient code is ready.
372 if (propertyNames.isEmpty() || propertyNames.contains("optional") || propert yNames.contains("mandatory")) 372 if (propertyNames.isEmpty() || propertyNames.contains("optional") || propert yNames.contains("mandatory"))
373 return 0; 373 return 0;
374 374
375 int32_t offerToReceiveVideo = -1; 375 int32_t offerToReceiveVideo = -1;
376 int32_t offerToReceiveAudio = -1; 376 int32_t offerToReceiveAudio = -1;
377 bool voiceActivityDetection = true; 377 bool voiceActivityDetection = true;
378 bool iceRestart = false; 378 bool iceRestart = false;
379 379
380 if (DictionaryHelper::get(options, "offerToReceiveVideo", offerToReceiveVide o) && offerToReceiveVideo < 0) { 380 if (DictionaryHelper::get(options, "offerToReceiveVideo", offerToReceiveVide o) && offerToReceiveVideo < 0)
381 exceptionState.throwTypeError("Invalid offerToReceiveVideo"); 381 offerToReceiveVideo = 0;
382 return 0; 382 if (DictionaryHelper::get(options, "offerToReceiveAudio", offerToReceiveAudi o) && offerToReceiveAudio < 0)
383 } 383 offerToReceiveAudio = 0;
384
385 if (DictionaryHelper::get(options, "offerToReceiveAudio", offerToReceiveAudi o) && offerToReceiveAudio < 0) {
386 exceptionState.throwTypeError("Invalid offerToReceiveAudio");
387 return 0;
388 }
389
390 DictionaryHelper::get(options, "voiceActivityDetection", voiceActivityDetect ion); 384 DictionaryHelper::get(options, "voiceActivityDetection", voiceActivityDetect ion);
391 DictionaryHelper::get(options, "iceRestart", iceRestart); 385 DictionaryHelper::get(options, "iceRestart", iceRestart);
392 386
393 RTCOfferOptions* rtcOfferOptions = RTCOfferOptions::create(offerToReceiveVid eo, offerToReceiveAudio, voiceActivityDetection, iceRestart); 387 RTCOfferOptions* rtcOfferOptions = RTCOfferOptions::create(offerToReceiveVid eo, offerToReceiveAudio, voiceActivityDetection, iceRestart);
394 return rtcOfferOptions; 388 return rtcOfferOptions;
395 } 389 }
396 390
397 RTCPeerConnection* RTCPeerConnection::create(ExecutionContext* context, const Di ctionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState& exceptionState) 391 RTCPeerConnection* RTCPeerConnection::create(ExecutionContext* context, const Di ctionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState& exceptionState)
398 { 392 {
399 if (mediaConstraints.isObject()) 393 if (mediaConstraints.isObject())
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 452 }
459 } 453 }
460 454
461 RTCPeerConnection::~RTCPeerConnection() 455 RTCPeerConnection::~RTCPeerConnection()
462 { 456 {
463 // This checks that close() or stop() is called before the destructor. 457 // This checks that close() or stop() is called before the destructor.
464 // We are assuming that a wrapper is always created when RTCPeerConnection i s created. 458 // We are assuming that a wrapper is always created when RTCPeerConnection i s created.
465 ASSERT(m_closed || m_stopped); 459 ASSERT(m_closed || m_stopped);
466 } 460 }
467 461
468 void RTCPeerConnection::createOffer(ExecutionContext* context, RTCSessionDescrip tionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, co nst Dictionary& rtcOfferOptions, ExceptionState& exceptionState) 462 void RTCPeerConnection::createOffer(ExecutionContext* context, RTCSessionDescrip tionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, co nst Dictionary& rtcOfferOptions)
469 { 463 {
470 if (errorCallback) 464 ASSERT(successCallback);
471 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferLegac yFailureCallback); 465 ASSERT(errorCallback);
472 else 466 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferLegacyFai lureCallback);
473 Deprecation::countDeprecation(context, UseCounter::RTCPeerConnectionCrea teOfferLegacyNoFailureCallback); 467 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) )
474
475 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
476 return; 468 return;
477 469
478 ASSERT(successCallback); 470 RTCOfferOptions* offerOptions = parseOfferOptions(rtcOfferOptions);
479
480 RTCOfferOptions* offerOptions = parseOfferOptions(rtcOfferOptions, exception State);
481 if (exceptionState.hadException())
482 return;
483
484 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr eate(executionContext(), this, successCallback, errorCallback); 471 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr eate(executionContext(), this, successCallback, errorCallback);
485 472
486 if (offerOptions) { 473 if (offerOptions) {
487 if (offerOptions->offerToReceiveAudio() != -1 || offerOptions->offerToRe ceiveVideo() != -1) 474 if (offerOptions->offerToReceiveAudio() != -1 || offerOptions->offerToRe ceiveVideo() != -1)
488 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyOfferOptions); 475 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyOfferOptions);
489 else if (errorCallback) 476 else
490 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyCompliant); 477 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyCompliant);
491 478
492 m_peerHandler->createOffer(request, offerOptions); 479 m_peerHandler->createOffer(request, offerOptions);
493 } else { 480 } else {
494 MediaErrorState mediaErrorState; 481 MediaErrorState mediaErrorState;
495 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, rtcOfferOptions, mediaErrorState); 482 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, rtcOfferOptions, mediaErrorState);
496 if (mediaErrorState.hadException()) { 483 if (mediaErrorState.canGenerateException()) {
philipj_slow 2016/03/01 04:53:05 It's a bit subtle why this works. Isn't it a bug i
hta - Chromium 2016/03/07 15:15:47 The reason for canGenerateException is that the DO
philipj_slow 2016/03/09 13:15:31 OK, so this is related to NavigatorUserMediaError
Guido Urdaneta 2016/03/09 15:04:35 Done.
497 mediaErrorState.raiseException(exceptionState); 484 String errorMsg = mediaErrorState.getErrorMessage();
485 asyncCallErrorCallback(errorCallback, DOMException::create(Operation Error, errorMsg));
498 return; 486 return;
499 } 487 }
500 488
501 if (!constraints.isEmpty()) 489 if (!constraints.isEmpty())
502 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyConstraints); 490 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyConstraints);
503 else if (errorCallback) 491 else
504 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyCompliant); 492 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL egacyCompliant);
505 493
506 m_peerHandler->createOffer(request, constraints); 494 m_peerHandler->createOffer(request, constraints);
507 } 495 }
508 } 496 }
509 497
510 void RTCPeerConnection::createAnswer(ExecutionContext* context, RTCSessionDescri ptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, c onst Dictionary& mediaConstraints, ExceptionState& exceptionState) 498 void RTCPeerConnection::createAnswer(ExecutionContext* context, RTCSessionDescri ptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, c onst Dictionary& mediaConstraints)
511 { 499 {
512 if (errorCallback) 500 ASSERT(successCallback);
513 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega cyFailureCallback); 501 ASSERT(errorCallback);
514 else 502 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLegacyFa ilureCallback);
515 Deprecation::countDeprecation(context, UseCounter::RTCPeerConnectionCrea teAnswerLegacyNoFailureCallback);
516
517 if (mediaConstraints.isObject()) 503 if (mediaConstraints.isObject())
518 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega cyConstraints); 504 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega cyConstraints);
519 else if (errorCallback) 505 else
520 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega cyCompliant); 506 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega cyCompliant);
521 507
522 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 508 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback) )
523 return; 509 return;
524 510
525 ASSERT(successCallback);
526
527 MediaErrorState mediaErrorState; 511 MediaErrorState mediaErrorState;
528 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, medi aConstraints, mediaErrorState); 512 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, medi aConstraints, mediaErrorState);
529 if (mediaErrorState.hadException()) { 513 if (mediaErrorState.canGenerateException()) {
530 mediaErrorState.raiseException(exceptionState); 514 String errorMsg = mediaErrorState.getErrorMessage();
515 asyncCallErrorCallback(errorCallback, DOMException::create(OperationErro r, errorMsg));
531 return; 516 return;
532 } 517 }
533 518
534 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr eate(executionContext(), this, successCallback, errorCallback); 519 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr eate(executionContext(), this, successCallback, errorCallback);
535 m_peerHandler->createAnswer(request, constraints); 520 m_peerHandler->createAnswer(request, constraints);
536 } 521 }
537 522
538 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, c onst RTCSessionDescriptionInit& sessionDescriptionInit) 523 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, c onst RTCSessionDescriptionInit& sessionDescriptionInit)
539 { 524 {
540 if (m_signalingState == SignalingStateClosed) 525 if (m_signalingState == SignalingStateClosed)
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 { 1144 {
1160 visitor->trace(m_localStreams); 1145 visitor->trace(m_localStreams);
1161 visitor->trace(m_remoteStreams); 1146 visitor->trace(m_remoteStreams);
1162 visitor->trace(m_dispatchScheduledEventRunner); 1147 visitor->trace(m_dispatchScheduledEventRunner);
1163 visitor->trace(m_scheduledEvents); 1148 visitor->trace(m_scheduledEvents);
1164 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); 1149 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor);
1165 ActiveDOMObject::trace(visitor); 1150 ActiveDOMObject::trace(visitor);
1166 } 1151 }
1167 1152
1168 } // namespace blink 1153 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698