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

Side by Side Diff: ui/aura/mus/property_converter.cc

Issue 2513753003: Add string16 and name/title support to aura::PropertyConverter. (Closed)
Patch Set: Update failing test to ack all changes as failed. Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 } // namespace 29 } // namespace
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::kRestoreBoundsKey, 40 RegisterProperty(client::kRestoreBoundsKey,
40 ui::mojom::WindowManager::kRestoreBounds_Property); 41 ui::mojom::WindowManager::kRestoreBounds_Property);
42 RegisterProperty(client::kTitleKey,
43 ui::mojom::WindowManager::kWindowTitle_Property);
41 } 44 }
42 45
43 PropertyConverter::~PropertyConverter() {} 46 PropertyConverter::~PropertyConverter() {}
44 47
45 bool PropertyConverter::ConvertPropertyForTransport( 48 bool PropertyConverter::ConvertPropertyForTransport(
46 Window* window, 49 Window* window,
47 const void* key, 50 const void* key,
48 std::string* transport_name, 51 std::string* transport_name,
49 std::unique_ptr<std::vector<uint8_t>>* transport_value) { 52 std::unique_ptr<std::vector<uint8_t>>* transport_value) {
50 *transport_name = GetTransportNameForPropertyKey(key); 53 *transport_name = GetTransportNameForPropertyKey(key);
51 if (transport_name->empty()) 54 if (transport_name->empty())
52 return false; 55 return false;
53 56
54 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); 57 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key);
55 if (rect_properties_.count(rect_key) > 0) { 58 if (rect_properties_.count(rect_key) > 0) {
56 *transport_value = GetArray(window, rect_key); 59 *transport_value = GetArray(window, rect_key);
57 return true; 60 return true;
58 } 61 }
59 62
60 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); 63 auto string_key = static_cast<const WindowProperty<std::string*>*>(key);
61 if (string_properties_.count(string_key) > 0) { 64 if (string_properties_.count(string_key) > 0) {
62 *transport_value = GetArray(window, string_key); 65 *transport_value = GetArray(window, string_key);
63 return true; 66 return true;
64 } 67 }
65 68
69 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key);
70 if (string16_properties_.count(string16_key) > 0) {
71 *transport_value = GetArray(window, string16_key);
72 return true;
73 }
74
66 // Handle primitive property types generically. 75 // Handle primitive property types generically.
67 DCHECK_GT(primitive_properties_.count(key), 0u); 76 DCHECK_GT(primitive_properties_.count(key), 0u);
68 // TODO(msw): Using the int64_t accessor is wasteful for smaller types. 77 // TODO(msw): Using the int64_t accessor is wasteful for smaller types.
69 const int64_t value = window->GetPropertyInternal(key, 0); 78 const int64_t value = window->GetPropertyInternal(key, 0);
70 *transport_value = base::MakeUnique<std::vector<uint8_t>>( 79 *transport_value = base::MakeUnique<std::vector<uint8_t>>(
71 mojo::ConvertTo<std::vector<uint8_t>>(value)); 80 mojo::ConvertTo<std::vector<uint8_t>>(value));
72 return true; 81 return true;
73 } 82 }
74 83
75 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) { 84 std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) {
76 if (primitive_properties_.count(key) > 0) 85 if (primitive_properties_.count(key) > 0)
77 return primitive_properties_[key].second; 86 return primitive_properties_[key].second;
78 87
79 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key); 88 auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key);
80 if (rect_properties_.count(rect_key) > 0) 89 if (rect_properties_.count(rect_key) > 0)
81 return rect_properties_[rect_key]; 90 return rect_properties_[rect_key];
82 91
83 auto string_key = static_cast<const WindowProperty<std::string*>*>(key); 92 auto string_key = static_cast<const WindowProperty<std::string*>*>(key);
84 if (string_properties_.count(string_key) > 0) 93 if (string_properties_.count(string_key) > 0)
85 return string_properties_[string_key]; 94 return string_properties_[string_key];
86 95
96 auto string16_key = static_cast<const WindowProperty<base::string16*>*>(key);
97 if (string16_properties_.count(string16_key) > 0)
98 return string16_properties_[string16_key];
99
87 return std::string(); 100 return std::string();
88 } 101 }
89 102
90 void PropertyConverter::SetPropertyFromTransportValue( 103 void PropertyConverter::SetPropertyFromTransportValue(
91 Window* window, 104 Window* window,
92 const std::string& transport_name, 105 const std::string& transport_name,
93 const std::vector<uint8_t>* data) { 106 const std::vector<uint8_t>* data) {
94 for (const auto& primitive_property : primitive_properties_) { 107 for (const auto& primitive_property : primitive_properties_) {
95 if (primitive_property.second.second == transport_name) { 108 if (primitive_property.second.second == transport_name) {
96 // aura::Window only supports property types that fit in int64_t. 109 // aura::Window only supports property types that fit in int64_t.
(...skipping 24 matching lines...) Expand all
121 134
122 for (const auto& string_property : string_properties_) { 135 for (const auto& string_property : string_properties_) {
123 if (string_property.second == transport_name) { 136 if (string_property.second == transport_name) {
124 // TODO(msw): Validate the data somehow, before trying to convert? 137 // TODO(msw): Validate the data somehow, before trying to convert?
125 const std::string value = mojo::ConvertTo<std::string>(*data); 138 const std::string value = mojo::ConvertTo<std::string>(*data);
126 window->SetProperty(string_property.first, new std::string(value)); 139 window->SetProperty(string_property.first, new std::string(value));
127 return; 140 return;
128 } 141 }
129 } 142 }
130 143
144 for (const auto& string16_property : string16_properties_) {
145 if (string16_property.second == transport_name) {
146 // TODO(msw): Validate the data somehow, before trying to convert?
147 const base::string16 value = mojo::ConvertTo<base::string16>(*data);
148 window->SetProperty(string16_property.first, new base::string16(value));
149 return;
150 }
151 }
152
131 DVLOG(2) << "Unknown mus property name: " << transport_name; 153 DVLOG(2) << "Unknown mus property name: " << transport_name;
132 } 154 }
133 155
134 void PropertyConverter::RegisterProperty( 156 void PropertyConverter::RegisterProperty(
135 const WindowProperty<gfx::Rect*>* property, 157 const WindowProperty<gfx::Rect*>* property,
136 const char* transport_name) { 158 const char* transport_name) {
137 rect_properties_[property] = transport_name; 159 rect_properties_[property] = transport_name;
138 } 160 }
139 161
140 void PropertyConverter::RegisterProperty( 162 void PropertyConverter::RegisterProperty(
141 const WindowProperty<std::string*>* property, 163 const WindowProperty<std::string*>* property,
142 const char* transport_name) { 164 const char* transport_name) {
143 string_properties_[property] = transport_name; 165 string_properties_[property] = transport_name;
144 } 166 }
145 167
168 void PropertyConverter::RegisterProperty(
169 const WindowProperty<base::string16*>* property,
170 const char* transport_name) {
171 string16_properties_[property] = transport_name;
172 }
173
146 } // namespace aura 174 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698