OLD | NEW |
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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "modules/mediastream/MediaConstraintsImpl.h" | 33 #include "modules/mediastream/MediaConstraintsImpl.h" |
34 | 34 |
35 #include "bindings/core/v8/ArrayValue.h" | 35 #include "bindings/core/v8/ArrayValue.h" |
36 #include "bindings/core/v8/Dictionary.h" | 36 #include "bindings/core/v8/Dictionary.h" |
| 37 #include "bindings/core/v8/DictionaryHelper.h" |
37 #include "bindings/core/v8/ExceptionState.h" | 38 #include "bindings/core/v8/ExceptionState.h" |
38 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
39 #include "wtf/HashMap.h" | 40 #include "wtf/HashMap.h" |
40 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
41 #include "wtf/text/StringHash.h" | 42 #include "wtf/text/StringHash.h" |
42 | 43 |
43 namespace WebCore { | 44 namespace WebCore { |
44 namespace MediaConstraintsImpl { | 45 namespace MediaConstraintsImpl { |
45 | 46 |
46 static bool parse(const Dictionary& constraintsDictionary, blink::WebVector<blin
k::WebMediaConstraint>& optional, blink::WebVector<blink::WebMediaConstraint>& m
andatory) | 47 static bool parse(const Dictionary& constraintsDictionary, blink::WebVector<blin
k::WebMediaConstraint>& optional, blink::WebVector<blink::WebMediaConstraint>& m
andatory) |
(...skipping 25 matching lines...) Expand all Loading... |
72 return false; | 73 return false; |
73 | 74 |
74 HashMap<String, String>::const_iterator iter = mandatoryConstraintsHashM
ap.begin(); | 75 HashMap<String, String>::const_iterator iter = mandatoryConstraintsHashM
ap.begin(); |
75 for (; iter != mandatoryConstraintsHashMap.end(); ++iter) | 76 for (; iter != mandatoryConstraintsHashMap.end(); ++iter) |
76 mandatoryConstraintsVector.append(blink::WebMediaConstraint(iter->ke
y, iter->value)); | 77 mandatoryConstraintsVector.append(blink::WebMediaConstraint(iter->ke
y, iter->value)); |
77 } | 78 } |
78 | 79 |
79 Vector<blink::WebMediaConstraint> optionalConstraintsVector; | 80 Vector<blink::WebMediaConstraint> optionalConstraintsVector; |
80 if (names.contains(optionalName)) { | 81 if (names.contains(optionalName)) { |
81 ArrayValue optionalConstraints; | 82 ArrayValue optionalConstraints; |
82 bool ok = constraintsDictionary.get(optionalName, optionalConstraints); | 83 bool ok = DictionaryHelper::get(constraintsDictionary, optionalName, opt
ionalConstraints); |
83 if (!ok || optionalConstraints.isUndefinedOrNull()) | 84 if (!ok || optionalConstraints.isUndefinedOrNull()) |
84 return false; | 85 return false; |
85 | 86 |
86 size_t numberOfConstraints; | 87 size_t numberOfConstraints; |
87 ok = optionalConstraints.length(numberOfConstraints); | 88 ok = optionalConstraints.length(numberOfConstraints); |
88 if (!ok) | 89 if (!ok) |
89 return false; | 90 return false; |
90 | 91 |
91 for (size_t i = 0; i < numberOfConstraints; ++i) { | 92 for (size_t i = 0; i < numberOfConstraints; ++i) { |
92 Dictionary constraint; | 93 Dictionary constraint; |
93 ok = optionalConstraints.get(i, constraint); | 94 ok = optionalConstraints.get(i, constraint); |
94 if (!ok || constraint.isUndefinedOrNull()) | 95 if (!ok || constraint.isUndefinedOrNull()) |
95 return false; | 96 return false; |
96 Vector<String> localNames; | 97 Vector<String> localNames; |
97 constraint.getOwnPropertyNames(localNames); | 98 constraint.getOwnPropertyNames(localNames); |
98 if (localNames.size() != 1) | 99 if (localNames.size() != 1) |
99 return false; | 100 return false; |
100 String key = localNames[0]; | 101 String key = localNames[0]; |
101 String value; | 102 String value; |
102 ok = constraint.get(key, value); | 103 ok = DictionaryHelper::get(constraint, key, value); |
103 if (!ok) | 104 if (!ok) |
104 return false; | 105 return false; |
105 optionalConstraintsVector.append(blink::WebMediaConstraint(key, valu
e)); | 106 optionalConstraintsVector.append(blink::WebMediaConstraint(key, valu
e)); |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 optional.assign(optionalConstraintsVector); | 110 optional.assign(optionalConstraintsVector); |
110 mandatory.assign(mandatoryConstraintsVector); | 111 mandatory.assign(mandatoryConstraintsVector); |
111 return true; | 112 return true; |
112 } | 113 } |
(...skipping 15 matching lines...) Expand all Loading... |
128 | 129 |
129 blink::WebMediaConstraints create() | 130 blink::WebMediaConstraints create() |
130 { | 131 { |
131 blink::WebMediaConstraints constraints; | 132 blink::WebMediaConstraints constraints; |
132 constraints.initialize(); | 133 constraints.initialize(); |
133 return constraints; | 134 return constraints; |
134 } | 135 } |
135 | 136 |
136 } // namespace MediaConstraintsImpl | 137 } // namespace MediaConstraintsImpl |
137 } // namespace WebCore | 138 } // namespace WebCore |
OLD | NEW |