Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/media_stream_constraints_util.h" | |
| 6 | |
| 7 #include "base/strings/string_number_conversions.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 15 const std::string& key, | |
| 16 bool* value) { | |
| 17 int constraint_value = 0; | |
| 18 if (!GetConstraintValue(constraints, key, &constraint_value)) | |
| 19 return false; | |
| 20 | |
| 21 *value = static_cast<bool>(constraint_value); | |
|
tommi (sloooow) - chröme
2014/04/17 10:56:41
can you DCHECK that constraint_value is either 1 o
no longer working on chromium
2014/04/23 14:59:06
No, that is constraint from JS, users can set it t
no longer working on chromium
2014/04/23 18:16:48
Wrong reply, I added overloaded methods for the Ge
| |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 26 const std::string& key, | |
| 27 int* value) { | |
| 28 return GetMandatoryConstraintValue(constraints, key, value) || | |
| 29 GetOptionalConstraintValue(constraints, key, value); | |
| 30 } | |
| 31 | |
| 32 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 33 const std::string& key, | |
| 34 std::string* value) { | |
| 35 blink::WebString value_str; | |
| 36 if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), | |
| 37 value_str) && | |
| 38 !constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), | |
| 39 value_str)) { | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 *value = value_str.utf8(); | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 bool GetMandatoryConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 48 const std::string& key, | |
| 49 int* value) { | |
| 50 blink::WebString value_str; | |
| 51 if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), | |
| 52 value_str)) { | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 return base::StringToInt(value_str.utf8(), value); | |
|
tommi (sloooow) - chröme
2014/04/17 10:56:41
I think I've asked about this as well before. It
no longer working on chromium
2014/04/23 15:11:55
Thanks for pointing it out. I misunderstood that t
| |
| 57 } | |
| 58 | |
| 59 bool GetOptionalConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 60 const std::string& key, | |
| 61 int* value) { | |
| 62 blink::WebString value_str; | |
| 63 if (!constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), | |
| 64 value_str)) { | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 return base::StringToInt(value_str.utf8(), value); | |
|
tommi (sloooow) - chröme
2014/04/17 10:56:41
here too
no longer working on chromium
2014/04/23 15:11:55
Ditto.
| |
| 69 } | |
| 70 | |
| 71 } // namespace content | |
| OLD | NEW |