Chromium Code Reviews| Index: ui/aura/mus/property_converter.cc |
| diff --git a/ui/aura/mus/property_converter.cc b/ui/aura/mus/property_converter.cc |
| index 9787d57626460a43747f8f46791b4375c6aa97c7..14a85014c8b0279bfb17e7ea60706b3a67c7d8c9 100644 |
| --- a/ui/aura/mus/property_converter.cc |
| +++ b/ui/aura/mus/property_converter.cc |
| @@ -27,27 +27,64 @@ std::unique_ptr<std::vector<uint8_t>> GetArray(Window* window, |
| mojo::ConvertTo<std::vector<uint8_t>>(*value)); |
| } |
| +// A validator that always returns true regardless of its input. |
| +bool AlwaysTrue(int64_t value) { |
| + return true; |
| +} |
| + |
| +bool ValidateResizeBehavior(int64_t value) { |
| + // Resize behaviour is a 3 bitfield. |
|
msw
2017/02/23 22:35:12
nit: consistent Behavior/behaviour spelling
Elliot Glaysher
2017/02/23 22:57:34
Done.
|
| + return value >= 0 && value <= 7; |
|
msw
2017/02/23 22:35:12
optional nit: use value >= 0 && value <= ui::mojom
Elliot Glaysher
2017/02/23 22:57:34
Done.
|
| +} |
| + |
| +bool ValidateShowState(int64_t value) { |
| + return value == int64_t(ui::mojom::ShowState::DEFAULT) || |
|
msw
2017/02/23 22:35:12
It's a bummer that validating each enum requires l
Elliot Glaysher
2017/02/23 22:57:34
Acknowledged.
|
| + value == int64_t(ui::mojom::ShowState::NORMAL) || |
| + value == int64_t(ui::mojom::ShowState::MINIMIZED) || |
| + value == int64_t(ui::mojom::ShowState::MAXIMIZED) || |
| + value == int64_t(ui::mojom::ShowState::INACTIVE) || |
| + value == int64_t(ui::mojom::ShowState::FULLSCREEN) || |
| + value == int64_t(ui::mojom::ShowState::DOCKED); |
| +} |
| + |
| } // namespace |
| +PropertyConverter::PrimitiveProperty::PrimitiveProperty() {} |
| + |
| +PropertyConverter::PrimitiveProperty::PrimitiveProperty( |
| + const PrimitiveProperty& property) = default; |
| + |
| +PropertyConverter::PrimitiveProperty::~PrimitiveProperty() {} |
| + |
| +// static |
| +base::RepeatingCallback<bool(int64_t)> |
| +PropertyConverter::CreateAcceptAnyValueCallback() { |
| + return base::Bind(&AlwaysTrue); |
| +} |
| + |
| PropertyConverter::PropertyConverter() { |
| // Add known aura properties with associated mus properties. |
| RegisterProperty(client::kAlwaysOnTopKey, |
| - ui::mojom::WindowManager::kAlwaysOnTop_Property); |
| + ui::mojom::WindowManager::kAlwaysOnTop_Property, |
| + CreateAcceptAnyValueCallback()); |
|
msw
2017/02/23 22:35:11
Should we have a special callback for validating b
Elliot Glaysher
2017/02/23 22:57:35
Unsure; are there cases where a non-0, non-1 value
msw
2017/02/23 23:22:35
Yeah, perhaps there's no value in doing so... I wa
|
| RegisterProperty(client::kAppIconKey, |
| ui::mojom::WindowManager::kAppIcon_Property); |
| RegisterProperty(client::kAppIdKey, |
| ui::mojom::WindowManager::kAppID_Property); |
| RegisterProperty(client::kImmersiveFullscreenKey, |
| - ui::mojom::WindowManager::kImmersiveFullscreen_Property); |
| + ui::mojom::WindowManager::kImmersiveFullscreen_Property, |
| + CreateAcceptAnyValueCallback()); |
| RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); |
| RegisterProperty(client::kPreferredSize, |
| ui::mojom::WindowManager::kPreferredSize_Property); |
| RegisterProperty(client::kResizeBehaviorKey, |
| - ui::mojom::WindowManager::kResizeBehavior_Property); |
| + ui::mojom::WindowManager::kResizeBehavior_Property, |
| + base::Bind(&ValidateResizeBehavior)); |
| RegisterProperty(client::kRestoreBoundsKey, |
| ui::mojom::WindowManager::kRestoreBounds_Property); |
| RegisterProperty(client::kShowStateKey, |
| - ui::mojom::WindowManager::kShowState_Property); |
| + ui::mojom::WindowManager::kShowState_Property, |
| + base::Bind(&ValidateShowState)); |
| RegisterProperty(client::kWindowIconKey, |
| ui::mojom::WindowManager::kWindowIcon_Property); |
| RegisterProperty(client::kTitleKey, |
| @@ -157,6 +194,9 @@ void PropertyConverter::SetPropertyFromTransportValue( |
| << transport_name; |
| return; |
| } |
| + const int64_t v = *reinterpret_cast<const int64_t*>(&data->front()); |
| + if (!primitive_property.second.validator.Run(v)) |
| + return; |
|
msw
2017/02/23 22:35:12
We should probably log when invalid property value
Elliot Glaysher
2017/02/23 22:57:35
Done.
|
| const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); |
| // TODO(msw): Should aura::Window just store all properties by name? |
| window->SetPropertyInternal( |
| @@ -233,6 +273,10 @@ bool PropertyConverter::GetPropertyValueFromTransportValue( |
| } |
| for (const auto& primitive_property : primitive_properties_) { |
| if (primitive_property.second.transport_name == transport_name) { |
| + const int64_t v = |
| + *reinterpret_cast<const int64_t*>(&transport_data.front()); |
| + if (!primitive_property.second.validator.Run(v)) |
| + return false; |
|
msw
2017/02/23 22:35:12
Ditto
Elliot Glaysher
2017/02/23 22:57:35
Done.
|
| *value = mojo::ConvertTo<PrimitiveType>(transport_data); |
| return true; |
| } |