Index: third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp |
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp b/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp |
index f2e997a1fe24c9608d265375d8e6e6a9f97c7ca9..30a9eb884ddbd7e779f3f76ae0b549558a19f598 100644 |
--- a/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp |
+++ b/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp |
@@ -40,7 +40,9 @@ |
#include "bindings/core/v8/ScriptValue.h" |
#include "bindings/core/v8/V8ThrowException.h" |
#include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h" |
+#include "bindings/modules/v8/V8MediaStreamTrack.h" |
#include "bindings/modules/v8/V8RTCCertificate.h" |
+#include "bindings/modules/v8/V8RTCStatsCallback.h" |
#include "core/dom/DOMException.h" |
#include "core/dom/DOMTimeStamp.h" |
#include "core/dom/Document.h" |
@@ -71,6 +73,7 @@ |
#include "modules/peerconnection/RTCStatsRequestImpl.h" |
#include "modules/peerconnection/RTCVoidRequestImpl.h" |
#include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" |
+#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/peerconnection/RTCAnswerOptionsPlatform.h" |
#include "platform/peerconnection/RTCConfiguration.h" |
#include "platform/peerconnection/RTCOfferOptionsPlatform.h" |
@@ -371,6 +374,17 @@ RTCOfferOptionsPlatform* parseOfferOptions(const Dictionary& options) |
return rtcOfferOptions; |
} |
+RTCStatsCallback* ValueToRTCStatsCallback(ScriptState* scriptState, const v8::Local<v8::Value>& value) |
+{ |
+ if (!value->IsObject()) |
+ return nullptr; |
+ v8::Local<v8::Object> object = value->ToObject(); |
+ if (!object->IsCallable()) |
+ return nullptr; |
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(object); |
+ return V8RTCStatsCallback::create(function, scriptState); |
+} |
+ |
} // namespace |
RTCPeerConnection::EventWrapper::EventWrapper( |
@@ -948,12 +962,69 @@ MediaStream* RTCPeerConnection::getStreamById(const String& streamId) |
return 0; |
} |
-void RTCPeerConnection::getStats(ExecutionContext* context, RTCStatsCallback* successCallback, MediaStreamTrack* selector) |
+ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, ScriptValue value) |
+{ |
+ v8::Local<v8::Value> v8Value = value.v8Value(); |
+ if (v8Value->IsUndefined() || v8Value->IsNull()) { |
+ // Dispatch to "getStats(optional MediaStreamTrack?)". |
+ 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
|
+ } |
+ if (v8Value->IsObject()) { |
+ // Is |v8Value| a |MediaStreamTrack|? |
+ MediaStreamTrack* selector = V8MediaStreamTrack::toImplWithTypeCheck(scriptState->isolate(), v8Value); |
+ if (selector) { |
+ // Dispatch to "getStats(optional MediaStreamTrack?)". |
+ return getStats(scriptState, selector); |
+ } |
+ |
+ // [RTCStatsCallback| is either a function or an object that contains a |handleEvent| function. |
+ // Is |v8Value| a valid callback function? |
+ RTCStatsCallback* callback = ValueToRTCStatsCallback(scriptState, v8Value); |
+ if (!callback) { |
+ // Is "value.handleEvent" a valid callback function? |
+ v8::Local<v8::Object> object = v8Value->ToObject(scriptState->context()).ToLocalChecked(); |
+ v8::MaybeLocal<v8::Value> handleEvent = object->Get( |
+ scriptState->context(), |
+ v8::String::NewFromUtf8(scriptState->isolate(), "handleEvent")); |
+ if (!handleEvent.IsEmpty()) |
+ callback = ValueToRTCStatsCallback(scriptState, handleEvent.ToLocalChecked()); |
+ } |
+ if (callback) { |
+ // Dispatch to "getStats(RTCStatsCallback, MediaStreamTrack?)". |
+ return getStats(scriptState, callback, nullptr); |
+ } |
+ } |
+ |
+ // Invalid parameter, |value| is not compatible with |MediaStreamTrack| or |RTCStatsCallback|. |
+ if (!RuntimeEnabledFeatures::rTCPeerConnectionNewGetStatsEnabled()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(TypeMismatchError, "The 1st argument provided is not a valid RTCStatsCallback object.")); |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(TypeMismatchError, "The 1st argument provided is not a valid MediaStreamTrack or RTCStatsCallback object.")); |
+} |
+ |
+ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, RTCStatsCallback* successCallback, MediaStreamTrack* selector) |
{ |
+ ExecutionContext* context = scriptState->getExecutionContext(); |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
UseCounter::count(context, UseCounter::RTCPeerConnectionGetStatsLegacyNonCompliant); |
RTCStatsRequest* statsRequest = RTCStatsRequestImpl::create(getExecutionContext(), this, successCallback, selector); |
// FIXME: Add passing selector as part of the statsRequest. |
m_peerHandler->getStats(statsRequest); |
+ |
+ resolver->resolve(); |
+ return promise; |
+} |
+ |
+ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, MediaStreamTrack* selector) |
+{ |
+ if (!RuntimeEnabledFeatures::rTCPeerConnectionNewGetStatsEnabled()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "RTCStatsCallback"))); |
+ |
+ ExecutionContext* context = scriptState->getExecutionContext(); |
+ UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats); |
+ // TODO(hbos): Implement new |getStats| function. crbug.com/627816 |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "getStats(optional MediaStreamTrack?) has not been implemented yet.")); |
} |
RTCDataChannel* RTCPeerConnection::createDataChannel(String label, const Dictionary& options, ExceptionState& exceptionState) |