Chromium Code Reviews| 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 "mojo/services/view_manager/view_manager_service_impl.h" | 5 #include "mojo/services/view_manager/view_manager_service_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 10 #include "mojo/services/view_manager/connection_manager.h" | 10 #include "mojo/services/view_manager/connection_manager.h" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 const Callback<void(bool)>& callback) { | 457 const Callback<void(bool)>& callback) { |
| 458 InterfaceRequest<ServiceProvider> spir; | 458 InterfaceRequest<ServiceProvider> spir; |
| 459 spir.Bind(service_provider.PassMessagePipe()); | 459 spir.Bind(service_provider.PassMessagePipe()); |
| 460 | 460 |
| 461 if (ViewIdFromTransportId(transport_view_id) == InvalidViewId()) { | 461 if (ViewIdFromTransportId(transport_view_id) == InvalidViewId()) { |
| 462 connection_manager_->EmbedRoot(url, spir.Pass()); | 462 connection_manager_->EmbedRoot(url, spir.Pass()); |
| 463 callback.Run(true); | 463 callback.Run(true); |
| 464 return; | 464 return; |
| 465 } | 465 } |
| 466 const ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 466 const ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
| 467 bool success = view && access_policy_->CanEmbed(view); | 467 if (!view && access_policy_->CanEmbed(view)) { |
|
sky
2014/09/02 15:47:15
Shouldn't this be:
if (!view || !...CanEmbed(view
Aaron Boodman
2014/09/02 19:10:44
Done.
| |
| 468 if (success) { | 468 callback.Run(false); |
| 469 // Only allow a view to be the root for one connection. | 469 return; |
| 470 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | |
| 471 ViewManagerServiceImpl* connection_by_url = | |
| 472 connection_manager_->GetConnectionByCreator(id_, url.To<std::string>()); | |
| 473 ViewManagerServiceImpl* connection_with_view_as_root = | |
| 474 connection_manager_->GetConnectionWithRoot(view_id); | |
| 475 if ((connection_by_url != connection_with_view_as_root || | |
| 476 (!connection_by_url && !connection_with_view_as_root)) && | |
| 477 (!connection_by_url || !connection_by_url->HasRoot(view_id))) { | |
| 478 ConnectionManager::ScopedChange change(this, connection_manager_, true); | |
| 479 RemoveChildrenAsPartOfEmbed(view_id); | |
| 480 // Never message the originating connection. | |
| 481 connection_manager_->OnConnectionMessagedClient(id_); | |
| 482 if (connection_with_view_as_root) | |
| 483 connection_with_view_as_root->RemoveRoot(view_id); | |
|
sky
2014/09/02 15:47:16
You should be able to get rid of AddRoot now.
Also
Aaron Boodman
2014/09/02 19:10:44
Done.
| |
| 484 if (connection_by_url) { | |
| 485 connection_by_url->AddRoot(view_id, spir.Pass()); | |
| 486 } else { | |
| 487 connection_manager_->Embed(id_, url, transport_view_id, spir.Pass()); | |
| 488 } | |
| 489 } else { | |
| 490 success = false; | |
| 491 } | |
| 492 } | 470 } |
| 493 callback.Run(success); | 471 |
| 472 // Only allow a node to be the root for one connection. | |
|
Ben Goodger (Google)
2014/09/02 20:50:14
I think this is a good simplification. I will pond
| |
| 473 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | |
| 474 ViewManagerServiceImpl* existing_owner = | |
| 475 connection_manager_->GetConnectionWithRoot(view_id); | |
| 476 | |
| 477 ConnectionManager::ScopedChange change(this, connection_manager_, true); | |
| 478 if (existing_owner) { | |
| 479 RemoveChildrenAsPartOfEmbed(view_id); | |
| 480 // Never message the originating connection. | |
| 481 connection_manager_->OnConnectionMessagedClient(id_); | |
| 482 existing_owner->RemoveRoot(view_id); | |
| 483 } | |
| 484 connection_manager_->Embed(id_, url, transport_view_id, spir.Pass()); | |
| 485 callback.Run(true); | |
| 494 } | 486 } |
| 495 | 487 |
| 496 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, | 488 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, |
| 497 EventPtr event) { | 489 EventPtr event) { |
| 498 // We only allow the WM to dispatch events. At some point this function will | 490 // We only allow the WM to dispatch events. At some point this function will |
| 499 // move to a separate interface and the check can go away. | 491 // move to a separate interface and the check can go away. |
| 500 if (id_ != kWindowManagerConnection) | 492 if (id_ != kWindowManagerConnection) |
| 501 return; | 493 return; |
| 502 | 494 |
| 503 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | 495 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 | 533 |
| 542 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 534 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
| 543 const ServerView* view) const { | 535 const ServerView* view) const { |
| 544 ViewManagerServiceImpl* connection = | 536 ViewManagerServiceImpl* connection = |
| 545 connection_manager_->GetConnectionWithRoot(view->id()); | 537 connection_manager_->GetConnectionWithRoot(view->id()); |
| 546 return connection && connection != this; | 538 return connection && connection != this; |
| 547 } | 539 } |
| 548 | 540 |
| 549 } // namespace service | 541 } // namespace service |
| 550 } // namespace mojo | 542 } // namespace mojo |
| OLD | NEW |