| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/mus/ws/connection_manager.h" | 5 #include "components/mus/ws/connection_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/mus/ws/client_connection.h" | 9 #include "components/mus/ws/client_connection.h" |
| 10 #include "components/mus/ws/connection_manager_delegate.h" | 10 #include "components/mus/ws/connection_manager_delegate.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ConnectionManager::OnHostConnectionClosed( | 105 void ConnectionManager::OnHostConnectionClosed( |
| 106 ViewTreeHostConnection* connection) { | 106 ViewTreeHostConnection* connection) { |
| 107 auto it = host_connection_map_.find(connection->view_tree_host()); | 107 auto it = host_connection_map_.find(connection->view_tree_host()); |
| 108 DCHECK(it != host_connection_map_.end()); | 108 DCHECK(it != host_connection_map_.end()); |
| 109 | 109 |
| 110 // Get the ClientConnection by ViewTreeImpl ID. | 110 // Get the ClientConnection by ViewTreeImpl ID. |
| 111 ConnectionMap::iterator service_connection_it = | 111 ConnectionMap::iterator service_connection_it = |
| 112 connection_map_.find(it->first->GetViewTree()->id()); | 112 connection_map_.find(it->first->GetWindowTree()->id()); |
| 113 DCHECK(service_connection_it != connection_map_.end()); | 113 DCHECK(service_connection_it != connection_map_.end()); |
| 114 | 114 |
| 115 // Tear down the associated ViewTree connection. | 115 // Tear down the associated ViewTree connection. |
| 116 // TODO(fsamuel): I don't think this is quite right, we should tear down all | 116 // TODO(fsamuel): I don't think this is quite right, we should tear down all |
| 117 // connections within the root's viewport. We should probably employ an | 117 // connections within the root's viewport. We should probably employ an |
| 118 // observer pattern to do this. Each ViewTreeImpl should track its | 118 // observer pattern to do this. Each ViewTreeImpl should track its |
| 119 // parent's lifetime. | 119 // parent's lifetime. |
| 120 host_connection_map_.erase(it); | 120 host_connection_map_.erase(it); |
| 121 OnConnectionError(service_connection_it->second); | 121 OnConnectionError(service_connection_it->second); |
| 122 | 122 |
| 123 // If we have no more roots left, let the app know so it can terminate. | 123 // If we have no more roots left, let the app know so it can terminate. |
| 124 if (!host_connection_map_.size()) | 124 if (!host_connection_map_.size()) |
| 125 delegate_->OnNoMoreRootConnections(); | 125 delegate_->OnNoMoreRootConnections(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ConnectionManager::EmbedAtView(ConnectionSpecificId creator_id, | 128 void ConnectionManager::EmbedAtView(ConnectionSpecificId creator_id, |
| 129 const ViewId& view_id, | 129 const ViewId& view_id, |
| 130 uint32_t policy_bitmask, | 130 uint32_t policy_bitmask, |
| 131 mojo::URLRequestPtr request) { | 131 mojo::URLRequestPtr request) { |
| 132 mojo::ViewTreePtr service_ptr; | 132 mojom::WindowTreePtr service_ptr; |
| 133 ClientConnection* client_connection = | 133 ClientConnection* client_connection = |
| 134 delegate_->CreateClientConnectionForEmbedAtView( | 134 delegate_->CreateClientConnectionForEmbedAtView( |
| 135 this, GetProxy(&service_ptr), creator_id, request.Pass(), view_id, | 135 this, GetProxy(&service_ptr), creator_id, request.Pass(), view_id, |
| 136 policy_bitmask); | 136 policy_bitmask); |
| 137 AddConnection(client_connection); | 137 AddConnection(client_connection); |
| 138 client_connection->service()->Init(client_connection->client(), | 138 client_connection->service()->Init(client_connection->client(), |
| 139 service_ptr.Pass()); | 139 service_ptr.Pass()); |
| 140 OnConnectionMessagedClient(client_connection->service()->id()); | 140 OnConnectionMessagedClient(client_connection->service()->id()); |
| 141 } | 141 } |
| 142 | 142 |
| 143 ViewTreeImpl* ConnectionManager::EmbedAtView(ConnectionSpecificId creator_id, | 143 ViewTreeImpl* ConnectionManager::EmbedAtView( |
| 144 const ViewId& view_id, | 144 ConnectionSpecificId creator_id, |
| 145 uint32_t policy_bitmask, | 145 const ViewId& view_id, |
| 146 mojo::ViewTreeClientPtr client) { | 146 uint32_t policy_bitmask, |
| 147 mojo::ViewTreePtr service_ptr; | 147 mojom::WindowTreeClientPtr client) { |
| 148 mojom::WindowTreePtr service_ptr; |
| 148 ClientConnection* client_connection = | 149 ClientConnection* client_connection = |
| 149 delegate_->CreateClientConnectionForEmbedAtView( | 150 delegate_->CreateClientConnectionForEmbedAtView( |
| 150 this, GetProxy(&service_ptr), creator_id, view_id, policy_bitmask, | 151 this, GetProxy(&service_ptr), creator_id, view_id, policy_bitmask, |
| 151 client.Pass()); | 152 client.Pass()); |
| 152 AddConnection(client_connection); | 153 AddConnection(client_connection); |
| 153 client_connection->service()->Init(client_connection->client(), | 154 client_connection->service()->Init(client_connection->client(), |
| 154 service_ptr.Pass()); | 155 service_ptr.Pass()); |
| 155 OnConnectionMessagedClient(client_connection->service()->id()); | 156 OnConnectionMessagedClient(client_connection->service()->id()); |
| 156 | 157 |
| 157 return client_connection->service(); | 158 return client_connection->service(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 void ConnectionManager::OnConnectionMessagedClient(ConnectionSpecificId id) { | 192 void ConnectionManager::OnConnectionMessagedClient(ConnectionSpecificId id) { |
| 192 if (current_change_) | 193 if (current_change_) |
| 193 current_change_->MarkConnectionAsMessaged(id); | 194 current_change_->MarkConnectionAsMessaged(id); |
| 194 } | 195 } |
| 195 | 196 |
| 196 bool ConnectionManager::DidConnectionMessageClient( | 197 bool ConnectionManager::DidConnectionMessageClient( |
| 197 ConnectionSpecificId id) const { | 198 ConnectionSpecificId id) const { |
| 198 return current_change_ && current_change_->DidMessageConnection(id); | 199 return current_change_ && current_change_->DidMessageConnection(id); |
| 199 } | 200 } |
| 200 | 201 |
| 201 mojo::ViewportMetricsPtr ConnectionManager::GetViewportMetricsForView( | 202 mojom::ViewportMetricsPtr ConnectionManager::GetViewportMetricsForView( |
| 202 const ServerView* view) { | 203 const ServerView* view) { |
| 203 ViewTreeHostImpl* host = GetViewTreeHostByView(view); | 204 ViewTreeHostImpl* host = GetWindowTreeHostByView(view); |
| 204 if (host) | 205 if (host) |
| 205 return host->GetViewportMetrics().Clone(); | 206 return host->GetViewportMetrics().Clone(); |
| 206 | 207 |
| 207 if (!host_connection_map_.empty()) | 208 if (!host_connection_map_.empty()) |
| 208 return host_connection_map_.begin()->first->GetViewportMetrics().Clone(); | 209 return host_connection_map_.begin()->first->GetViewportMetrics().Clone(); |
| 209 | 210 |
| 210 mojo::ViewportMetricsPtr metrics = mojo::ViewportMetrics::New(); | 211 mojom::ViewportMetricsPtr metrics = mojom::ViewportMetrics::New(); |
| 211 metrics->size_in_pixels = mojo::Size::New(); | 212 metrics->size_in_pixels = mojo::Size::New(); |
| 212 return metrics.Pass(); | 213 return metrics.Pass(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 const ViewTreeImpl* ConnectionManager::GetConnectionWithRoot( | 216 const ViewTreeImpl* ConnectionManager::GetConnectionWithRoot( |
| 216 const ViewId& id) const { | 217 const ViewId& id) const { |
| 217 for (auto& pair : connection_map_) { | 218 for (auto& pair : connection_map_) { |
| 218 if (pair.second->service()->IsRoot(id)) | 219 if (pair.second->service()->IsRoot(id)) |
| 219 return pair.second->service(); | 220 return pair.second->service(); |
| 220 } | 221 } |
| 221 return nullptr; | 222 return nullptr; |
| 222 } | 223 } |
| 223 | 224 |
| 224 ViewTreeHostImpl* ConnectionManager::GetViewTreeHostByView( | 225 ViewTreeHostImpl* ConnectionManager::GetWindowTreeHostByView( |
| 225 const ServerView* view) { | 226 const ServerView* view) { |
| 226 return const_cast<ViewTreeHostImpl*>( | 227 return const_cast<ViewTreeHostImpl*>( |
| 227 static_cast<const ConnectionManager*>(this)->GetViewTreeHostByView(view)); | 228 static_cast<const ConnectionManager*>(this) |
| 229 ->GetWindowTreeHostByView(view)); |
| 228 } | 230 } |
| 229 | 231 |
| 230 const ViewTreeHostImpl* ConnectionManager::GetViewTreeHostByView( | 232 const ViewTreeHostImpl* ConnectionManager::GetWindowTreeHostByView( |
| 231 const ServerView* view) const { | 233 const ServerView* view) const { |
| 232 while (view && view->parent()) | 234 while (view && view->parent()) |
| 233 view = view->parent(); | 235 view = view->parent(); |
| 234 for (auto& pair : host_connection_map_) { | 236 for (auto& pair : host_connection_map_) { |
| 235 if (view == pair.first->root_view()) | 237 if (view == pair.first->root_view()) |
| 236 return pair.first; | 238 return pair.first; |
| 237 } | 239 } |
| 238 return nullptr; | 240 return nullptr; |
| 239 } | 241 } |
| 240 | 242 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 const ServerView* old_parent) { | 289 const ServerView* old_parent) { |
| 288 for (auto& pair : connection_map_) { | 290 for (auto& pair : connection_map_) { |
| 289 pair.second->service()->ProcessViewHierarchyChanged( | 291 pair.second->service()->ProcessViewHierarchyChanged( |
| 290 view, new_parent, old_parent, IsChangeSource(pair.first)); | 292 view, new_parent, old_parent, IsChangeSource(pair.first)); |
| 291 } | 293 } |
| 292 } | 294 } |
| 293 | 295 |
| 294 void ConnectionManager::ProcessViewReorder( | 296 void ConnectionManager::ProcessViewReorder( |
| 295 const ServerView* view, | 297 const ServerView* view, |
| 296 const ServerView* relative_view, | 298 const ServerView* relative_view, |
| 297 const mojo::OrderDirection direction) { | 299 const mojom::OrderDirection direction) { |
| 298 for (auto& pair : connection_map_) { | 300 for (auto& pair : connection_map_) { |
| 299 pair.second->service()->ProcessViewReorder(view, relative_view, direction, | 301 pair.second->service()->ProcessViewReorder(view, relative_view, direction, |
| 300 IsChangeSource(pair.first)); | 302 IsChangeSource(pair.first)); |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 304 void ConnectionManager::ProcessViewDeleted(const ViewId& view) { | 306 void ConnectionManager::ProcessViewDeleted(const ViewId& view) { |
| 305 for (auto& pair : connection_map_) { | 307 for (auto& pair : connection_map_) { |
| 306 pair.second->service()->ProcessViewDeleted(view, | 308 pair.second->service()->ProcessViewDeleted(view, |
| 307 IsChangeSource(pair.first)); | 309 IsChangeSource(pair.first)); |
| 308 } | 310 } |
| 309 } | 311 } |
| 310 | 312 |
| 311 void ConnectionManager::ProcessViewportMetricsChanged( | 313 void ConnectionManager::ProcessViewportMetricsChanged( |
| 312 const mojo::ViewportMetrics& old_metrics, | 314 const mojom::ViewportMetrics& old_metrics, |
| 313 const mojo::ViewportMetrics& new_metrics) { | 315 const mojom::ViewportMetrics& new_metrics) { |
| 314 for (auto& pair : connection_map_) { | 316 for (auto& pair : connection_map_) { |
| 315 pair.second->service()->ProcessViewportMetricsChanged( | 317 pair.second->service()->ProcessViewportMetricsChanged( |
| 316 old_metrics, new_metrics, IsChangeSource(pair.first)); | 318 old_metrics, new_metrics, IsChangeSource(pair.first)); |
| 317 } | 319 } |
| 318 } | 320 } |
| 319 | 321 |
| 320 void ConnectionManager::PrepareForChange(ScopedChange* change) { | 322 void ConnectionManager::PrepareForChange(ScopedChange* change) { |
| 321 // Should only ever have one change in flight. | 323 // Should only ever have one change in flight. |
| 322 CHECK(!current_change_); | 324 CHECK(!current_change_); |
| 323 current_change_ = change; | 325 current_change_ = change; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 337 SurfacesState* ConnectionManager::GetSurfacesState() { | 339 SurfacesState* ConnectionManager::GetSurfacesState() { |
| 338 return surfaces_state_.get(); | 340 return surfaces_state_.get(); |
| 339 } | 341 } |
| 340 | 342 |
| 341 void ConnectionManager::OnScheduleViewPaint(const ServerView* view) { | 343 void ConnectionManager::OnScheduleViewPaint(const ServerView* view) { |
| 342 if (!in_destructor_) | 344 if (!in_destructor_) |
| 343 SchedulePaint(view, gfx::Rect(view->bounds().size())); | 345 SchedulePaint(view, gfx::Rect(view->bounds().size())); |
| 344 } | 346 } |
| 345 | 347 |
| 346 const ServerView* ConnectionManager::GetRootView(const ServerView* view) const { | 348 const ServerView* ConnectionManager::GetRootView(const ServerView* view) const { |
| 347 const ViewTreeHostImpl* host = GetViewTreeHostByView(view); | 349 const ViewTreeHostImpl* host = GetWindowTreeHostByView(view); |
| 348 return host ? host->root_view() : nullptr; | 350 return host ? host->root_view() : nullptr; |
| 349 } | 351 } |
| 350 | 352 |
| 351 void ConnectionManager::OnViewDestroyed(ServerView* view) { | 353 void ConnectionManager::OnViewDestroyed(ServerView* view) { |
| 352 if (!in_destructor_) | 354 if (!in_destructor_) |
| 353 ProcessViewDeleted(view->id()); | 355 ProcessViewDeleted(view->id()); |
| 354 } | 356 } |
| 355 | 357 |
| 356 void ConnectionManager::OnWillChangeViewHierarchy(ServerView* view, | 358 void ConnectionManager::OnWillChangeViewHierarchy(ServerView* view, |
| 357 ServerView* new_parent, | 359 ServerView* new_parent, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 const gfx::Rect& old_client_area, | 399 const gfx::Rect& old_client_area, |
| 398 const gfx::Rect& new_client_area) { | 400 const gfx::Rect& new_client_area) { |
| 399 if (in_destructor_) | 401 if (in_destructor_) |
| 400 return; | 402 return; |
| 401 | 403 |
| 402 ProcessClientAreaChanged(window, old_client_area, new_client_area); | 404 ProcessClientAreaChanged(window, old_client_area, new_client_area); |
| 403 } | 405 } |
| 404 | 406 |
| 405 void ConnectionManager::OnViewReordered(ServerView* view, | 407 void ConnectionManager::OnViewReordered(ServerView* view, |
| 406 ServerView* relative, | 408 ServerView* relative, |
| 407 mojo::OrderDirection direction) { | 409 mojom::OrderDirection direction) { |
| 408 if (!in_destructor_) | 410 if (!in_destructor_) |
| 409 SchedulePaint(view, gfx::Rect(view->bounds().size())); | 411 SchedulePaint(view, gfx::Rect(view->bounds().size())); |
| 410 } | 412 } |
| 411 | 413 |
| 412 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { | 414 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { |
| 413 if (in_destructor_) | 415 if (in_destructor_) |
| 414 return; | 416 return; |
| 415 | 417 |
| 416 // Need to repaint if the view was drawn (which means it's in the process of | 418 // Need to repaint if the view was drawn (which means it's in the process of |
| 417 // hiding) or the view is transitioning to drawn. | 419 // hiding) or the view is transitioning to drawn. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 432 const std::vector<uint8_t>* new_data) { | 434 const std::vector<uint8_t>* new_data) { |
| 433 for (auto& pair : connection_map_) { | 435 for (auto& pair : connection_map_) { |
| 434 pair.second->service()->ProcessViewPropertyChanged( | 436 pair.second->service()->ProcessViewPropertyChanged( |
| 435 view, name, new_data, IsChangeSource(pair.first)); | 437 view, name, new_data, IsChangeSource(pair.first)); |
| 436 } | 438 } |
| 437 } | 439 } |
| 438 | 440 |
| 439 void ConnectionManager::OnViewTextInputStateChanged( | 441 void ConnectionManager::OnViewTextInputStateChanged( |
| 440 ServerView* view, | 442 ServerView* view, |
| 441 const ui::TextInputState& state) { | 443 const ui::TextInputState& state) { |
| 442 ViewTreeHostImpl* host = GetViewTreeHostByView(view); | 444 ViewTreeHostImpl* host = GetWindowTreeHostByView(view); |
| 443 host->UpdateTextInputState(view, state); | 445 host->UpdateTextInputState(view, state); |
| 444 } | 446 } |
| 445 | 447 |
| 446 } // namespace mus | 448 } // namespace mus |
| OLD | NEW |