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

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

Issue 2156063002: Preparation for new Promise-based RTCPeerConnection.getStats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed hta's comments Created 4 years, 5 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 22 matching lines...) Expand all
33 #include "bindings/core/v8/ArrayValue.h" 33 #include "bindings/core/v8/ArrayValue.h"
34 #include "bindings/core/v8/ExceptionMessages.h" 34 #include "bindings/core/v8/ExceptionMessages.h"
35 #include "bindings/core/v8/ExceptionState.h" 35 #include "bindings/core/v8/ExceptionState.h"
36 #include "bindings/core/v8/Microtask.h" 36 #include "bindings/core/v8/Microtask.h"
37 #include "bindings/core/v8/Nullable.h" 37 #include "bindings/core/v8/Nullable.h"
38 #include "bindings/core/v8/ScriptPromiseResolver.h" 38 #include "bindings/core/v8/ScriptPromiseResolver.h"
39 #include "bindings/core/v8/ScriptState.h" 39 #include "bindings/core/v8/ScriptState.h"
40 #include "bindings/core/v8/ScriptValue.h" 40 #include "bindings/core/v8/ScriptValue.h"
41 #include "bindings/core/v8/V8ThrowException.h" 41 #include "bindings/core/v8/V8ThrowException.h"
42 #include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h" 42 #include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h"
43 #include "bindings/modules/v8/V8MediaStreamTrack.h"
43 #include "bindings/modules/v8/V8RTCCertificate.h" 44 #include "bindings/modules/v8/V8RTCCertificate.h"
45 #include "bindings/modules/v8/V8RTCStatsCallback.h"
44 #include "core/dom/DOMException.h" 46 #include "core/dom/DOMException.h"
45 #include "core/dom/DOMTimeStamp.h" 47 #include "core/dom/DOMTimeStamp.h"
46 #include "core/dom/Document.h" 48 #include "core/dom/Document.h"
47 #include "core/dom/ExceptionCode.h" 49 #include "core/dom/ExceptionCode.h"
48 #include "core/dom/ExecutionContext.h" 50 #include "core/dom/ExecutionContext.h"
49 #include "core/frame/HostsUsingFeatures.h" 51 #include "core/frame/HostsUsingFeatures.h"
50 #include "core/frame/LocalFrame.h" 52 #include "core/frame/LocalFrame.h"
51 #include "core/frame/UseCounter.h" 53 #include "core/frame/UseCounter.h"
52 #include "core/html/VoidCallback.h" 54 #include "core/html/VoidCallback.h"
53 #include "core/loader/FrameLoader.h" 55 #include "core/loader/FrameLoader.h"
(...skipping 10 matching lines...) Expand all
64 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h" 66 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h"
65 #include "modules/peerconnection/RTCSessionDescription.h" 67 #include "modules/peerconnection/RTCSessionDescription.h"
66 #include "modules/peerconnection/RTCSessionDescriptionCallback.h" 68 #include "modules/peerconnection/RTCSessionDescriptionCallback.h"
67 #include "modules/peerconnection/RTCSessionDescriptionInit.h" 69 #include "modules/peerconnection/RTCSessionDescriptionInit.h"
68 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h" 70 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h"
69 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h" 71 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h"
70 #include "modules/peerconnection/RTCStatsCallback.h" 72 #include "modules/peerconnection/RTCStatsCallback.h"
71 #include "modules/peerconnection/RTCStatsRequestImpl.h" 73 #include "modules/peerconnection/RTCStatsRequestImpl.h"
72 #include "modules/peerconnection/RTCVoidRequestImpl.h" 74 #include "modules/peerconnection/RTCVoidRequestImpl.h"
73 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" 75 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h"
76 #include "platform/RuntimeEnabledFeatures.h"
74 #include "platform/peerconnection/RTCAnswerOptionsPlatform.h" 77 #include "platform/peerconnection/RTCAnswerOptionsPlatform.h"
75 #include "platform/peerconnection/RTCConfiguration.h" 78 #include "platform/peerconnection/RTCConfiguration.h"
76 #include "platform/peerconnection/RTCOfferOptionsPlatform.h" 79 #include "platform/peerconnection/RTCOfferOptionsPlatform.h"
77 #include "public/platform/Platform.h" 80 #include "public/platform/Platform.h"
78 #include "public/platform/WebCryptoAlgorithmParams.h" 81 #include "public/platform/WebCryptoAlgorithmParams.h"
79 #include "public/platform/WebMediaStream.h" 82 #include "public/platform/WebMediaStream.h"
80 #include "public/platform/WebRTCAnswerOptions.h" 83 #include "public/platform/WebRTCAnswerOptions.h"
81 #include "public/platform/WebRTCCertificate.h" 84 #include "public/platform/WebRTCCertificate.h"
82 #include "public/platform/WebRTCCertificateGenerator.h" 85 #include "public/platform/WebRTCCertificateGenerator.h"
83 #include "public/platform/WebRTCConfiguration.h" 86 #include "public/platform/WebRTCConfiguration.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 offerToReceiveVideo = 0; 367 offerToReceiveVideo = 0;
365 if (DictionaryHelper::get(options, "offerToReceiveAudio", offerToReceiveAudi o) && offerToReceiveAudio < 0) 368 if (DictionaryHelper::get(options, "offerToReceiveAudio", offerToReceiveAudi o) && offerToReceiveAudio < 0)
366 offerToReceiveAudio = 0; 369 offerToReceiveAudio = 0;
367 DictionaryHelper::get(options, "voiceActivityDetection", voiceActivityDetect ion); 370 DictionaryHelper::get(options, "voiceActivityDetection", voiceActivityDetect ion);
368 DictionaryHelper::get(options, "iceRestart", iceRestart); 371 DictionaryHelper::get(options, "iceRestart", iceRestart);
369 372
370 RTCOfferOptionsPlatform* rtcOfferOptions = RTCOfferOptionsPlatform::create(o fferToReceiveVideo, offerToReceiveAudio, voiceActivityDetection, iceRestart); 373 RTCOfferOptionsPlatform* rtcOfferOptions = RTCOfferOptionsPlatform::create(o fferToReceiveVideo, offerToReceiveAudio, voiceActivityDetection, iceRestart);
371 return rtcOfferOptions; 374 return rtcOfferOptions;
372 } 375 }
373 376
377 RTCStatsCallback* ValueToRTCStatsCallback(ScriptState* scriptState, const v8::Lo cal<v8::Value>& value)
378 {
379 if (!value->IsObject())
380 return nullptr;
381 v8::Local<v8::Object> object = value->ToObject();
382 if (!object->IsCallable())
383 return nullptr;
384 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(object);
385 return V8RTCStatsCallback::create(function, scriptState);
386 }
387
374 } // namespace 388 } // namespace
375 389
376 RTCPeerConnection::EventWrapper::EventWrapper( 390 RTCPeerConnection::EventWrapper::EventWrapper(
377 Event* event, 391 Event* event,
378 std::unique_ptr<BoolFunction> function) 392 std::unique_ptr<BoolFunction> function)
379 : m_event(event) 393 : m_event(event)
380 , m_setupFunction(std::move(function)) 394 , m_setupFunction(std::move(function))
381 { 395 {
382 } 396 }
383 397
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } 955 }
942 956
943 for (MediaStreamVector::iterator iter = m_remoteStreams.begin(); iter != m_r emoteStreams.end(); ++iter) { 957 for (MediaStreamVector::iterator iter = m_remoteStreams.begin(); iter != m_r emoteStreams.end(); ++iter) {
944 if ((*iter)->id() == streamId) 958 if ((*iter)->id() == streamId)
945 return iter->get(); 959 return iter->get();
946 } 960 }
947 961
948 return 0; 962 return 0;
949 } 963 }
950 964
951 void RTCPeerConnection::getStats(ExecutionContext* context, RTCStatsCallback* su ccessCallback, MediaStreamTrack* selector) 965 ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, ScriptValue value)
952 { 966 {
967 v8::Local<v8::Value> v8Value = value.v8Value();
968 if (v8Value->IsUndefined() || v8Value->IsNull()) {
969 // Dispatch to "getStats(optional MediaStreamTrack?)".
970 return getStats(scriptState, static_cast<MediaStreamTrack*>(nullptr));
tommi (sloooow) - chröme 2016/07/25 08:31:17 you shouldn't need to cast a nullptr
hbos_chromium 2016/07/25 09:56:22 (Removed all of this code now that getStats overlo
971 }
972 if (v8Value->IsObject()) {
973 // Is |v8Value| a |MediaStreamTrack|?
974 MediaStreamTrack* selector = V8MediaStreamTrack::toImplWithTypeCheck(scr iptState->isolate(), v8Value);
975 if (selector) {
976 // Dispatch to "getStats(optional MediaStreamTrack?)".
977 return getStats(scriptState, selector);
978 }
979
980 // [RTCStatsCallback| is either a function or an object that contains a |handleEvent| function.
981 // Is |v8Value| a valid callback function?
982 RTCStatsCallback* callback = ValueToRTCStatsCallback(scriptState, v8Valu e);
983 if (!callback) {
984 // Is "value.handleEvent" a valid callback function?
985 v8::Local<v8::Object> object = v8Value->ToObject(scriptState->contex t()).ToLocalChecked();
986 v8::MaybeLocal<v8::Value> handleEvent = object->Get(
987 scriptState->context(),
988 v8::String::NewFromUtf8(scriptState->isolate(), "handleEvent"));
989 if (!handleEvent.IsEmpty())
990 callback = ValueToRTCStatsCallback(scriptState, handleEvent.ToLo calChecked());
991 }
992 if (callback) {
993 // Dispatch to "getStats(RTCStatsCallback, MediaStreamTrack?)".
994 return getStats(scriptState, callback, nullptr);
995 }
996 }
997
998 // Invalid parameter, |value| is not compatible with |MediaStreamTrack| or | RTCStatsCallback|.
999 if (!RuntimeEnabledFeatures::rTCPeerConnectionNewGetStatsEnabled())
1000 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(TypeMismatchError, "The 1st argument provided is not a valid RTCStatsCall back object."));
1001 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(TypeMismatchError, "The 1st argument provided is not a valid MediaStreamTrack or RTCStatsCallback object."));
1002 }
1003
1004 ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, RTCStatsCall back* successCallback, MediaStreamTrack* selector)
1005 {
1006 ExecutionContext* context = scriptState->getExecutionContext();
1007 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
1008 ScriptPromise promise = resolver->promise();
1009
953 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStatsLegacyNonCom pliant); 1010 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStatsLegacyNonCom pliant);
954 RTCStatsRequest* statsRequest = RTCStatsRequestImpl::create(getExecutionCont ext(), this, successCallback, selector); 1011 RTCStatsRequest* statsRequest = RTCStatsRequestImpl::create(getExecutionCont ext(), this, successCallback, selector);
955 // FIXME: Add passing selector as part of the statsRequest. 1012 // FIXME: Add passing selector as part of the statsRequest.
956 m_peerHandler->getStats(statsRequest); 1013 m_peerHandler->getStats(statsRequest);
1014
1015 resolver->resolve();
1016 return promise;
1017 }
1018
1019 ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, MediaStreamT rack* selector)
1020 {
1021 if (!RuntimeEnabledFeatures::rTCPeerConnectionNewGetStatsEnabled())
1022 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "RTC StatsCallback")));
1023
1024 ExecutionContext* context = scriptState->getExecutionContext();
1025 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats);
1026 // TODO(hbos): Implement new |getStats| function. crbug.com/627816
1027 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "getStats(optional MediaStreamTrack?) has not been impleme nted yet."));
957 } 1028 }
958 1029
959 RTCDataChannel* RTCPeerConnection::createDataChannel(String label, const Diction ary& options, ExceptionState& exceptionState) 1030 RTCDataChannel* RTCPeerConnection::createDataChannel(String label, const Diction ary& options, ExceptionState& exceptionState)
960 { 1031 {
961 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 1032 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
962 return nullptr; 1033 return nullptr;
963 1034
964 WebRTCDataChannelInit init; 1035 WebRTCDataChannelInit init;
965 DictionaryHelper::get(options, "ordered", init.ordered); 1036 DictionaryHelper::get(options, "ordered", init.ordered);
966 DictionaryHelper::get(options, "negotiated", init.negotiated); 1037 DictionaryHelper::get(options, "negotiated", init.negotiated);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 { 1329 {
1259 visitor->trace(m_localStreams); 1330 visitor->trace(m_localStreams);
1260 visitor->trace(m_remoteStreams); 1331 visitor->trace(m_remoteStreams);
1261 visitor->trace(m_dispatchScheduledEventRunner); 1332 visitor->trace(m_dispatchScheduledEventRunner);
1262 visitor->trace(m_scheduledEvents); 1333 visitor->trace(m_scheduledEvents);
1263 EventTargetWithInlineData::trace(visitor); 1334 EventTargetWithInlineData::trace(visitor);
1264 ActiveDOMObject::trace(visitor); 1335 ActiveDOMObject::trace(visitor);
1265 } 1336 }
1266 1337
1267 } // namespace blink 1338 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698