| OLD | NEW |
| 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 "mojo/public/cpp/bindings/type_converter.h" | 7 #include "mojo/public/cpp/bindings/type_converter.h" |
| 8 #include "services/ui/public/cpp/property_type_converters.h" | 8 #include "services/ui/public/cpp/property_type_converters.h" |
| 9 #include "services/ui/public/interfaces/window_manager.mojom.h" | 9 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 PropertyConverter::PropertyConverter() { | 31 PropertyConverter::PropertyConverter() { |
| 32 // Add known aura properties with associated mus properties. | 32 // Add known aura properties with associated mus properties. |
| 33 RegisterProperty(client::kAlwaysOnTopKey, | 33 RegisterProperty(client::kAlwaysOnTopKey, |
| 34 ui::mojom::WindowManager::kAlwaysOnTop_Property); | 34 ui::mojom::WindowManager::kAlwaysOnTop_Property); |
| 35 RegisterProperty(client::kAppIdKey, | 35 RegisterProperty(client::kAppIdKey, |
| 36 ui::mojom::WindowManager::kAppID_Property); | 36 ui::mojom::WindowManager::kAppID_Property); |
| 37 RegisterProperty(client::kExcludeFromMruKey, | 37 RegisterProperty(client::kExcludeFromMruKey, |
| 38 ui::mojom::WindowManager::kExcludeFromMru_Property); | 38 ui::mojom::WindowManager::kExcludeFromMru_Property); |
| 39 RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); | 39 RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property); |
| 40 RegisterProperty(client::kPreferredSize, |
| 41 ui::mojom::WindowManager::kPreferredSize_Property); |
| 40 RegisterProperty(client::kRestoreBoundsKey, | 42 RegisterProperty(client::kRestoreBoundsKey, |
| 41 ui::mojom::WindowManager::kRestoreBounds_Property); | 43 ui::mojom::WindowManager::kRestoreBounds_Property); |
| 44 RegisterProperty(client::kShowStateKey, |
| 45 ui::mojom::WindowManager::kShowState_Property); |
| 42 RegisterProperty(client::kTitleKey, | 46 RegisterProperty(client::kTitleKey, |
| 43 ui::mojom::WindowManager::kWindowTitle_Property); | 47 ui::mojom::WindowManager::kWindowTitle_Property); |
| 44 } | 48 } |
| 45 | 49 |
| 46 PropertyConverter::~PropertyConverter() {} | 50 PropertyConverter::~PropertyConverter() {} |
| 47 | 51 |
| 48 bool PropertyConverter::ConvertPropertyForTransport( | 52 bool PropertyConverter::ConvertPropertyForTransport( |
| 49 Window* window, | 53 Window* window, |
| 50 const void* key, | 54 const void* key, |
| 51 std::string* transport_name, | 55 std::string* transport_name, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 67 } | 71 } |
| 68 return true; | 72 return true; |
| 69 } | 73 } |
| 70 | 74 |
| 71 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 75 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
| 72 if (rect_properties_.count(rect_key) > 0) { | 76 if (rect_properties_.count(rect_key) > 0) { |
| 73 *transport_value = GetArray(window, rect_key); | 77 *transport_value = GetArray(window, rect_key); |
| 74 return true; | 78 return true; |
| 75 } | 79 } |
| 76 | 80 |
| 81 auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); |
| 82 if (size_properties_.count(size_key) > 0) { |
| 83 *transport_value = GetArray(window, size_key); |
| 84 return true; |
| 85 } |
| 86 |
| 77 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 87 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); |
| 78 if (string_properties_.count(string_key) > 0) { | 88 if (string_properties_.count(string_key) > 0) { |
| 79 *transport_value = GetArray(window, string_key); | 89 *transport_value = GetArray(window, string_key); |
| 80 return true; | 90 return true; |
| 81 } | 91 } |
| 82 | 92 |
| 83 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 93 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
| 84 if (string16_properties_.count(string16_key) > 0) { | 94 if (string16_properties_.count(string16_key) > 0) { |
| 85 *transport_value = GetArray(window, string16_key); | 95 *transport_value = GetArray(window, string16_key); |
| 86 return true; | 96 return true; |
| 87 } | 97 } |
| 88 | 98 |
| 89 // Handle primitive property types generically. | 99 // Handle primitive property types generically. |
| 90 DCHECK_GT(primitive_properties_.count(key), 0u); | 100 DCHECK_GT(primitive_properties_.count(key), 0u); |
| 91 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. | 101 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. |
| 92 const int64_t value = window->GetPropertyInternal(key, 0); | 102 const PrimitiveType value = window->GetPropertyInternal(key, 0); |
| 93 *transport_value = base::MakeUnique<std::vector<uint8_t>>( | 103 *transport_value = base::MakeUnique<std::vector<uint8_t>>( |
| 94 mojo::ConvertTo<std::vector<uint8_t>>(value)); | 104 mojo::ConvertTo<std::vector<uint8_t>>(value)); |
| 95 return true; | 105 return true; |
| 96 } | 106 } |
| 97 | 107 |
| 98 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { | 108 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { |
| 99 if (primitive_properties_.count(key) > 0) | 109 if (primitive_properties_.count(key) > 0) |
| 100 return primitive_properties_[key].second; | 110 return primitive_properties_[key].second; |
| 101 | 111 |
| 102 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); | 112 auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key); |
| 103 if (image_properties_.count(image_key) > 0) | 113 if (image_properties_.count(image_key) > 0) |
| 104 return image_properties_[image_key]; | 114 return image_properties_[image_key]; |
| 105 | 115 |
| 106 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); | 116 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); |
| 107 if (rect_properties_.count(rect_key) > 0) | 117 if (rect_properties_.count(rect_key) > 0) |
| 108 return rect_properties_[rect_key]; | 118 return rect_properties_[rect_key]; |
| 109 | 119 |
| 120 auto size_key = static_cast<const WindowProperty<gfx::Size*>*>(key); |
| 121 if (size_properties_.count(size_key) > 0) |
| 122 return size_properties_[size_key]; |
| 123 |
| 110 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); | 124 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); |
| 111 if (string_properties_.count(string_key) > 0) | 125 if (string_properties_.count(string_key) > 0) |
| 112 return string_properties_[string_key]; | 126 return string_properties_[string_key]; |
| 113 | 127 |
| 114 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); | 128 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key); |
| 115 if (string16_properties_.count(string16_key) > 0) | 129 if (string16_properties_.count(string16_key) > 0) |
| 116 return string16_properties_[string16_key]; | 130 return string16_properties_[string16_key]; |
| 117 | 131 |
| 118 return std::string(); | 132 return std::string(); |
| 119 } | 133 } |
| 120 | 134 |
| 121 void PropertyConverter::SetPropertyFromTransportValue( | 135 void PropertyConverter::SetPropertyFromTransportValue( |
| 122 Window* window, | 136 Window* window, |
| 123 const std::string& transport_name, | 137 const std::string& transport_name, |
| 124 const std::vector<uint8_t>* data) { | 138 const std::vector<uint8_t>* data) { |
| 125 for (const auto& primitive_property : primitive_properties_) { | 139 for (const auto& primitive_property : primitive_properties_) { |
| 126 if (primitive_property.second.second == transport_name) { | 140 if (primitive_property.second.second == transport_name) { |
| 127 // aura::Window only supports property types that fit in int64_t. | 141 // aura::Window only supports property types that fit in PrimitiveType. |
| 128 if (data->size() != 8u) { | 142 if (data->size() != 8u) { |
| 129 DVLOG(2) << "Property size mismatch (int64_t): " << transport_name; | 143 DVLOG(2) << "Property size mismatch (PrimitiveType): " |
| 144 << transport_name; |
| 130 return; | 145 return; |
| 131 } | 146 } |
| 132 const int64_t value = mojo::ConvertTo<int64_t>(*data); | 147 const PrimitiveType value = mojo::ConvertTo<PrimitiveType>(*data); |
| 133 // TODO(msw): Should aura::Window just store all properties by name? | 148 // TODO(msw): Should aura::Window just store all properties by name? |
| 134 window->SetPropertyInternal(primitive_property.first, | 149 window->SetPropertyInternal(primitive_property.first, |
| 135 primitive_property.second.first, nullptr, | 150 primitive_property.second.first, nullptr, |
| 136 value, 0); | 151 value, 0); |
| 137 return; | 152 return; |
| 138 } | 153 } |
| 139 } | 154 } |
| 140 | 155 |
| 141 for (const auto& image_property : image_properties_) { | 156 for (const auto& image_property : image_properties_) { |
| 142 if (image_property.second == transport_name) { | 157 if (image_property.second == transport_name) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 154 if (data->size() != 16u) { | 169 if (data->size() != 16u) { |
| 155 DVLOG(2) << "Property size mismatch (gfx::Rect): " << transport_name; | 170 DVLOG(2) << "Property size mismatch (gfx::Rect): " << transport_name; |
| 156 return; | 171 return; |
| 157 } | 172 } |
| 158 const gfx::Rect value = mojo::ConvertTo<gfx::Rect>(*data); | 173 const gfx::Rect value = mojo::ConvertTo<gfx::Rect>(*data); |
| 159 window->SetProperty(rect_property.first, new gfx::Rect(value)); | 174 window->SetProperty(rect_property.first, new gfx::Rect(value)); |
| 160 return; | 175 return; |
| 161 } | 176 } |
| 162 } | 177 } |
| 163 | 178 |
| 179 for (const auto& size_property : size_properties_) { |
| 180 if (size_property.second == transport_name) { |
| 181 if (data->size() != 8u) { |
| 182 DVLOG(2) << "Property size mismatch (gfx::Size): " << transport_name; |
| 183 return; |
| 184 } |
| 185 const gfx::Size value = mojo::ConvertTo<gfx::Size>(*data); |
| 186 window->SetProperty(size_property.first, new gfx::Size(value)); |
| 187 return; |
| 188 } |
| 189 } |
| 190 |
| 164 for (const auto& string_property : string_properties_) { | 191 for (const auto& string_property : string_properties_) { |
| 165 if (string_property.second == transport_name) { | 192 if (string_property.second == transport_name) { |
| 166 // TODO(msw): Validate the data somehow, before trying to convert? | 193 // TODO(msw): Validate the data somehow, before trying to convert? |
| 167 const std::string value = mojo::ConvertTo<std::string>(*data); | 194 const std::string value = mojo::ConvertTo<std::string>(*data); |
| 168 window->SetProperty(string_property.first, new std::string(value)); | 195 window->SetProperty(string_property.first, new std::string(value)); |
| 169 return; | 196 return; |
| 170 } | 197 } |
| 171 } | 198 } |
| 172 | 199 |
| 173 for (const auto& string16_property : string16_properties_) { | 200 for (const auto& string16_property : string16_properties_) { |
| 174 if (string16_property.second == transport_name) { | 201 if (string16_property.second == transport_name) { |
| 175 // TODO(msw): Validate the data somehow, before trying to convert? | 202 // TODO(msw): Validate the data somehow, before trying to convert? |
| 176 const base::string16 value = mojo::ConvertTo<base::string16>(*data); | 203 const base::string16 value = mojo::ConvertTo<base::string16>(*data); |
| 177 window->SetProperty(string16_property.first, new base::string16(value)); | 204 window->SetProperty(string16_property.first, new base::string16(value)); |
| 178 return; | 205 return; |
| 179 } | 206 } |
| 180 } | 207 } |
| 181 | 208 |
| 182 DVLOG(2) << "Unknown mus property name: " << transport_name; | 209 DVLOG(2) << "Unknown mus property name: " << transport_name; |
| 183 } | 210 } |
| 184 | 211 |
| 212 bool PropertyConverter::GetPropertyValueFromTransportValue( |
| 213 const std::string& transport_name, |
| 214 const std::vector<uint8_t>& transport_data, |
| 215 PrimitiveType* value) { |
| 216 // aura::Window only supports property types that fit in PrimitiveType. |
| 217 if (transport_data.size() != 8u) { |
| 218 DVLOG(2) << "Property size mismatch (PrimitiveType): " << transport_name; |
| 219 return false; |
| 220 } |
| 221 for (const auto& primitive_property : primitive_properties_) { |
| 222 if (primitive_property.second.second == transport_name) { |
| 223 *value = mojo::ConvertTo<PrimitiveType>(transport_data); |
| 224 return true; |
| 225 } |
| 226 } |
| 227 return false; |
| 228 } |
| 229 |
| 185 void PropertyConverter::RegisterProperty( | 230 void PropertyConverter::RegisterProperty( |
| 186 const WindowProperty<gfx::ImageSkia*>* property, | 231 const WindowProperty<gfx::ImageSkia*>* property, |
| 187 const char* transport_name) { | 232 const char* transport_name) { |
| 188 image_properties_[property] = transport_name; | 233 image_properties_[property] = transport_name; |
| 189 } | 234 } |
| 190 | 235 |
| 191 void PropertyConverter::RegisterProperty( | 236 void PropertyConverter::RegisterProperty( |
| 192 const WindowProperty<gfx::Rect*>* property, | 237 const WindowProperty<gfx::Rect*>* property, |
| 193 const char* transport_name) { | 238 const char* transport_name) { |
| 194 rect_properties_[property] = transport_name; | 239 rect_properties_[property] = transport_name; |
| 195 } | 240 } |
| 196 | 241 |
| 197 void PropertyConverter::RegisterProperty( | 242 void PropertyConverter::RegisterProperty( |
| 243 const WindowProperty<gfx::Size*>* property, |
| 244 const char* transport_name) { |
| 245 size_properties_[property] = transport_name; |
| 246 } |
| 247 |
| 248 void PropertyConverter::RegisterProperty( |
| 198 const WindowProperty<std::string*>* property, | 249 const WindowProperty<std::string*>* property, |
| 199 const char* transport_name) { | 250 const char* transport_name) { |
| 200 string_properties_[property] = transport_name; | 251 string_properties_[property] = transport_name; |
| 201 } | 252 } |
| 202 | 253 |
| 203 void PropertyConverter::RegisterProperty( | 254 void PropertyConverter::RegisterProperty( |
| 204 const WindowProperty<base::string16*>* property, | 255 const WindowProperty<base::string16*>* property, |
| 205 const char* transport_name) { | 256 const char* transport_name) { |
| 206 string16_properties_[property] = transport_name; | 257 string16_properties_[property] = transport_name; |
| 207 } | 258 } |
| 208 | 259 |
| 209 } // namespace aura | 260 } // namespace aura |
| OLD | NEW |