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

Unified Diff: third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp

Issue 1318393002: Refactor "track options" to be a dictionary. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Used MediaTrackConstraintSet in union types Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp
diff --git a/third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp b/third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp
index 66d3a5dbfc49e32ed0e39ee4766b01adefe4abfb..4ab367fc4d28857d1b3d352b4624f7f34bacf618 100644
--- a/third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp
+++ b/third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp
@@ -31,6 +31,7 @@
#include "config.h"
#include "modules/mediastream/MediaConstraintsImpl.h"
+#include "modules/mediastream/MediaTrackConstraintSet.h"
#include "bindings/core/v8/ArrayValue.h"
#include "bindings/core/v8/Dictionary.h"
@@ -112,6 +113,48 @@ static bool parse(const Dictionary& constraintsDictionary, WebVector<WebMediaCon
return true;
}
+static bool parse(const MediaTrackConstraintSet& constraintsIn, WebVector<WebMediaConstraint>& optional, WebVector<WebMediaConstraint>& mandatory)
+{
+ Vector<WebMediaConstraint> mandatoryConstraintsVector;
+ if (constraintsIn.hasMandatory()) {
+ Dictionary mandatoryConstraintsDictionary = constraintsIn.mandatory();
Peter Beverloo 2015/10/05 13:49:09 Parsing of |mandatoryConstraintsDictionary| and |o
hta - Chromium 2015/10/05 21:28:06 There are subtle differences in the control flow,
+
+ HashMap<String, String> mandatoryConstraintsHashMap;
+ bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(mandatoryConstraintsHashMap);
+ if (!ok)
+ return false;
+
+ HashMap<String, String>::const_iterator iter = mandatoryConstraintsHashMap.begin();
+ for (; iter != mandatoryConstraintsHashMap.end(); ++iter)
Guido Urdaneta 2015/10/05 12:34:12 Can you use range for here?
hta - Chromium 2015/10/05 12:54:01 can you point to an examle of range for? I think t
Guido Urdaneta 2015/10/05 13:00:25 Since this is not an STL container I don't know if
+ mandatoryConstraintsVector.append(WebMediaConstraint(iter->key, iter->value));
+ }
+
+ Vector<WebMediaConstraint> optionalConstraintsVector;
+ if (constraintsIn.hasOptional()) {
+ const Vector<Dictionary> optionalConstraints = constraintsIn.optional();
+
+ for (size_t i = 0; i < optionalConstraints.size(); ++i) {
Guido Urdaneta 2015/10/05 12:34:12 Range for?
+ Dictionary constraint = optionalConstraints[i];
+ if (constraint.isUndefinedOrNull())
+ return false;
+ Vector<String> localNames;
+ constraint.getPropertyNames(localNames);
+ if (localNames.size() != 1)
+ return false;
+ String key = localNames[0];
+ String value;
+ bool ok = DictionaryHelper::get(constraint, key, value);
+ if (!ok)
+ return false;
+ optionalConstraintsVector.append(WebMediaConstraint(key, value));
+ }
+ }
+
+ optional.assign(optionalConstraintsVector);
+ mandatory.assign(mandatoryConstraintsVector);
+ return true;
+}
+
WebMediaConstraints create(const Dictionary& constraintsDictionary, ExceptionState& exceptionState)
{
@@ -127,6 +170,19 @@ WebMediaConstraints create(const Dictionary& constraintsDictionary, ExceptionSta
return constraints;
}
+WebMediaConstraints create(const MediaTrackConstraintSet& constraintsIn, ExceptionState& exceptionState)
+{
+ WebVector<WebMediaConstraint> optional;
+ WebVector<WebMediaConstraint> mandatory;
+ if (!parse(constraintsIn, optional, mandatory)) {
+ exceptionState.throwTypeError("Malformed constraints object.");
+ return WebMediaConstraints();
+ }
+ WebMediaConstraints constraints;
+ constraints.initialize(optional, mandatory);
+ return constraints;
+}
+
WebMediaConstraints create()
{
WebMediaConstraints constraints;

Powered by Google App Engine
This is Rietveld 408576698