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 "services/view_manager/view_manager_service_impl.h" | 5 #include "services/view_manager/view_manager_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 ServerView* view = GetView(view_id); | 133 ServerView* view = GetView(view_id); |
134 if (!view || view->visible() == visible || | 134 if (!view || view->visible() == visible || |
135 !access_policy_->CanChangeViewVisibility(view)) { | 135 !access_policy_->CanChangeViewVisibility(view)) { |
136 return false; | 136 return false; |
137 } | 137 } |
138 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 138 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
139 view->SetVisible(visible); | 139 view->SetVisible(visible); |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
143 bool ViewManagerServiceImpl::Embed(const std::string& url, | 143 bool ViewManagerServiceImpl::EmbedUrl( |
144 const ViewId& view_id, | 144 const std::string& url, |
145 InterfaceRequest<ServiceProvider> services, | 145 const ViewId& view_id, |
146 ServiceProviderPtr exposed_services) { | 146 InterfaceRequest<ServiceProvider> services, |
147 const ServerView* view = GetView(view_id); | 147 ServiceProviderPtr exposed_services) { |
148 if (!view || !access_policy_->CanEmbed(view)) | 148 if (!PrepareForEmbed(view_id)) |
149 return false; | 149 return false; |
150 | |
151 // Only allow a node to be the root for one connection. | |
152 ViewManagerServiceImpl* existing_owner = | |
153 connection_manager_->GetConnectionWithRoot(view_id); | |
154 | |
155 ConnectionManager::ScopedChange change(this, connection_manager_, true); | |
156 RemoveChildrenAsPartOfEmbed(view_id); | |
157 if (existing_owner) { | |
158 // Never message the originating connection. | |
159 connection_manager_->OnConnectionMessagedClient(id_); | |
160 existing_owner->RemoveRoot(); | |
161 } | |
162 connection_manager_->EmbedAtView(id_, url, view_id, services.Pass(), | 150 connection_manager_->EmbedAtView(id_, url, view_id, services.Pass(), |
163 exposed_services.Pass()); | 151 exposed_services.Pass()); |
164 return true; | 152 return true; |
165 } | 153 } |
166 | 154 |
| 155 bool ViewManagerServiceImpl::Embed(const ViewId& view_id, |
| 156 mojo::ViewManagerClientPtr client) { |
| 157 if (!client.get() || !PrepareForEmbed(view_id)) |
| 158 return false; |
| 159 connection_manager_->EmbedAtView(id_, view_id, client.Pass()); |
| 160 return true; |
| 161 } |
| 162 |
167 void ViewManagerServiceImpl::ProcessViewBoundsChanged( | 163 void ViewManagerServiceImpl::ProcessViewBoundsChanged( |
168 const ServerView* view, | 164 const ServerView* view, |
169 const gfx::Rect& old_bounds, | 165 const gfx::Rect& old_bounds, |
170 const gfx::Rect& new_bounds, | 166 const gfx::Rect& new_bounds, |
171 bool originated_change) { | 167 bool originated_change) { |
172 if (originated_change || !IsViewKnown(view)) | 168 if (originated_change || !IsViewKnown(view)) |
173 return; | 169 return; |
174 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), | 170 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), |
175 Rect::From(old_bounds), | 171 Rect::From(old_bounds), |
176 Rect::From(new_bounds)); | 172 Rect::From(new_bounds)); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 ConnectionManager::ScopedChange change(this, connection_manager_, true); | 465 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
470 // If we get here from the destructor we're not going to get | 466 // If we get here from the destructor we're not going to get |
471 // ProcessViewDeleted(). Copy the map and delete from the copy so that we | 467 // ProcessViewDeleted(). Copy the map and delete from the copy so that we |
472 // don't have to worry about whether |view_map_| changes or not. | 468 // don't have to worry about whether |view_map_| changes or not. |
473 ViewMap view_map_copy; | 469 ViewMap view_map_copy; |
474 view_map_.swap(view_map_copy); | 470 view_map_.swap(view_map_copy); |
475 STLDeleteValues(&view_map_copy); | 471 STLDeleteValues(&view_map_copy); |
476 } | 472 } |
477 } | 473 } |
478 | 474 |
| 475 bool ViewManagerServiceImpl::PrepareForEmbed(const ViewId& view_id) { |
| 476 const ServerView* view = GetView(view_id); |
| 477 if (!view || !access_policy_->CanEmbed(view)) |
| 478 return false; |
| 479 |
| 480 // Only allow a node to be the root for one connection. |
| 481 ViewManagerServiceImpl* existing_owner = |
| 482 connection_manager_->GetConnectionWithRoot(view_id); |
| 483 |
| 484 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
| 485 RemoveChildrenAsPartOfEmbed(view_id); |
| 486 if (existing_owner) { |
| 487 // Never message the originating connection. |
| 488 connection_manager_->OnConnectionMessagedClient(id_); |
| 489 existing_owner->RemoveRoot(); |
| 490 } |
| 491 return true; |
| 492 } |
| 493 |
479 void ViewManagerServiceImpl::CreateView( | 494 void ViewManagerServiceImpl::CreateView( |
480 Id transport_view_id, | 495 Id transport_view_id, |
481 const Callback<void(mojo::ErrorCode)>& callback) { | 496 const Callback<void(mojo::ErrorCode)>& callback) { |
482 callback.Run(CreateView(ViewIdFromTransportId(transport_view_id))); | 497 callback.Run(CreateView(ViewIdFromTransportId(transport_view_id))); |
483 } | 498 } |
484 | 499 |
485 void ViewManagerServiceImpl::DeleteView( | 500 void ViewManagerServiceImpl::DeleteView( |
486 Id transport_view_id, | 501 Id transport_view_id, |
487 const Callback<void(bool)>& callback) { | 502 const Callback<void(bool)>& callback) { |
488 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 503 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 if (value.is_null()) { | 603 if (value.is_null()) { |
589 view->SetProperty(name, nullptr); | 604 view->SetProperty(name, nullptr); |
590 } else { | 605 } else { |
591 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); | 606 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); |
592 view->SetProperty(name, &data); | 607 view->SetProperty(name, &data); |
593 } | 608 } |
594 } | 609 } |
595 callback.Run(success); | 610 callback.Run(success); |
596 } | 611 } |
597 | 612 |
598 void ViewManagerServiceImpl::Embed(const String& url, | 613 void ViewManagerServiceImpl::EmbedUrl( |
599 Id transport_view_id, | 614 const String& url, |
600 InterfaceRequest<ServiceProvider> services, | 615 Id transport_view_id, |
601 ServiceProviderPtr exposed_services, | 616 InterfaceRequest<ServiceProvider> services, |
602 const Callback<void(bool)>& callback) { | 617 ServiceProviderPtr exposed_services, |
603 callback.Run(Embed(url.To<std::string>(), | 618 const Callback<void(bool)>& callback) { |
604 ViewIdFromTransportId(transport_view_id), services.Pass(), | 619 callback.Run(EmbedUrl(url.To<std::string>(), |
605 exposed_services.Pass())); | 620 ViewIdFromTransportId(transport_view_id), |
| 621 services.Pass(), exposed_services.Pass())); |
| 622 } |
| 623 |
| 624 void ViewManagerServiceImpl::Embed(mojo::Id transport_view_id, |
| 625 mojo::ViewManagerClientPtr client, |
| 626 const mojo::Callback<void(bool)>& callback) { |
| 627 callback.Run(Embed(ViewIdFromTransportId(transport_view_id), client.Pass())); |
606 } | 628 } |
607 | 629 |
608 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId& id) const { | 630 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId& id) const { |
609 return IsRoot(id); | 631 return IsRoot(id); |
610 } | 632 } |
611 | 633 |
612 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( | 634 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( |
613 const ServerView* view) const { | 635 const ServerView* view) const { |
614 return IsViewKnown(view); | 636 return IsViewKnown(view); |
615 } | 637 } |
616 | 638 |
617 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 639 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
618 const ServerView* view) const { | 640 const ServerView* view) const { |
619 ViewManagerServiceImpl* connection = | 641 ViewManagerServiceImpl* connection = |
620 connection_manager_->GetConnectionWithRoot(view->id()); | 642 connection_manager_->GetConnectionWithRoot(view->id()); |
621 return connection && connection != this; | 643 return connection && connection != this; |
622 } | 644 } |
623 | 645 |
624 } // namespace view_manager | 646 } // namespace view_manager |
OLD | NEW |