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

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

Issue 2702423004: Validate incoming window properties. (Closed)
Patch Set: rebase to tot Created 3 years, 9 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 // 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(int32_t value) {
32 return true;
33 }
34
35 bool ValidateResizeBehavior(int32_t value) {
36 // Resize behaviour is a 3 bitfield.
37 return value >= 0 && value <= 7;
38 }
39
40 bool ValidateShowState(int32_t value) {
41 return value == int32_t(ui::mojom::ShowState::DEFAULT) ||
42 value == int32_t(ui::mojom::ShowState::NORMAL) ||
43 value == int32_t(ui::mojom::ShowState::MINIMIZED) ||
44 value == int32_t(ui::mojom::ShowState::MAXIMIZED) ||
45 value == int32_t(ui::mojom::ShowState::INACTIVE) ||
46 value == int32_t(ui::mojom::ShowState::FULLSCREEN) ||
47 value == int32_t(ui::mojom::ShowState::DOCKED);
48 }
49
30 } // namespace 50 } // namespace
31 51
52 PropertyConverter::PrimitiveProperty::PrimitiveProperty() {}
53
54 PropertyConverter::PrimitiveProperty::PrimitiveProperty(
55 const PrimitiveProperty& property) = default;
56
57 PropertyConverter::PrimitiveProperty::~PrimitiveProperty() {}
58
59 // static
60 base::RepeatingCallback<bool(int32_t)> PropertyConverter::AcceptAnyValue() {
61 return base::Bind(&AlwaysTrue);
62 }
63
32 PropertyConverter::PropertyConverter() { 64 PropertyConverter::PropertyConverter() {
33 // Add known aura properties with associated mus properties. 65 // Add known aura properties with associated mus properties.
34 RegisterProperty(client::kAlwaysOnTopKey, 66 RegisterProperty(client::kAlwaysOnTopKey,
35 ui::mojom::WindowManager::kAlwaysOnTop_Property); 67 ui::mojom::WindowManager::kAlwaysOnTop_Property,
68 AcceptAnyValue());
36 RegisterProperty(client::kAppIconKey, 69 RegisterProperty(client::kAppIconKey,
37 ui::mojom::WindowManager::kAppIcon_Property); 70 ui::mojom::WindowManager::kAppIcon_Property);
38 RegisterProperty(client::kAppIdKey, 71 RegisterProperty(client::kAppIdKey,
39 ui::mojom::WindowManager::kAppID_Property); 72 ui::mojom::WindowManager::kAppID_Property);
40 RegisterProperty(client::kImmersiveFullscreenKey, 73 RegisterProperty(client::kImmersiveFullscreenKey,
41 ui::mojom::WindowManager::kImmersiveFullscreen_Property); 74 ui::mojom::WindowManager::kImmersiveFullscreen_Property,
75 AcceptAnyValue());
42 RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); 76 RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property);
43 RegisterProperty(client::kPreferredSize, 77 RegisterProperty(client::kPreferredSize,
44 ui::mojom::WindowManager::kPreferredSize_Property); 78 ui::mojom::WindowManager::kPreferredSize_Property);
45 RegisterProperty(client::kResizeBehaviorKey, 79 RegisterProperty(client::kResizeBehaviorKey,
46 ui::mojom::WindowManager::kResizeBehavior_Property); 80 ui::mojom::WindowManager::kResizeBehavior_Property,
81 base::Bind(&ValidateResizeBehavior));
47 RegisterProperty(client::kRestoreBoundsKey, 82 RegisterProperty(client::kRestoreBoundsKey,
48 ui::mojom::WindowManager::kRestoreBounds_Property); 83 ui::mojom::WindowManager::kRestoreBounds_Property);
49 RegisterProperty(client::kShowStateKey, 84 RegisterProperty(client::kShowStateKey,
50 ui::mojom::WindowManager::kShowState_Property); 85 ui::mojom::WindowManager::kShowState_Property,
86 base::Bind(&ValidateShowState));
51 RegisterProperty(client::kWindowIconKey, 87 RegisterProperty(client::kWindowIconKey,
52 ui::mojom::WindowManager::kWindowIcon_Property); 88 ui::mojom::WindowManager::kWindowIcon_Property);
53 RegisterProperty(client::kTitleKey, 89 RegisterProperty(client::kTitleKey,
54 ui::mojom::WindowManager::kWindowTitle_Property); 90 ui::mojom::WindowManager::kWindowTitle_Property);
55 } 91 }
56 92
57 PropertyConverter::~PropertyConverter() {} 93 PropertyConverter::~PropertyConverter() {}
58 94
59 bool PropertyConverter::IsTransportNameRegistered( 95 bool PropertyConverter::IsTransportNameRegistered(
60 const std::string& name) const { 96 const std::string& name) const {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 const std::string& transport_name, 186 const std::string& transport_name,
151 const std::vector<uint8_t>* data) { 187 const std::vector<uint8_t>* data) {
152 for (const auto& primitive_property : primitive_properties_) { 188 for (const auto& primitive_property : primitive_properties_) {
153 if (primitive_property.second.transport_name == transport_name) { 189 if (primitive_property.second.transport_name == transport_name) {
154 // aura::Window only supports property types that fit in PrimitiveType. 190 // aura::Window only supports property types that fit in PrimitiveType.
155 if (data->size() != 8u) { 191 if (data->size() != 8u) {
156 DVLOG(2) << "Property size mismatch (PrimitiveType): " 192 DVLOG(2) << "Property size mismatch (PrimitiveType): "
157 << transport_name; 193 << transport_name;
158 return; 194 return;
159 } 195 }
196 const int32_t v = *reinterpret_cast<const int32_t*>(&data->front());
197 if (!primitive_property.second.validator.Run(v))
198 return;
160 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); 199 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data);
161 // TODO(msw): Should aura::Window just store all properties by name? 200 // TODO(msw): Should aura::Window just store all properties by name?
162 window->SetPropertyInternal( 201 window->SetPropertyInternal(
163 primitive_property.first, primitive_property.second.property_name, 202 primitive_property.first, primitive_property.second.property_name,
164 nullptr, value, primitive_property.second.default_value); 203 nullptr, value, primitive_property.second.default_value);
165 return; 204 return;
166 } 205 }
167 } 206 }
168 207
169 for (const auto& image_property : image_properties_) { 208 for (const auto& image_property : image_properties_) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const std::string& transport_name, 265 const std::string& transport_name,
227 const std::vector<uint8_t>& transport_data, 266 const std::vector<uint8_t>& transport_data,
228 PrimitiveType* value) { 267 PrimitiveType* value) {
229 // aura::Window only supports property types that fit in PrimitiveType. 268 // aura::Window only supports property types that fit in PrimitiveType.
230 if (transport_data.size() != 8u) { 269 if (transport_data.size() != 8u) {
231 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name; 270 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name;
232 return false; 271 return false;
233 } 272 }
234 for (const auto& primitive_property : primitive_properties_) { 273 for (const auto& primitive_property : primitive_properties_) {
235 if (primitive_property.second.transport_name == transport_name) { 274 if (primitive_property.second.transport_name == transport_name) {
275 const int32_t v =
276 *reinterpret_cast<const int32_t*>(&transport_data.front());
277 if (!primitive_property.second.validator.Run(v))
278 return false;
236 *value = mojo::ConvertTo<PrimitiveType>(transport_data); 279 *value = mojo::ConvertTo<PrimitiveType>(transport_data);
237 return true; 280 return true;
238 } 281 }
239 } 282 }
240 return false; 283 return false;
241 } 284 }
242 285
243 void PropertyConverter::RegisterProperty( 286 void PropertyConverter::RegisterProperty(
244 const WindowProperty<gfx::ImageSkia*>* property, 287 const WindowProperty<gfx::ImageSkia*>* property,
245 const char* transport_name) { 288 const char* transport_name) {
(...skipping 23 matching lines...) Expand all
269 } 312 }
270 313
271 void PropertyConverter::RegisterProperty( 314 void PropertyConverter::RegisterProperty(
272 const WindowProperty<base::string16*>* property, 315 const WindowProperty<base::string16*>* property,
273 const char* transport_name) { 316 const char* transport_name) {
274 string16_properties_[property] = transport_name; 317 string16_properties_[property] = transport_name;
275 transport_names_.insert(transport_name); 318 transport_names_.insert(transport_name);
276 } 319 }
277 320
278 } // namespace aura 321 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698