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

Unified Diff: ui/aura/mus/property_converter.h

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 side-by-side diff with in-line comments
Download patch
Index: ui/aura/mus/property_converter.h
diff --git a/ui/aura/mus/property_converter.h b/ui/aura/mus/property_converter.h
index dbe10850fff633f37a5b4fdfb9500a3eac2a3c59..b523a9a5d75e0addffeba223c89059488e481574 100644
--- a/ui/aura/mus/property_converter.h
+++ b/ui/aura/mus/property_converter.h
@@ -12,6 +12,7 @@
#include <string>
#include <vector>
+#include "base/callback_forward.h"
#include "base/macros.h"
#include "ui/aura/aura_export.h"
#include "ui/aura/window.h"
@@ -36,6 +37,10 @@ class AURA_EXPORT PropertyConverter {
PropertyConverter();
~PropertyConverter();
+ // Creates a validation callback for use in RegisterProperty() which will
+ // accept any value.
+ static base::RepeatingCallback<bool(int64_t)> CreateAcceptAnyValueCallback();
+
// Returns true if RegisterProperty() has been called with the specified
// transport name.
bool IsTransportNameRegistered(const std::string& name) const;
@@ -71,14 +76,19 @@ class AURA_EXPORT PropertyConverter {
PrimitiveType* value);
// Register a property to support conversion between mus and aura.
- template<typename T>
- void RegisterProperty(const WindowProperty<T>* property,
- const char* transport_name) {
+ // |validator| is a callback used to validate incoming values from
+ // transport_data; if it returns false, the value is rejected.
+ template <typename T>
+ void RegisterProperty(
+ const WindowProperty<T>* property,
+ const char* transport_name,
+ const base::RepeatingCallback<bool(int64_t)>& validator) {
PrimitiveProperty primitive_property;
primitive_property.property_name = property->name;
primitive_property.transport_name = transport_name;
primitive_property.default_value =
ui::ClassPropertyCaster<T>::ToInt64(property->default_value);
+ primitive_property.validator = validator;
primitive_properties_[property] = primitive_property;
transport_names_.insert(transport_name);
}
@@ -97,13 +107,19 @@ class AURA_EXPORT PropertyConverter {
private:
// Contains data needed to store and convert primitive-type properties.
- struct PrimitiveProperty {
+ struct AURA_EXPORT PrimitiveProperty {
+ PrimitiveProperty();
+ PrimitiveProperty(const PrimitiveProperty& property);
+ ~PrimitiveProperty();
+
// The aura::WindowProperty::name used for storage.
const char* property_name = nullptr;
// The mus property name used for transport.
const char* transport_name = nullptr;
// The aura::WindowProperty::default_value stored using PrimitiveType.
PrimitiveType default_value = 0;
+ // A callback used to validate incoming values.
+ base::RepeatingCallback<bool(int64_t)> validator;
};
// A map of aura::WindowProperty<T> to PrimitiveProperty structs.
« no previous file with comments | « chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc ('k') | ui/aura/mus/property_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698