Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/modules/mediastream/MediaConstraintsImpl.cpp

Issue 469773002: Cleanup blink:: prefix usage in Source/core/modules/[mediasource/*.cpp to websockets/*.cpp] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
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/ExceptionState.h" 37 #include "bindings/core/v8/ExceptionState.h"
38 #include "core/dom/ExceptionCode.h" 38 #include "core/dom/ExceptionCode.h"
39 #include "wtf/HashMap.h" 39 #include "wtf/HashMap.h"
40 #include "wtf/Vector.h" 40 #include "wtf/Vector.h"
41 #include "wtf/text/StringHash.h" 41 #include "wtf/text/StringHash.h"
42 42
43 namespace blink { 43 namespace blink {
44
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, WebVector<WebMediaCon straint>& optional, WebVector<WebMediaConstraint>& mandatory)
47 { 48 {
48 if (constraintsDictionary.isUndefinedOrNull()) 49 if (constraintsDictionary.isUndefinedOrNull())
49 return true; 50 return true;
50 51
51 Vector<String> names; 52 Vector<String> names;
52 constraintsDictionary.getOwnPropertyNames(names); 53 constraintsDictionary.getOwnPropertyNames(names);
53 54
54 String mandatoryName("mandatory"); 55 String mandatoryName("mandatory");
55 String optionalName("optional"); 56 String optionalName("optional");
56 57
57 for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) { 58 for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) {
58 if (*it != mandatoryName && *it != optionalName) 59 if (*it != mandatoryName && *it != optionalName)
59 return false; 60 return false;
60 } 61 }
61 62
62 Vector<blink::WebMediaConstraint> mandatoryConstraintsVector; 63 Vector<WebMediaConstraint> mandatoryConstraintsVector;
63 if (names.contains(mandatoryName)) { 64 if (names.contains(mandatoryName)) {
64 Dictionary mandatoryConstraintsDictionary; 65 Dictionary mandatoryConstraintsDictionary;
65 bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsD ictionary); 66 bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsD ictionary);
66 if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull()) 67 if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull())
67 return false; 68 return false;
68 69
69 HashMap<String, String> mandatoryConstraintsHashMap; 70 HashMap<String, String> mandatoryConstraintsHashMap;
70 ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(mand atoryConstraintsHashMap); 71 ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(mand atoryConstraintsHashMap);
71 if (!ok) 72 if (!ok)
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(WebMediaConstraint(iter->key, iter ->value));
77 } 78 }
78 79
79 Vector<blink::WebMediaConstraint> optionalConstraintsVector; 80 Vector<WebMediaConstraint> optionalConstraintsVector;
80 if (names.contains(optionalName)) { 81 if (names.contains(optionalName)) {
81 ArrayValue optionalConstraints; 82 ArrayValue optionalConstraints;
82 bool ok = DictionaryHelper::get(constraintsDictionary, optionalName, opt ionalConstraints); 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 = DictionaryHelper::get(constraint, 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(WebMediaConstraint(key, value));
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 }
113 114
114 115
115 blink::WebMediaConstraints create(const Dictionary& constraintsDictionary, Excep tionState& exceptionState) 116 WebMediaConstraints create(const Dictionary& constraintsDictionary, ExceptionSta te& exceptionState)
116 { 117 {
117 blink::WebVector<blink::WebMediaConstraint> optional; 118 WebVector<WebMediaConstraint> optional;
118 blink::WebVector<blink::WebMediaConstraint> mandatory; 119 WebVector<WebMediaConstraint> mandatory;
119 if (!parse(constraintsDictionary, optional, mandatory)) { 120 if (!parse(constraintsDictionary, optional, mandatory)) {
120 exceptionState.throwTypeError("Malformed constraints object."); 121 exceptionState.throwTypeError("Malformed constraints object.");
121 return blink::WebMediaConstraints(); 122 return WebMediaConstraints();
122 } 123 }
123 124
124 blink::WebMediaConstraints constraints; 125 WebMediaConstraints constraints;
125 constraints.initialize(optional, mandatory); 126 constraints.initialize(optional, mandatory);
126 return constraints; 127 return constraints;
127 } 128 }
128 129
129 blink::WebMediaConstraints create() 130 WebMediaConstraints create()
130 { 131 {
131 blink::WebMediaConstraints constraints; 132 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 blink 138 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/mediasource/MediaSource.cpp ('k') | Source/modules/mediastream/MediaDeviceInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698