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

Side by Side Diff: ui/aura/mus/property_converter.cc

Issue 2702423004: Validate incoming window properties. (Closed)
Patch Set: sky comments Created 3 years, 10 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
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/mus/property_converter.h" 5 #include "ui/aura/mus/property_converter.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "mojo/public/cpp/bindings/type_converter.h" 8 #include "mojo/public/cpp/bindings/type_converter.h"
9 #include "services/ui/public/cpp/property_type_converters.h" 9 #include "services/ui/public/cpp/property_type_converters.h"
10 #include "services/ui/public/interfaces/window_manager.mojom.h" 10 #include "services/ui/public/interfaces/window_manager.mojom.h"
11 #include "ui/aura/client/aura_constants.h" 11 #include "ui/aura/client/aura_constants.h"
12 #include "ui/base/class_property.h" 12 #include "ui/base/class_property.h"
13 13
14 namespace aura { 14 namespace aura {
15 15
16 namespace { 16 namespace {
17 17
18 // Get the WindowProperty's value as a byte array. Only supports aura properties 18 // Get the WindowProperty's value as a byte array. Only supports aura properties
19 // that point to types with a matching std::vector<uint8_t> mojo::TypeConverter. 19 // that point to types with a matching std::vector<uint8_t> mojo::TypeConverter.
20 template <typename T> 20 template <typename T>
21 std::unique_ptr<std::vector<uint8_t>> GetArray(Window* window, 21 std::unique_ptr<std::vector<uint8_t>> GetArray(Window* window,
22 const WindowProperty<T>* key) { 22 const WindowProperty<T>* key) {
23 const T value = window->GetProperty(key); 23 const T value = window->GetProperty(key);
24 if (!value) 24 if (!value)
25 return base::MakeUnique<std::vector<uint8_t>>(); 25 return base::MakeUnique<std::vector<uint8_t>>();
26 return base::MakeUnique<std::vector<uint8_t>>( 26 return base::MakeUnique<std::vector<uint8_t>>(
27 mojo::ConvertTo<std::vector<uint8_t>>(*value)); 27 mojo::ConvertTo<std::vector<uint8_t>>(*value));
28 } 28 }
29 29
30 // A validator that always returns true regardless of its input.
31 bool AlwaysTrue(int64_t value) {
32 return true;
33 }
34
35 bool ValidateResizeBehaviour(int64_t value) {
36 // Resize behaviour is a 3 bitfield.
37 return value >= 0 &&
38 value <= (ui::mojom::kResizeBehaviorCanMaximize |
39 ui::mojom::kResizeBehaviorCanMinimize |
40 ui::mojom::kResizeBehaviorCanResize);
41 }
42
43 bool ValidateShowState(int64_t value) {
44 return value == int64_t(ui::mojom::ShowState::DEFAULT) ||
45 value == int64_t(ui::mojom::ShowState::NORMAL) ||
46 value == int64_t(ui::mojom::ShowState::MINIMIZED) ||
47 value == int64_t(ui::mojom::ShowState::MAXIMIZED) ||
48 value == int64_t(ui::mojom::ShowState::INACTIVE) ||
49 value == int64_t(ui::mojom::ShowState::FULLSCREEN) ||
50 value == int64_t(ui::mojom::ShowState::DOCKED);
51 }
52
30 } // namespace 53 } // namespace
31 54
55 PropertyConverter::PrimitiveProperty::PrimitiveProperty() {}
56
57 PropertyConverter::PrimitiveProperty::PrimitiveProperty(
58 const PrimitiveProperty& property) = default;
59
60 PropertyConverter::PrimitiveProperty::~PrimitiveProperty() {}
61
62 // static
63 base::RepeatingCallback<bool(int64_t)>
64 PropertyConverter::CreateAcceptAnyValueCallback() {
65 return base::Bind(&AlwaysTrue);
66 }
67
32 PropertyConverter::PropertyConverter() { 68 PropertyConverter::PropertyConverter() {
33 // Add known aura properties with associated mus properties. 69 // Add known aura properties with associated mus properties.
34 RegisterProperty(client::kAlwaysOnTopKey, 70 RegisterProperty(client::kAlwaysOnTopKey,
35 ui::mojom::WindowManager::kAlwaysOnTop_Property); 71 ui::mojom::WindowManager::kAlwaysOnTop_Property,
72 CreateAcceptAnyValueCallback());
36 RegisterProperty(client::kAppIconKey, 73 RegisterProperty(client::kAppIconKey,
37 ui::mojom::WindowManager::kAppIcon_Property); 74 ui::mojom::WindowManager::kAppIcon_Property);
38 RegisterProperty(client::kAppIdKey, 75 RegisterProperty(client::kAppIdKey,
39 ui::mojom::WindowManager::kAppID_Property); 76 ui::mojom::WindowManager::kAppID_Property);
40 RegisterProperty(client::kImmersiveFullscreenKey, 77 RegisterProperty(client::kImmersiveFullscreenKey,
41 ui::mojom::WindowManager::kImmersiveFullscreen_Property); 78 ui::mojom::WindowManager::kImmersiveFullscreen_Property,
79 CreateAcceptAnyValueCallback());
42 RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); 80 RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property);
43 RegisterProperty(client::kPreferredSize, 81 RegisterProperty(client::kPreferredSize,
44 ui::mojom::WindowManager::kPreferredSize_Property); 82 ui::mojom::WindowManager::kPreferredSize_Property);
45 RegisterProperty(client::kResizeBehaviorKey, 83 RegisterProperty(client::kResizeBehaviorKey,
46 ui::mojom::WindowManager::kResizeBehavior_Property); 84 ui::mojom::WindowManager::kResizeBehavior_Property,
85 base::Bind(&ValidateResizeBehaviour));
47 RegisterProperty(client::kRestoreBoundsKey, 86 RegisterProperty(client::kRestoreBoundsKey,
48 ui::mojom::WindowManager::kRestoreBounds_Property); 87 ui::mojom::WindowManager::kRestoreBounds_Property);
49 RegisterProperty(client::kShowStateKey, 88 RegisterProperty(client::kShowStateKey,
50 ui::mojom::WindowManager::kShowState_Property); 89 ui::mojom::WindowManager::kShowState_Property,
90 base::Bind(&ValidateShowState));
51 RegisterProperty(client::kWindowIconKey, 91 RegisterProperty(client::kWindowIconKey,
52 ui::mojom::WindowManager::kWindowIcon_Property); 92 ui::mojom::WindowManager::kWindowIcon_Property);
53 RegisterProperty(client::kTitleKey, 93 RegisterProperty(client::kTitleKey,
54 ui::mojom::WindowManager::kWindowTitle_Property); 94 ui::mojom::WindowManager::kWindowTitle_Property);
55 } 95 }
56 96
57 PropertyConverter::~PropertyConverter() {} 97 PropertyConverter::~PropertyConverter() {}
58 98
59 bool PropertyConverter::IsTransportNameRegistered( 99 bool PropertyConverter::IsTransportNameRegistered(
60 const std::string& name) const { 100 const std::string& name) const {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const std::vector<uint8_t>* data) { 191 const std::vector<uint8_t>* data) {
152 for (const auto& primitive_property : primitive_properties_) { 192 for (const auto& primitive_property : primitive_properties_) {
153 if (primitive_property.second.transport_name == transport_name) { 193 if (primitive_property.second.transport_name == transport_name) {
154 // aura::Window only supports property types that fit in PrimitiveType. 194 // aura::Window only supports property types that fit in PrimitiveType.
155 if (data->size() != 8u) { 195 if (data->size() != 8u) {
156 DVLOG(2) << "Property size mismatch (PrimitiveType): " 196 DVLOG(2) << "Property size mismatch (PrimitiveType): "
157 << transport_name; 197 << transport_name;
158 return; 198 return;
159 } 199 }
160 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); 200 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data);
201 if (!primitive_property.second.validator.Run(value)) {
202 DVLOG(2) << "Property value rejected (PrimitiveType): "
203 << transport_name;
204 return;
205 }
161 // TODO(msw): Should aura::Window just store all properties by name? 206 // TODO(msw): Should aura::Window just store all properties by name?
162 window->SetPropertyInternal( 207 window->SetPropertyInternal(
163 primitive_property.first, primitive_property.second.property_name, 208 primitive_property.first, primitive_property.second.property_name,
164 nullptr, value, primitive_property.second.default_value); 209 nullptr, value, primitive_property.second.default_value);
165 return; 210 return;
166 } 211 }
167 } 212 }
168 213
169 for (const auto& image_property : image_properties_) { 214 for (const auto& image_property : image_properties_) {
170 if (image_property.second == transport_name) { 215 if (image_property.second == transport_name) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const std::string& transport_name, 271 const std::string& transport_name,
227 const std::vector<uint8_t>& transport_data, 272 const std::vector<uint8_t>& transport_data,
228 PrimitiveType* value) { 273 PrimitiveType* value) {
229 // aura::Window only supports property types that fit in PrimitiveType. 274 // aura::Window only supports property types that fit in PrimitiveType.
230 if (transport_data.size() != 8u) { 275 if (transport_data.size() != 8u) {
231 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name; 276 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name;
232 return false; 277 return false;
233 } 278 }
234 for (const auto& primitive_property : primitive_properties_) { 279 for (const auto& primitive_property : primitive_properties_) {
235 if (primitive_property.second.transport_name == transport_name) { 280 if (primitive_property.second.transport_name == transport_name) {
236 *value = mojo::ConvertTo<PrimitiveType>(transport_data); 281 PrimitiveType v = mojo::ConvertTo<PrimitiveType>(transport_data);
282 if (!primitive_property.second.validator.Run(v)) {
283 DVLOG(2) << "Property value rejected (PrimitiveType): "
284 << transport_name;
285 return false;
286 }
287 *value = v;
237 return true; 288 return true;
238 } 289 }
239 } 290 }
240 return false; 291 return false;
241 } 292 }
242 293
243 void PropertyConverter::RegisterProperty( 294 void PropertyConverter::RegisterProperty(
244 const WindowProperty<gfx::ImageSkia*>* property, 295 const WindowProperty<gfx::ImageSkia*>* property,
245 const char* transport_name) { 296 const char* transport_name) {
246 image_properties_[property] = transport_name; 297 image_properties_[property] = transport_name;
(...skipping 22 matching lines...) Expand all
269 } 320 }
270 321
271 void PropertyConverter::RegisterProperty( 322 void PropertyConverter::RegisterProperty(
272 const WindowProperty<base::string16*>* property, 323 const WindowProperty<base::string16*>* property,
273 const char* transport_name) { 324 const char* transport_name) {
274 string16_properties_[property] = transport_name; 325 string16_properties_[property] = transport_name;
275 transport_names_.insert(transport_name); 326 transport_names_.insert(transport_name);
276 } 327 }
277 328
278 } // namespace aura 329 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698