This source file includes following definitions.
- parse
- create
- create
#include "config.h"
#include "modules/mediastream/MediaConstraintsImpl.h"
#include "bindings/v8/ArrayValue.h"
#include "bindings/v8/Dictionary.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "wtf/HashMap.h"
#include "wtf/Vector.h"
#include "wtf/text/StringHash.h"
namespace WebCore {
namespace MediaConstraintsImpl {
static bool parse(const Dictionary& constraintsDictionary, blink::WebVector<blink::WebMediaConstraint>& optional, blink::WebVector<blink::WebMediaConstraint>& mandatory)
{
if (constraintsDictionary.isUndefinedOrNull())
return true;
Vector<String> names;
constraintsDictionary.getOwnPropertyNames(names);
String mandatoryName("mandatory");
String optionalName("optional");
for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) {
if (*it != mandatoryName && *it != optionalName)
return false;
}
Vector<blink::WebMediaConstraint> mandatoryConstraintsVector;
if (names.contains(mandatoryName)) {
Dictionary mandatoryConstraintsDictionary;
bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsDictionary);
if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull())
return false;
HashMap<String, String> mandatoryConstraintsHashMap;
ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(mandatoryConstraintsHashMap);
if (!ok)
return false;
HashMap<String, String>::const_iterator iter = mandatoryConstraintsHashMap.begin();
for (; iter != mandatoryConstraintsHashMap.end(); ++iter)
mandatoryConstraintsVector.append(blink::WebMediaConstraint(iter->key, iter->value));
}
Vector<blink::WebMediaConstraint> optionalConstraintsVector;
if (names.contains(optionalName)) {
ArrayValue optionalConstraints;
bool ok = constraintsDictionary.get(optionalName, optionalConstraints);
if (!ok || optionalConstraints.isUndefinedOrNull())
return false;
size_t numberOfConstraints;
ok = optionalConstraints.length(numberOfConstraints);
if (!ok)
return false;
for (size_t i = 0; i < numberOfConstraints; ++i) {
Dictionary constraint;
ok = optionalConstraints.get(i, constraint);
if (!ok || constraint.isUndefinedOrNull())
return false;
Vector<String> localNames;
constraint.getOwnPropertyNames(localNames);
if (localNames.size() != 1)
return false;
String key = localNames[0];
String value;
ok = constraint.get(key, value);
if (!ok)
return false;
optionalConstraintsVector.append(blink::WebMediaConstraint(key, value));
}
}
optional.assign(optionalConstraintsVector);
mandatory.assign(mandatoryConstraintsVector);
return true;
}
blink::WebMediaConstraints create(const Dictionary& constraintsDictionary, ExceptionState& exceptionState)
{
blink::WebVector<blink::WebMediaConstraint> optional;
blink::WebVector<blink::WebMediaConstraint> mandatory;
if (!parse(constraintsDictionary, optional, mandatory)) {
exceptionState.throwTypeError("Malformed constraints object.");
return blink::WebMediaConstraints();
}
blink::WebMediaConstraints constraints;
constraints.initialize(optional, mandatory);
return constraints;
}
blink::WebMediaConstraints create()
{
blink::WebMediaConstraints constraints;
constraints.initialize();
return constraints;
}
}
}