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
3 // found in the LICENSE file.
5 #include "components/view_manager/view_manager_service_impl.h"
8 #include "base/stl_util.h"
9 #include "components/view_manager/connection_manager.h"
10 #include "components/view_manager/default_access_policy.h"
11 #include "components/view_manager/display_manager.h"
12 #include "components/view_manager/server_view.h"
13 #include "components/view_manager/type_converters.h"
14 #include "components/view_manager/window_manager_access_policy.h"
15 #include "mojo/converters/geometry/geometry_type_converters.h"
16 #include "mojo/converters/input_events/input_events_type_converters.h"
17 #include "mojo/converters/surfaces/surfaces_type_converters.h"
18 #include "ui/platform_window/text_input_state.h"
23 using mojo::InterfaceRequest
;
24 using mojo::OrderDirection
;
26 using mojo::ServiceProvider
;
27 using mojo::ServiceProviderPtr
;
29 using mojo::ViewDataPtr
;
31 namespace view_manager
{
33 // Contains information needed to complete an Embed(). See description of
34 // |pending_embeds_| for more details.
35 struct ViewManagerServiceImpl::PendingEmbed
36 : public base::RefCounted
<PendingEmbed
> {
37 PendingEmbed() : embed_root(nullptr) {}
39 ViewManagerServiceImpl
* embed_root
;
41 mojo::Callback
<void(bool)> callback
;
44 friend class base::RefCounted
<PendingEmbed
>;
49 ViewManagerServiceImpl::ViewManagerServiceImpl(
50 ConnectionManager
* connection_manager
,
51 mojo::ConnectionSpecificId creator_id
,
52 const ViewId
& root_id
)
53 : connection_manager_(connection_manager
),
54 id_(connection_manager_
->GetAndAdvanceNextConnectionId()),
55 creator_id_(creator_id
),
57 is_embed_root_(false) {
58 ServerView
* view
= GetView(root_id
);
60 root_
.reset(new ViewId(root_id
));
61 if (view
->GetRoot() == view
)
62 access_policy_
.reset(new WindowManagerAccessPolicy(id_
, this));
64 access_policy_
.reset(new DefaultAccessPolicy(id_
, this));
67 ViewManagerServiceImpl::~ViewManagerServiceImpl() {
71 void ViewManagerServiceImpl::Init(mojo::ViewManagerClient
* client
,
72 mojo::ViewManagerServicePtr service_ptr
) {
75 std::vector
<const ServerView
*> to_send
;
77 GetUnknownViewsFrom(GetView(*root_
), &to_send
);
79 const ServerView
* focused_view
= connection_manager_
->GetFocusedView();
81 focused_view
= access_policy_
->GetViewForFocusChange(focused_view
);
82 const mojo::Id
focused_view_transport_id(
83 ViewIdToTransportId(focused_view
? focused_view
->id() : ViewId()));
85 client
->OnEmbed(id_
, ViewToViewData(to_send
.front()), service_ptr
.Pass(),
86 focused_view_transport_id
);
89 const ServerView
* ViewManagerServiceImpl::GetView(const ViewId
& id
) const {
90 if (id_
== id
.connection_id
) {
91 ViewMap::const_iterator i
= view_map_
.find(id
.view_id
);
92 return i
== view_map_
.end() ? NULL
: i
->second
;
94 return connection_manager_
->GetView(id
);
97 bool ViewManagerServiceImpl::IsRoot(const ViewId
& id
) const {
98 return root_
.get() && *root_
== id
;
101 void ViewManagerServiceImpl::OnWillDestroyViewManagerServiceImpl(
102 ViewManagerServiceImpl
* connection
) {
103 InvalidatePendingEmbedForConnection(connection
);
104 if (creator_id_
== connection
->id())
105 creator_id_
= kInvalidConnectionId
;
106 if (connection
->root_
&& connection
->root_
->connection_id
== id_
&&
107 view_map_
.count(connection
->root_
->view_id
) > 0) {
108 client()->OnEmbeddedAppDisconnected(
109 ViewIdToTransportId(*connection
->root_
));
111 if (root_
.get() && root_
->connection_id
== connection
->id())
115 mojo::ErrorCode
ViewManagerServiceImpl::CreateView(const ViewId
& view_id
) {
116 if (view_id
.connection_id
!= id_
)
117 return mojo::ERROR_CODE_ILLEGAL_ARGUMENT
;
118 if (view_map_
.find(view_id
.view_id
) != view_map_
.end())
119 return mojo::ERROR_CODE_VALUE_IN_USE
;
120 view_map_
[view_id
.view_id
] = connection_manager_
->CreateServerView(view_id
);
121 known_views_
.insert(ViewIdToTransportId(view_id
));
122 return mojo::ERROR_CODE_NONE
;
125 bool ViewManagerServiceImpl::AddView(const ViewId
& parent_id
,
126 const ViewId
& child_id
) {
127 ServerView
* parent
= GetView(parent_id
);
128 ServerView
* child
= GetView(child_id
);
129 if (parent
&& child
&& child
->parent() != parent
&&
130 !child
->Contains(parent
) && access_policy_
->CanAddView(parent
, child
)) {
131 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
138 std::vector
<const ServerView
*> ViewManagerServiceImpl::GetViewTree(
139 const ViewId
& view_id
) const {
140 const ServerView
* view
= GetView(view_id
);
141 std::vector
<const ServerView
*> views
;
143 GetViewTreeImpl(view
, &views
);
147 bool ViewManagerServiceImpl::SetViewVisibility(const ViewId
& view_id
,
149 ServerView
* view
= GetView(view_id
);
150 if (!view
|| view
->visible() == visible
||
151 !access_policy_
->CanChangeViewVisibility(view
)) {
154 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
155 view
->SetVisible(visible
);
159 void ViewManagerServiceImpl::EmbedAllowingReembed(
160 const ViewId
& view_id
,
161 mojo::URLRequestPtr request
,
162 const mojo::Callback
<void(bool)>& callback
) {
163 if (!CanEmbed(view_id
)) {
168 ViewManagerServiceImpl
* embed_root
= nullptr;
170 ServerView
* view
= GetView(view_id
);
171 DCHECK(view
); // CanEmbed() returns true only if |view_id| is valid.
172 if (view
->id().connection_id
== id_
) {
173 view
->set_allows_reembed(true);
175 // Only consult the embed root if the creator is doing the embed. If someone
176 // other than the creator is doing the embed they were granted embed access.
177 embed_root
= connection_manager_
->GetEmbedRoot(this);
181 PrepareForEmbed(view_id
);
182 connection_manager_
->EmbedAtView(id_
, view_id
, request
.Pass());
187 // There is an embed root. We have to query it before completing the embed.
188 scoped_refptr
<PendingEmbed
> pending_embed(new PendingEmbed
);
189 pending_embeds_
.insert(pending_embed
);
190 pending_embed
->embed_root
= embed_root
;
191 pending_embed
->view_id
= view_id
;
192 pending_embed
->callback
= callback
;
193 pending_embeds_
.insert(pending_embed
);
194 embed_root
->client()->OnEmbedForDescendant(
195 ViewIdToTransportId(view_id
), request
.Pass(),
196 base::Bind(&ViewManagerServiceImpl::OnEmbedForDescendantDone
,
197 base::Unretained(this), pending_embed
));
200 bool ViewManagerServiceImpl::Embed(const ViewId
& view_id
,
201 mojo::ViewManagerClientPtr client
) {
202 if (!client
.get() || !CanEmbed(view_id
))
204 PrepareForEmbed(view_id
);
206 connection_manager_
->EmbedAtView(id_
, view_id
, client
.Pass()));
210 void ViewManagerServiceImpl::ProcessViewBoundsChanged(
211 const ServerView
* view
,
212 const gfx::Rect
& old_bounds
,
213 const gfx::Rect
& new_bounds
,
214 bool originated_change
) {
215 if (originated_change
|| !IsViewKnown(view
))
217 client()->OnViewBoundsChanged(ViewIdToTransportId(view
->id()),
218 Rect::From(old_bounds
),
219 Rect::From(new_bounds
));
222 void ViewManagerServiceImpl::ProcessViewportMetricsChanged(
223 const mojo::ViewportMetrics
& old_metrics
,
224 const mojo::ViewportMetrics
& new_metrics
,
225 bool originated_change
) {
226 client()->OnViewViewportMetricsChanged(old_metrics
.Clone(),
227 new_metrics
.Clone());
230 void ViewManagerServiceImpl::ProcessWillChangeViewHierarchy(
231 const ServerView
* view
,
232 const ServerView
* new_parent
,
233 const ServerView
* old_parent
,
234 bool originated_change
) {
235 if (originated_change
)
238 const bool old_drawn
= view
->IsDrawn();
239 const bool new_drawn
= view
->visible() && new_parent
&& new_parent
->IsDrawn();
240 if (old_drawn
== new_drawn
)
243 NotifyDrawnStateChanged(view
, new_drawn
);
246 void ViewManagerServiceImpl::ProcessViewPropertyChanged(
247 const ServerView
* view
,
248 const std::string
& name
,
249 const std::vector
<uint8_t>* new_data
,
250 bool originated_change
) {
251 if (originated_change
)
256 data
= Array
<uint8_t>::From(*new_data
);
258 client()->OnViewSharedPropertyChanged(ViewIdToTransportId(view
->id()),
259 String(name
), data
.Pass());
262 void ViewManagerServiceImpl::ProcessViewHierarchyChanged(
263 const ServerView
* view
,
264 const ServerView
* new_parent
,
265 const ServerView
* old_parent
,
266 bool originated_change
) {
267 if (originated_change
&& !IsViewKnown(view
) && new_parent
&&
268 IsViewKnown(new_parent
)) {
269 std::vector
<const ServerView
*> unused
;
270 GetUnknownViewsFrom(view
, &unused
);
272 if (originated_change
|| connection_manager_
->is_processing_delete_view() ||
273 connection_manager_
->DidConnectionMessageClient(id_
)) {
277 if (!access_policy_
->ShouldNotifyOnHierarchyChange(
278 view
, &new_parent
, &old_parent
)) {
281 // Inform the client of any new views and update the set of views we know
283 std::vector
<const ServerView
*> to_send
;
284 if (!IsViewKnown(view
))
285 GetUnknownViewsFrom(view
, &to_send
);
286 const ViewId
new_parent_id(new_parent
? new_parent
->id() : ViewId());
287 const ViewId
old_parent_id(old_parent
? old_parent
->id() : ViewId());
288 client()->OnViewHierarchyChanged(ViewIdToTransportId(view
->id()),
289 ViewIdToTransportId(new_parent_id
),
290 ViewIdToTransportId(old_parent_id
),
291 ViewsToViewDatas(to_send
));
292 connection_manager_
->OnConnectionMessagedClient(id_
);
295 void ViewManagerServiceImpl::ProcessViewReorder(const ServerView
* view
,
296 const ServerView
* relative_view
,
297 OrderDirection direction
,
298 bool originated_change
) {
299 if (originated_change
|| !IsViewKnown(view
) || !IsViewKnown(relative_view
))
302 client()->OnViewReordered(ViewIdToTransportId(view
->id()),
303 ViewIdToTransportId(relative_view
->id()),
307 void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId
& view
,
308 bool originated_change
) {
309 if (view
.connection_id
== id_
)
310 view_map_
.erase(view
.view_id
);
312 const bool in_known
= known_views_
.erase(ViewIdToTransportId(view
)) > 0;
317 InvalidatePendingEmbedForView(view
);
319 if (originated_change
)
323 client()->OnViewDeleted(ViewIdToTransportId(view
));
324 connection_manager_
->OnConnectionMessagedClient(id_
);
328 void ViewManagerServiceImpl::ProcessWillChangeViewVisibility(
329 const ServerView
* view
,
330 bool originated_change
) {
331 if (originated_change
)
334 if (IsViewKnown(view
)) {
335 client()->OnViewVisibilityChanged(ViewIdToTransportId(view
->id()),
340 bool view_target_drawn_state
;
341 if (view
->visible()) {
342 // View is being hidden, won't be drawn.
343 view_target_drawn_state
= false;
345 // View is being shown. View will be drawn if its parent is drawn.
346 view_target_drawn_state
= view
->parent() && view
->parent()->IsDrawn();
349 NotifyDrawnStateChanged(view
, view_target_drawn_state
);
352 void ViewManagerServiceImpl::ProcessFocusChanged(
353 const ServerView
* old_focused_view
,
354 const ServerView
* new_focused_view
) {
355 const ServerView
* view
=
356 new_focused_view
? access_policy_
->GetViewForFocusChange(new_focused_view
)
358 client()->OnViewFocused(view
? ViewIdToTransportId(view
->id())
359 : ViewIdToTransportId(ViewId()));
362 bool ViewManagerServiceImpl::IsViewKnown(const ServerView
* view
) const {
363 return known_views_
.count(ViewIdToTransportId(view
->id())) > 0;
366 bool ViewManagerServiceImpl::CanReorderView(const ServerView
* view
,
367 const ServerView
* relative_view
,
368 OrderDirection direction
) const {
369 if (!view
|| !relative_view
)
372 if (!view
->parent() || view
->parent() != relative_view
->parent())
375 if (!access_policy_
->CanReorderView(view
, relative_view
, direction
))
378 std::vector
<const ServerView
*> children
= view
->parent()->GetChildren();
379 const size_t child_i
=
380 std::find(children
.begin(), children
.end(), view
) - children
.begin();
381 const size_t target_i
=
382 std::find(children
.begin(), children
.end(), relative_view
) -
384 if ((direction
== mojo::ORDER_DIRECTION_ABOVE
&& child_i
== target_i
+ 1) ||
385 (direction
== mojo::ORDER_DIRECTION_BELOW
&& child_i
+ 1 == target_i
)) {
392 bool ViewManagerServiceImpl::DeleteViewImpl(ViewManagerServiceImpl
* source
,
395 DCHECK_EQ(view
->id().connection_id
, id_
);
396 ConnectionManager::ScopedChange
change(source
, connection_manager_
, true);
401 void ViewManagerServiceImpl::GetUnknownViewsFrom(
402 const ServerView
* view
,
403 std::vector
<const ServerView
*>* views
) {
404 if (IsViewKnown(view
) || !access_policy_
->CanGetViewTree(view
))
406 views
->push_back(view
);
407 known_views_
.insert(ViewIdToTransportId(view
->id()));
408 if (!access_policy_
->CanDescendIntoViewForViewTree(view
))
410 std::vector
<const ServerView
*> children(view
->GetChildren());
411 for (size_t i
= 0 ; i
< children
.size(); ++i
)
412 GetUnknownViewsFrom(children
[i
], views
);
415 void ViewManagerServiceImpl::RemoveFromKnown(
416 const ServerView
* view
,
417 std::vector
<ServerView
*>* local_views
) {
418 if (view
->id().connection_id
== id_
) {
420 local_views
->push_back(GetView(view
->id()));
423 known_views_
.erase(ViewIdToTransportId(view
->id()));
424 std::vector
<const ServerView
*> children
= view
->GetChildren();
425 for (size_t i
= 0; i
< children
.size(); ++i
)
426 RemoveFromKnown(children
[i
], local_views
);
429 void ViewManagerServiceImpl::RemoveRoot() {
431 const ViewId
root_id(*root_
);
433 // No need to do anything if we created the view.
434 if (root_id
.connection_id
== id_
)
437 client()->OnViewDeleted(ViewIdToTransportId(root_id
));
438 connection_manager_
->OnConnectionMessagedClient(id_
);
440 // This connection no longer knows about the view. Unparent any views that
441 // were parented to views in the root.
442 std::vector
<ServerView
*> local_views
;
443 RemoveFromKnown(GetView(root_id
), &local_views
);
444 for (size_t i
= 0; i
< local_views
.size(); ++i
)
445 local_views
[i
]->parent()->Remove(local_views
[i
]);
448 Array
<ViewDataPtr
> ViewManagerServiceImpl::ViewsToViewDatas(
449 const std::vector
<const ServerView
*>& views
) {
450 Array
<ViewDataPtr
> array(views
.size());
451 for (size_t i
= 0; i
< views
.size(); ++i
)
452 array
[i
] = ViewToViewData(views
[i
]).Pass();
456 ViewDataPtr
ViewManagerServiceImpl::ViewToViewData(const ServerView
* view
) {
457 DCHECK(IsViewKnown(view
));
458 const ServerView
* parent
= view
->parent();
459 // If the parent isn't known, it means the parent is not visible to us (not
460 // in roots), and should not be sent over.
461 if (parent
&& !IsViewKnown(parent
))
463 ViewDataPtr
view_data(mojo::ViewData::New());
464 view_data
->parent_id
= ViewIdToTransportId(parent
? parent
->id() : ViewId());
465 view_data
->view_id
= ViewIdToTransportId(view
->id());
466 view_data
->bounds
= Rect::From(view
->bounds());
467 view_data
->properties
=
468 mojo::Map
<String
, Array
<uint8_t>>::From(view
->properties());
469 view_data
->visible
= view
->visible();
470 view_data
->drawn
= view
->IsDrawn();
471 view_data
->viewport_metrics
=
472 connection_manager_
->GetViewportMetricsForView(view
);
473 return view_data
.Pass();
476 void ViewManagerServiceImpl::GetViewTreeImpl(
477 const ServerView
* view
,
478 std::vector
<const ServerView
*>* views
) const {
481 if (!access_policy_
->CanGetViewTree(view
))
484 views
->push_back(view
);
486 if (!access_policy_
->CanDescendIntoViewForViewTree(view
))
489 std::vector
<const ServerView
*> children(view
->GetChildren());
490 for (size_t i
= 0 ; i
< children
.size(); ++i
)
491 GetViewTreeImpl(children
[i
], views
);
494 void ViewManagerServiceImpl::NotifyDrawnStateChanged(const ServerView
* view
,
495 bool new_drawn_value
) {
496 // Even though we don't know about view, it may be an ancestor of our root, in
497 // which case the change may effect our roots drawn state.
501 const ServerView
* root
= GetView(*root_
);
503 if (view
->Contains(root
) && (new_drawn_value
!= root
->IsDrawn())) {
504 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root
->id()),
509 void ViewManagerServiceImpl::DestroyViews() {
510 if (!view_map_
.empty()) {
511 ConnectionManager::ScopedChange
change(this, connection_manager_
, true);
512 // If we get here from the destructor we're not going to get
513 // ProcessViewDeleted(). Copy the map and delete from the copy so that we
514 // don't have to worry about whether |view_map_| changes or not.
515 ViewMap view_map_copy
;
516 view_map_
.swap(view_map_copy
);
517 STLDeleteValues(&view_map_copy
);
521 bool ViewManagerServiceImpl::CanEmbed(const ViewId
& view_id
) const {
522 const ServerView
* view
= GetView(view_id
);
523 return view
&& access_policy_
->CanEmbed(view
);
526 void ViewManagerServiceImpl::PrepareForEmbed(const ViewId
& view_id
) {
527 const ServerView
* view
= GetView(view_id
);
528 DCHECK(view
&& access_policy_
->CanEmbed(view
));
530 // Only allow a node to be the root for one connection.
531 ViewManagerServiceImpl
* existing_owner
=
532 connection_manager_
->GetConnectionWithRoot(view_id
);
534 ConnectionManager::ScopedChange
change(this, connection_manager_
, true);
535 RemoveChildrenAsPartOfEmbed(view_id
);
536 if (existing_owner
) {
537 // Never message the originating connection.
538 connection_manager_
->OnConnectionMessagedClient(id_
);
539 existing_owner
->RemoveRoot();
543 void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed(
544 const ViewId
& view_id
) {
545 ServerView
* view
= GetView(view_id
);
547 CHECK(view
->id().connection_id
== view_id
.connection_id
);
548 std::vector
<ServerView
*> children
= view
->GetChildren();
549 for (size_t i
= 0; i
< children
.size(); ++i
)
550 view
->Remove(children
[i
]);
553 void ViewManagerServiceImpl::OnEmbedForDescendantDone(
554 scoped_refptr
<PendingEmbed
> pending_embed
,
555 mojo::ViewManagerClientPtr client
) {
556 if (!pending_embeds_
.count(pending_embed
.get()))
559 const bool allow_embed
= client
.get() && CanEmbed(pending_embed
->view_id
);
561 PrepareForEmbed(pending_embed
->view_id
);
562 connection_manager_
->EmbedAtView(id_
, pending_embed
->view_id
,
565 RemovePendingEmbedAndNotifyCallback(pending_embed
.get(), allow_embed
);
568 void ViewManagerServiceImpl::InvalidatePendingEmbedForConnection(
569 ViewManagerServiceImpl
* connection
) {
570 if (pending_embeds_
.empty())
572 std::set
<scoped_refptr
<PendingEmbed
>> copy(pending_embeds_
);
573 for (auto& embed
: copy
) {
574 if (embed
->embed_root
== connection
)
575 RemovePendingEmbedAndNotifyCallback(embed
, false);
579 void ViewManagerServiceImpl::InvalidatePendingEmbedForView(
580 const ViewId
& view_id
) {
581 if (pending_embeds_
.empty())
583 std::set
<scoped_refptr
<PendingEmbed
>> copy(pending_embeds_
);
584 for (auto& embed
: copy
) {
585 if (embed
->view_id
== view_id
)
586 RemovePendingEmbedAndNotifyCallback(embed
, false);
590 void ViewManagerServiceImpl::RemovePendingEmbedAndNotifyCallback(
591 scoped_refptr
<PendingEmbed
> embed
,
593 pending_embeds_
.erase(embed
);
594 embed
->callback
.Run(success
);
597 void ViewManagerServiceImpl::CreateView(
598 Id transport_view_id
,
599 const Callback
<void(mojo::ErrorCode
)>& callback
) {
600 callback
.Run(CreateView(ViewIdFromTransportId(transport_view_id
)));
603 void ViewManagerServiceImpl::DeleteView(
604 Id transport_view_id
,
605 const Callback
<void(bool)>& callback
) {
606 ServerView
* view
= GetView(ViewIdFromTransportId(transport_view_id
));
607 bool success
= false;
608 if (view
&& access_policy_
->CanDeleteView(view
)) {
609 ViewManagerServiceImpl
* connection
=
610 connection_manager_
->GetConnection(view
->id().connection_id
);
611 success
= connection
&& connection
->DeleteViewImpl(this, view
);
613 callback
.Run(success
);
616 void ViewManagerServiceImpl::AddView(
619 const Callback
<void(bool)>& callback
) {
620 callback
.Run(AddView(ViewIdFromTransportId(parent_id
),
621 ViewIdFromTransportId(child_id
)));
624 void ViewManagerServiceImpl::RemoveViewFromParent(
626 const Callback
<void(bool)>& callback
) {
627 bool success
= false;
628 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
629 if (view
&& view
->parent() && access_policy_
->CanRemoveViewFromParent(view
)) {
631 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
632 view
->parent()->Remove(view
);
634 callback
.Run(success
);
637 void ViewManagerServiceImpl::ReorderView(Id view_id
,
639 OrderDirection direction
,
640 const Callback
<void(bool)>& callback
) {
641 bool success
= false;
642 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
643 ServerView
* relative_view
= GetView(ViewIdFromTransportId(relative_view_id
));
644 if (CanReorderView(view
, relative_view
, direction
)) {
646 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
647 view
->parent()->Reorder(view
, relative_view
, direction
);
648 connection_manager_
->ProcessViewReorder(view
, relative_view
, direction
);
650 callback
.Run(success
);
653 void ViewManagerServiceImpl::GetViewTree(
655 const Callback
<void(Array
<ViewDataPtr
>)>& callback
) {
656 std::vector
<const ServerView
*> views(
657 GetViewTree(ViewIdFromTransportId(view_id
)));
658 callback
.Run(ViewsToViewDatas(views
));
661 void ViewManagerServiceImpl::SetViewSurfaceId(
663 mojo::SurfaceIdPtr surface_id
,
664 const Callback
<void(bool)>& callback
) {
665 // TODO(sky): add coverage of not being able to set for random node.
666 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
667 if (!view
|| !access_policy_
->CanSetViewSurfaceId(view
)) {
671 view
->SetSurfaceId(surface_id
.To
<cc::SurfaceId
>());
675 void ViewManagerServiceImpl::SetViewBounds(
677 mojo::RectPtr bounds
,
678 const Callback
<void(bool)>& callback
) {
679 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
680 const bool success
= view
&& access_policy_
->CanSetViewBounds(view
);
682 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
683 view
->SetBounds(bounds
.To
<gfx::Rect
>());
685 callback
.Run(success
);
688 void ViewManagerServiceImpl::SetViewVisibility(
689 Id transport_view_id
,
691 const Callback
<void(bool)>& callback
) {
693 SetViewVisibility(ViewIdFromTransportId(transport_view_id
), visible
));
696 void ViewManagerServiceImpl::SetViewProperty(
698 const mojo::String
& name
,
699 mojo::Array
<uint8_t> value
,
700 const mojo::Callback
<void(bool)>& callback
) {
701 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
702 const bool success
= view
&& access_policy_
->CanSetViewProperties(view
);
704 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
706 if (value
.is_null()) {
707 view
->SetProperty(name
, nullptr);
709 std::vector
<uint8_t> data
= value
.To
<std::vector
<uint8_t>>();
710 view
->SetProperty(name
, &data
);
713 callback
.Run(success
);
716 void ViewManagerServiceImpl::SetViewTextInputState(
718 mojo::TextInputStatePtr state
) {
719 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
720 bool success
= view
&& access_policy_
->CanSetViewTextInputState(view
);
722 view
->SetTextInputState(state
.To
<ui::TextInputState
>());
725 void ViewManagerServiceImpl::SetImeVisibility(uint32_t view_id
,
727 mojo::TextInputStatePtr state
) {
728 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
729 bool success
= view
&& access_policy_
->CanSetViewTextInputState(view
);
731 if (!state
.is_null())
732 view
->SetTextInputState(state
.To
<ui::TextInputState
>());
733 connection_manager_
->SetImeVisibility(view
, visible
);
737 void ViewManagerServiceImpl::SetEmbedRoot() {
738 is_embed_root_
= true;
741 void ViewManagerServiceImpl::Embed(mojo::Id transport_view_id
,
742 mojo::ViewManagerClientPtr client
,
743 const mojo::Callback
<void(bool)>& callback
) {
744 callback
.Run(Embed(ViewIdFromTransportId(transport_view_id
), client
.Pass()));
747 void ViewManagerServiceImpl::EmbedAllowingReembed(
748 mojo::Id transport_view_id
,
749 mojo::URLRequestPtr request
,
750 const mojo::Callback
<void(bool)>& callback
) {
751 EmbedAllowingReembed(ViewIdFromTransportId(transport_view_id
), request
.Pass(),
755 void ViewManagerServiceImpl::SetFocus(uint32_t view_id
,
756 const SetFocusCallback
& callback
) {
757 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
758 bool success
= view
&& view
->IsDrawn() && access_policy_
->CanSetFocus(view
);
760 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
761 connection_manager_
->SetFocusedView(view
);
763 callback
.Run(success
);
766 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId
& id
) const {
770 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy(
771 const ServerView
* view
) const {
772 return IsViewKnown(view
);
775 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy(
776 const ServerView
* view
) const {
777 ViewManagerServiceImpl
* connection
=
778 connection_manager_
->GetConnectionWithRoot(view
->id());
779 return connection
&& connection
!= this;
782 bool ViewManagerServiceImpl::IsEmbedRootForAccessPolicy() {
783 return is_embed_root_
;
786 } // namespace view_manager