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..2d5390f0d18a71a7105a5923e86c2e92797e5494 100644 |
| --- a/ui/aura/mus/property_converter.cc |
| +++ b/ui/aura/mus/property_converter.cc |
| @@ -27,27 +27,67 @@ 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 ValidateResizeBehaviour(int64_t value) { |
| + // Resize behaviour is a 3 bitfield. |
| + return value >= 0 && |
| + value <= (ui::mojom::kResizeBehaviorCanMaximize | |
| + ui::mojom::kResizeBehaviorCanMinimize | |
| + ui::mojom::kResizeBehaviorCanResize); |
| +} |
| + |
| +bool ValidateShowState(int64_t value) { |
| + return value == int64_t(ui::mojom::ShowState::DEFAULT) || |
| + 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()); |
| 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(&ValidateResizeBehaviour)); |
| 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 +197,12 @@ void PropertyConverter::SetPropertyFromTransportValue( |
| << transport_name; |
| return; |
| } |
| + const int64_t v = *reinterpret_cast<const int64_t*>(&data->front()); |
| + if (!primitive_property.second.validator.Run(v)) { |
| + DVLOG(2) << "Property value rejected (PrimitiveType): " |
| + << transport_name; |
| + return; |
| + } |
| const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); |
| // TODO(msw): Should aura::Window just store all properties by name? |
| window->SetPropertyInternal( |
| @@ -233,6 +279,13 @@ 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)) { |
| + DVLOG(2) << "Property value rejected (PrimitiveType): " |
| + << transport_name; |
| + return false; |
| + } |
| *value = mojo::ConvertTo<PrimitiveType>(transport_data); |
|
sky
2017/02/24 04:09:42
Isn't this line the same as 282? PrimitiveType is
Elliot Glaysher
2017/02/24 20:50:43
Removed duplicates here and in SetPropertyFromTran
|
| return true; |
| } |