| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/mus/property_converter.h" |
| 6 |
| 7 #include "mojo/public/cpp/bindings/type_converter.h" |
| 8 #include "services/ui/public/cpp/property_type_converters.h" |
| 9 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/window_property.h" |
| 12 |
| 13 namespace aura { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Get the aura property key and name for a mus property transport |name|. |
| 18 bool GetPropertyKeyForTransportName(const std::string& name, |
| 19 const void** key_out, |
| 20 const char** name_out) { |
| 21 if (name == ui::mojom::WindowManager::kAlwaysOnTop_Property) { |
| 22 *key_out = client::kAlwaysOnTopKey; |
| 23 *name_out = client::kAlwaysOnTopKey->name; |
| 24 return true; |
| 25 } |
| 26 return false; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 PropertyConverter::PropertyConverter() {} |
| 32 |
| 33 PropertyConverter::~PropertyConverter() {} |
| 34 |
| 35 bool PropertyConverter::ConvertPropertyForTransport( |
| 36 Window* window, |
| 37 const void* key, |
| 38 std::string* server_property_name, |
| 39 std::unique_ptr<std::vector<uint8_t>>* server_property_value) { |
| 40 *server_property_name = GetTransportNameForPropertyKey(key); |
| 41 if (!server_property_name->empty()) { |
| 42 // TODO(msw): Using the int64_t accessor is wasteful for bool, etc. |
| 43 const int64_t value = window->GetPropertyInternal(key, 0); |
| 44 *server_property_value = base::MakeUnique<std::vector<uint8_t>>( |
| 45 mojo::ConvertTo<std::vector<uint8_t>>(value)); |
| 46 return true; |
| 47 } |
| 48 DVLOG(2) << "Unknown aura property key: " << key; |
| 49 return false; |
| 50 } |
| 51 |
| 52 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { |
| 53 if (key == client::kAlwaysOnTopKey) |
| 54 return ui::mojom::WindowManager::kAlwaysOnTop_Property; |
| 55 return std::string(); |
| 56 } |
| 57 |
| 58 void PropertyConverter::SetPropertyFromTransportValue( |
| 59 Window* window, |
| 60 const std::string& server_property_name, |
| 61 const std::vector<uint8_t>* data) { |
| 62 const void* key = nullptr; |
| 63 const char* name = nullptr; |
| 64 if (GetPropertyKeyForTransportName(server_property_name, &key, &name)) { |
| 65 DCHECK(key); |
| 66 DCHECK(name); |
| 67 // Aura window only supports property types that fit in int64_t. |
| 68 CHECK_LE(8u, data->size()) << " Property type not supported: " << key; |
| 69 const int64_t value = mojo::ConvertTo<int64_t>(*data); |
| 70 // TODO(msw): Should aura::Window just store all properties by name? |
| 71 window->SetPropertyInternal(key, name, nullptr, value, 0); |
| 72 } else { |
| 73 DVLOG(2) << "Unknown mus property name: " << server_property_name; |
| 74 } |
| 75 } |
| 76 |
| 77 } // namespace aura |
| OLD | NEW |