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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 #include "modules/mediastream/MediaTrackConstraintSet.h" | |
34 | 35 |
35 #include "bindings/core/v8/ArrayValue.h" | 36 #include "bindings/core/v8/ArrayValue.h" |
36 #include "bindings/core/v8/Dictionary.h" | 37 #include "bindings/core/v8/Dictionary.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 blink { | 44 namespace blink { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 return false; | 106 return false; |
106 optionalConstraintsVector.append(WebMediaConstraint(key, value)); | 107 optionalConstraintsVector.append(WebMediaConstraint(key, value)); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 optional.assign(optionalConstraintsVector); | 111 optional.assign(optionalConstraintsVector); |
111 mandatory.assign(mandatoryConstraintsVector); | 112 mandatory.assign(mandatoryConstraintsVector); |
112 return true; | 113 return true; |
113 } | 114 } |
114 | 115 |
116 static bool parse(const MediaTrackConstraintSet& constraintsIn, WebVector<WebMed iaConstraint>& optional, WebVector<WebMediaConstraint>& mandatory) | |
117 { | |
118 Vector<WebMediaConstraint> mandatoryConstraintsVector; | |
119 if (constraintsIn.hasMandatory()) { | |
120 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,
| |
121 | |
122 HashMap<String, String> mandatoryConstraintsHashMap; | |
123 bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap (mandatoryConstraintsHashMap); | |
124 if (!ok) | |
125 return false; | |
126 | |
127 HashMap<String, String>::const_iterator iter = mandatoryConstraintsHashM ap.begin(); | |
128 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
| |
129 mandatoryConstraintsVector.append(WebMediaConstraint(iter->key, iter ->value)); | |
130 } | |
131 | |
132 Vector<WebMediaConstraint> optionalConstraintsVector; | |
133 if (constraintsIn.hasOptional()) { | |
134 const Vector<Dictionary> optionalConstraints = constraintsIn.optional(); | |
135 | |
136 for (size_t i = 0; i < optionalConstraints.size(); ++i) { | |
Guido Urdaneta
2015/10/05 12:34:12
Range for?
| |
137 Dictionary constraint = optionalConstraints[i]; | |
138 if (constraint.isUndefinedOrNull()) | |
139 return false; | |
140 Vector<String> localNames; | |
141 constraint.getPropertyNames(localNames); | |
142 if (localNames.size() != 1) | |
143 return false; | |
144 String key = localNames[0]; | |
145 String value; | |
146 bool ok = DictionaryHelper::get(constraint, key, value); | |
147 if (!ok) | |
148 return false; | |
149 optionalConstraintsVector.append(WebMediaConstraint(key, value)); | |
150 } | |
151 } | |
152 | |
153 optional.assign(optionalConstraintsVector); | |
154 mandatory.assign(mandatoryConstraintsVector); | |
155 return true; | |
156 } | |
157 | |
115 | 158 |
116 WebMediaConstraints create(const Dictionary& constraintsDictionary, ExceptionSta te& exceptionState) | 159 WebMediaConstraints create(const Dictionary& constraintsDictionary, ExceptionSta te& exceptionState) |
117 { | 160 { |
118 WebVector<WebMediaConstraint> optional; | 161 WebVector<WebMediaConstraint> optional; |
119 WebVector<WebMediaConstraint> mandatory; | 162 WebVector<WebMediaConstraint> mandatory; |
120 if (!parse(constraintsDictionary, optional, mandatory)) { | 163 if (!parse(constraintsDictionary, optional, mandatory)) { |
121 exceptionState.throwTypeError("Malformed constraints object."); | 164 exceptionState.throwTypeError("Malformed constraints object."); |
122 return WebMediaConstraints(); | 165 return WebMediaConstraints(); |
123 } | 166 } |
124 | 167 |
125 WebMediaConstraints constraints; | 168 WebMediaConstraints constraints; |
126 constraints.initialize(optional, mandatory); | 169 constraints.initialize(optional, mandatory); |
127 return constraints; | 170 return constraints; |
128 } | 171 } |
129 | 172 |
173 WebMediaConstraints create(const MediaTrackConstraintSet& constraintsIn, Excepti onState& exceptionState) | |
174 { | |
175 WebVector<WebMediaConstraint> optional; | |
176 WebVector<WebMediaConstraint> mandatory; | |
177 if (!parse(constraintsIn, optional, mandatory)) { | |
178 exceptionState.throwTypeError("Malformed constraints object."); | |
179 return WebMediaConstraints(); | |
180 } | |
181 WebMediaConstraints constraints; | |
182 constraints.initialize(optional, mandatory); | |
183 return constraints; | |
184 } | |
185 | |
130 WebMediaConstraints create() | 186 WebMediaConstraints create() |
131 { | 187 { |
132 WebMediaConstraints constraints; | 188 WebMediaConstraints constraints; |
133 constraints.initialize(); | 189 constraints.initialize(); |
134 return constraints; | 190 return constraints; |
135 } | 191 } |
136 | 192 |
137 } // namespace MediaConstraintsImpl | 193 } // namespace MediaConstraintsImpl |
138 } // namespace blink | 194 } // namespace blink |
OLD | NEW |