| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // https://crbug.com/579729 | 144 // https://crbug.com/579729 |
| 145 const char kGoogLeakyBucket[] = "googLeakyBucket"; | 145 const char kGoogLeakyBucket[] = "googLeakyBucket"; |
| 146 const char kPowerLineFrequency[] = "googPowerLineFrequency"; | 146 const char kPowerLineFrequency[] = "googPowerLineFrequency"; |
| 147 // Names used for testing. | 147 // Names used for testing. |
| 148 const char kTestConstraint1[] = "valid_and_supported_1"; | 148 const char kTestConstraint1[] = "valid_and_supported_1"; |
| 149 const char kTestConstraint2[] = "valid_and_supported_2"; | 149 const char kTestConstraint2[] = "valid_and_supported_2"; |
| 150 | 150 |
| 151 static bool parseMandatoryConstraintsDictionary( | 151 static bool parseMandatoryConstraintsDictionary( |
| 152 const Dictionary& mandatoryConstraintsDictionary, | 152 const Dictionary& mandatoryConstraintsDictionary, |
| 153 Vector<NameValueStringConstraint>& mandatory) { | 153 Vector<NameValueStringConstraint>& mandatory) { |
| 154 HashMap<String, String> mandatoryConstraintsHashMap; | 154 TrackExceptionState exceptionState; |
| 155 bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap( | 155 const HashMap<String, String>& mandatoryConstraintsHashMap = |
| 156 mandatoryConstraintsHashMap); | 156 mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap( |
| 157 if (!ok) | 157 exceptionState); |
| 158 if (exceptionState.hadException()) |
| 158 return false; | 159 return false; |
| 159 | 160 |
| 160 for (const auto& iter : mandatoryConstraintsHashMap) | 161 for (const auto& iter : mandatoryConstraintsHashMap) |
| 161 mandatory.append(NameValueStringConstraint(iter.key, iter.value)); | 162 mandatory.append(NameValueStringConstraint(iter.key, iter.value)); |
| 162 return true; | 163 return true; |
| 163 } | 164 } |
| 164 | 165 |
| 165 static bool parseOptionalConstraintsVectorElement( | 166 static bool parseOptionalConstraintsVectorElement( |
| 166 const Dictionary& constraint, | 167 const Dictionary& constraint, |
| 167 Vector<NameValueStringConstraint>& optionalConstraintsVector) { | 168 Vector<NameValueStringConstraint>& optionalConstraintsVector) { |
| 168 Vector<String> localNames; | 169 TrackExceptionState exceptionState; |
| 169 bool ok = constraint.getPropertyNames(localNames); | 170 const Vector<String>& localNames = |
| 170 if (!ok) | 171 constraint.getPropertyNames(exceptionState); |
| 172 if (exceptionState.hadException()) |
| 171 return false; | 173 return false; |
| 172 if (localNames.size() != 1) | 174 if (localNames.size() != 1) |
| 173 return false; | 175 return false; |
| 174 const String& key = localNames[0]; | 176 const String& key = localNames[0]; |
| 175 String value; | 177 String value; |
| 176 ok = DictionaryHelper::get(constraint, key, value); | 178 bool ok = DictionaryHelper::get(constraint, key, value); |
| 177 if (!ok) | 179 if (!ok) |
| 178 return false; | 180 return false; |
| 179 optionalConstraintsVector.append(NameValueStringConstraint(key, value)); | 181 optionalConstraintsVector.append(NameValueStringConstraint(key, value)); |
| 180 return true; | 182 return true; |
| 181 } | 183 } |
| 182 | 184 |
| 183 // Old style parser. Deprecated. | 185 // Old style parser. Deprecated. |
| 184 static bool parse(const Dictionary& constraintsDictionary, | 186 static bool parse(const Dictionary& constraintsDictionary, |
| 185 Vector<NameValueStringConstraint>& optional, | 187 Vector<NameValueStringConstraint>& optional, |
| 186 Vector<NameValueStringConstraint>& mandatory) { | 188 Vector<NameValueStringConstraint>& mandatory) { |
| 187 if (constraintsDictionary.isUndefinedOrNull()) | 189 if (constraintsDictionary.isUndefinedOrNull()) |
| 188 return true; | 190 return true; |
| 189 | 191 |
| 190 Vector<String> names; | 192 TrackExceptionState exceptionState; |
| 191 bool ok = constraintsDictionary.getPropertyNames(names); | 193 const Vector<String>& names = |
| 192 if (!ok) | 194 constraintsDictionary.getPropertyNames(exceptionState); |
| 195 if (exceptionState.hadException()) |
| 193 return false; | 196 return false; |
| 194 | 197 |
| 195 String mandatoryName("mandatory"); | 198 String mandatoryName("mandatory"); |
| 196 String optionalName("optional"); | 199 String optionalName("optional"); |
| 197 | 200 |
| 198 for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) { | 201 for (const auto& name : names) { |
| 199 if (*it != mandatoryName && *it != optionalName) | 202 if (name != mandatoryName && name != optionalName) |
| 200 return false; | 203 return false; |
| 201 } | 204 } |
| 202 | 205 |
| 203 if (names.contains(mandatoryName)) { | 206 if (names.contains(mandatoryName)) { |
| 204 Dictionary mandatoryConstraintsDictionary; | 207 Dictionary mandatoryConstraintsDictionary; |
| 205 bool ok = constraintsDictionary.get(mandatoryName, | 208 bool ok = constraintsDictionary.get(mandatoryName, |
| 206 mandatoryConstraintsDictionary); | 209 mandatoryConstraintsDictionary); |
| 207 if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull()) | 210 if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull()) |
| 208 return false; | 211 return false; |
| 209 ok = parseMandatoryConstraintsDictionary(mandatoryConstraintsDictionary, | 212 ok = parseMandatoryConstraintsDictionary(mandatoryConstraintsDictionary, |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 MediaTrackConstraintSet element; | 803 MediaTrackConstraintSet element; |
| 801 convertConstraintSet(it, element); | 804 convertConstraintSet(it, element); |
| 802 advancedVector.append(element); | 805 advancedVector.append(element); |
| 803 } | 806 } |
| 804 if (!advancedVector.isEmpty()) | 807 if (!advancedVector.isEmpty()) |
| 805 output.setAdvanced(advancedVector); | 808 output.setAdvanced(advancedVector); |
| 806 } | 809 } |
| 807 | 810 |
| 808 } // namespace MediaConstraintsImpl | 811 } // namespace MediaConstraintsImpl |
| 809 } // namespace blink | 812 } // namespace blink |
| OLD | NEW |