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..bb815640d560d9ce38e2ed3e7d21e615574910d4 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,20 @@ 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); |
+ // |function| should have one argument. If called and it doesn't have one it |
+ // is still invoked but without the |RTCLegacyStatsReport|. If it has more |
+ // than one argument it is invoked with the subsequent arguments undefined. |
hta - Chromium
2016/07/19 09:56:48
Is this just a description of how v8::Function wor
hbos_chromium
2016/07/19 13:59:35
Done.
|
+ return V8RTCStatsCallback::create(function, scriptState); |
+} |
+ |
} // namespace |
RTCPeerConnection::EventWrapper::EventWrapper( |
@@ -948,12 +965,73 @@ 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)); |
+ } |
+ 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|. |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ resolver->reject(); |
hta - Chromium
2016/07/19 09:56:48
Where do we set the error to be returned in this c
hbos_chromium
2016/07/19 13:59:35
This error was undefined. I added an error and upd
|
+ return promise; |
+} |
+ |
+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) |
+{ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ if (!RuntimeEnabledFeatures::rTCPeerConnectionNewGetStatsEnabled()) { |
+ resolver->reject(ExceptionMessages::argumentNullOrIncorrectType(1, "successCallback")); |
+ return promise; |
+ } |
+ |
+ // TODO(hbos): Implement new |getStats| function. |
+ resolver->reject(DOMException::create(NotSupportedError, "getStats(optional MediaStreamTrack?) has not been implemented yet.")); |
+ return promise; |
} |
RTCDataChannel* RTCPeerConnection::createDataChannel(String label, const Dictionary& options, ExceptionState& exceptionState) |