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

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

Issue 2702423004: Validate incoming window properties. (Closed)
Patch Set: rebase to tot 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
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 #ifndef UI_AURA_MUS_PROPERTY_CONVERTER_H_ 5 #ifndef UI_AURA_MUS_PROPERTY_CONVERTER_H_
6 #define UI_AURA_MUS_PROPERTY_CONVERTER_H_ 6 #define UI_AURA_MUS_PROPERTY_CONVERTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback_forward.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "ui/aura/aura_export.h" 17 #include "ui/aura/aura_export.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
18 19
19 namespace gfx { 20 namespace gfx {
20 class Rect; 21 class Rect;
21 class Size; 22 class Size;
22 } 23 }
23 24
24 namespace aura { 25 namespace aura {
25 26
26 // PropertyConverter is used to convert Window properties for transport to the 27 // PropertyConverter is used to convert Window properties for transport to the
27 // mus window server and back. Any time a property changes from one side it is 28 // mus window server and back. Any time a property changes from one side it is
28 // mapped to the other using this class. Not all Window properties need to map 29 // mapped to the other using this class. Not all Window properties need to map
29 // to server properties, and similarly not all transport properties need map to 30 // to server properties, and similarly not all transport properties need map to
30 // Window properties. 31 // Window properties.
31 class AURA_EXPORT PropertyConverter { 32 class AURA_EXPORT PropertyConverter {
32 public: 33 public:
33 // All primitive values are stored using this type. 34 // All primitive values are stored using this type.
34 using PrimitiveType = int64_t; 35 using PrimitiveType = int64_t;
35 36
37 static base::RepeatingCallback<bool(int32_t)> AcceptAnyValue();
sky 2017/02/23 21:02:25 After constructor/destructor, and add a comment. W
Elliot Glaysher 2017/02/23 22:12:43 Done.
38
36 PropertyConverter(); 39 PropertyConverter();
37 ~PropertyConverter(); 40 ~PropertyConverter();
38 41
39 // Returns true if RegisterProperty() has been called with the specified 42 // Returns true if RegisterProperty() has been called with the specified
40 // transport name. 43 // transport name.
41 bool IsTransportNameRegistered(const std::string& name) const; 44 bool IsTransportNameRegistered(const std::string& name) const;
42 45
43 // Maps a property on the Window to a property pushed to the server. Return 46 // Maps a property on the Window to a property pushed to the server. Return
44 // true if the property should be sent to the server, false if the property 47 // true if the property should be sent to the server, false if the property
45 // is only used locally. 48 // is only used locally.
(...skipping 18 matching lines...) Expand all
64 // serialized as a PrimitiveType, so this function may be used for any 67 // serialized as a PrimitiveType, so this function may be used for any
65 // primitive. Returns true on success and sets |value| accordingly. A return 68 // primitive. Returns true on success and sets |value| accordingly. A return
66 // value of false indicates the value isn't known or the property type isn't 69 // value of false indicates the value isn't known or the property type isn't
67 // primitive. 70 // primitive.
68 bool GetPropertyValueFromTransportValue( 71 bool GetPropertyValueFromTransportValue(
69 const std::string& transport_name, 72 const std::string& transport_name,
70 const std::vector<uint8_t>& transport_data, 73 const std::vector<uint8_t>& transport_data,
71 PrimitiveType* value); 74 PrimitiveType* value);
72 75
73 // Register a property to support conversion between mus and aura. 76 // Register a property to support conversion between mus and aura.
74 template<typename T> 77 template <typename T>
75 void RegisterProperty(const WindowProperty<T>* property, 78 void RegisterProperty(
76 const char* transport_name) { 79 const WindowProperty<T>* property,
80 const char* transport_name,
81 const base::RepeatingCallback<bool(int32_t)>& validator) {
sky 2017/02/23 21:02:25 Document what the validator is, and mention using
Elliot Glaysher 2017/02/23 22:12:43 Commented, and you are right that all the int32_ts
77 PrimitiveProperty primitive_property; 82 PrimitiveProperty primitive_property;
78 primitive_property.property_name = property->name; 83 primitive_property.property_name = property->name;
79 primitive_property.transport_name = transport_name; 84 primitive_property.transport_name = transport_name;
80 primitive_property.default_value = 85 primitive_property.default_value =
81 ui::ClassPropertyCaster<T>::ToInt64(property->default_value); 86 ui::ClassPropertyCaster<T>::ToInt64(property->default_value);
87 primitive_property.validator = validator;
82 primitive_properties_[property] = primitive_property; 88 primitive_properties_[property] = primitive_property;
83 transport_names_.insert(transport_name); 89 transport_names_.insert(transport_name);
84 } 90 }
85 91
86 // Specializations for properties to pointer types supporting mojo conversion. 92 // Specializations for properties to pointer types supporting mojo conversion.
87 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property, 93 void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property,
88 const char* transport_name); 94 const char* transport_name);
89 void RegisterProperty(const WindowProperty<gfx::Rect*>* property, 95 void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
90 const char* transport_name); 96 const char* transport_name);
91 void RegisterProperty(const WindowProperty<gfx::Size*>* property, 97 void RegisterProperty(const WindowProperty<gfx::Size*>* property,
92 const char* transport_name); 98 const char* transport_name);
93 void RegisterProperty(const WindowProperty<std::string*>* property, 99 void RegisterProperty(const WindowProperty<std::string*>* property,
94 const char* transport_name); 100 const char* transport_name);
95 void RegisterProperty(const WindowProperty<base::string16*>* property, 101 void RegisterProperty(const WindowProperty<base::string16*>* property,
96 const char* transport_name); 102 const char* transport_name);
97 103
98 private: 104 private:
99 // Contains data needed to store and convert primitive-type properties. 105 // Contains data needed to store and convert primitive-type properties.
100 struct PrimitiveProperty { 106 struct AURA_EXPORT PrimitiveProperty {
107 PrimitiveProperty();
108 PrimitiveProperty(const PrimitiveProperty& property);
109 ~PrimitiveProperty();
110
101 // The aura::WindowProperty::name used for storage. 111 // The aura::WindowProperty::name used for storage.
102 const char* property_name = nullptr; 112 const char* property_name = nullptr;
103 // The mus property name used for transport. 113 // The mus property name used for transport.
104 const char* transport_name = nullptr; 114 const char* transport_name = nullptr;
105 // The aura::WindowProperty::default_value stored using PrimitiveType. 115 // The aura::WindowProperty::default_value stored using PrimitiveType.
106 PrimitiveType default_value = 0; 116 PrimitiveType default_value = 0;
117 // A callback used to validate incoming values.
118 base::RepeatingCallback<bool(int32_t)> validator;
107 }; 119 };
108 120
109 // A map of aura::WindowProperty<T> to PrimitiveProperty structs. 121 // A map of aura::WindowProperty<T> to PrimitiveProperty structs.
110 // This supports the internal codepaths for primitive types, eg. T=bool. 122 // This supports the internal codepaths for primitive types, eg. T=bool.
111 std::map<const void*, PrimitiveProperty> primitive_properties_; 123 std::map<const void*, PrimitiveProperty> primitive_properties_;
112 124
113 // Maps of aura::WindowProperty<T> to their mus property names. 125 // Maps of aura::WindowProperty<T> to their mus property names.
114 // This supports types that can be serialized for Mojo, eg. T=std::string*. 126 // This supports types that can be serialized for Mojo, eg. T=std::string*.
115 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*> 127 std::map<const WindowProperty<gfx::ImageSkia*>*, const char*>
116 image_properties_; 128 image_properties_;
117 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_; 129 std::map<const WindowProperty<gfx::Rect*>*, const char*> rect_properties_;
118 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_; 130 std::map<const WindowProperty<gfx::Size*>*, const char*> size_properties_;
119 std::map<const WindowProperty<std::string*>*, const char*> string_properties_; 131 std::map<const WindowProperty<std::string*>*, const char*> string_properties_;
120 std::map<const WindowProperty<base::string16*>*, const char*> 132 std::map<const WindowProperty<base::string16*>*, const char*>
121 string16_properties_; 133 string16_properties_;
122 134
123 // Set of transport names supplied to RegisterProperty(). 135 // Set of transport names supplied to RegisterProperty().
124 std::set<std::string> transport_names_; 136 std::set<std::string> transport_names_;
125 137
126 DISALLOW_COPY_AND_ASSIGN(PropertyConverter); 138 DISALLOW_COPY_AND_ASSIGN(PropertyConverter);
127 }; 139 };
128 140
129 } // namespace aura 141 } // namespace aura
130 142
131 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_ 143 #endif // UI_AURA_MUS_PROPERTY_CONVERTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698