| 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/view_manager/view_tree_impl.h" | 5 #include "components/view_manager/view_tree_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 "components/view_manager/connection_manager.h" | 9 #include "components/view_manager/connection_manager.h" |
| 10 #include "components/view_manager/default_access_policy.h" | 10 #include "components/view_manager/default_access_policy.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 mojo::ConnectionSpecificId creator_id, | 36 mojo::ConnectionSpecificId creator_id, |
| 37 const ViewId& root_id) | 37 const ViewId& root_id) |
| 38 : connection_manager_(connection_manager), | 38 : connection_manager_(connection_manager), |
| 39 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 39 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 40 creator_id_(creator_id), | 40 creator_id_(creator_id), |
| 41 client_(nullptr), | 41 client_(nullptr), |
| 42 is_embed_root_(false) { | 42 is_embed_root_(false) { |
| 43 ServerView* view = GetView(root_id); | 43 ServerView* view = GetView(root_id); |
| 44 CHECK(view); | 44 CHECK(view); |
| 45 root_.reset(new ViewId(root_id)); | 45 root_.reset(new ViewId(root_id)); |
| 46 if (view->GetRoot() == view) | 46 if (view->GetRoot() == view) { |
| 47 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 47 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
| 48 else | 48 is_embed_root_ = true; |
| 49 } else { |
| 49 access_policy_.reset(new DefaultAccessPolicy(id_, this)); | 50 access_policy_.reset(new DefaultAccessPolicy(id_, this)); |
| 51 is_embed_root_ = (view->get_and_clear_pending_access_policy() & |
| 52 ViewTree::ACCESS_POLICY_EMBED_ROOT) != 0; |
| 53 } |
| 50 } | 54 } |
| 51 | 55 |
| 52 ViewTreeImpl::~ViewTreeImpl() { | 56 ViewTreeImpl::~ViewTreeImpl() { |
| 53 DestroyViews(); | 57 DestroyViews(); |
| 54 } | 58 } |
| 55 | 59 |
| 56 void ViewTreeImpl::Init(mojo::ViewTreeClient* client, mojo::ViewTreePtr tree) { | 60 void ViewTreeImpl::Init(mojo::ViewTreeClient* client, mojo::ViewTreePtr tree) { |
| 57 DCHECK(!client_); | 61 DCHECK(!client_); |
| 58 client_ = client; | 62 client_ = client; |
| 59 std::vector<const ServerView*> to_send; | 63 std::vector<const ServerView*> to_send; |
| 60 if (root_.get()) | 64 if (root_.get()) |
| 61 GetUnknownViewsFrom(GetView(*root_), &to_send); | 65 GetUnknownViewsFrom(GetView(*root_), &to_send); |
| 62 | 66 |
| 63 // TODO(beng): verify that host can actually be nullptr here. | 67 // TODO(beng): verify that host can actually be nullptr here. |
| 64 ViewTreeHostImpl* host = GetHost(); | 68 ViewTreeHostImpl* host = GetHost(); |
| 65 const ServerView* focused_view = host ? host->GetFocusedView() : nullptr; | 69 const ServerView* focused_view = host ? host->GetFocusedView() : nullptr; |
| 66 if (focused_view) | 70 if (focused_view) |
| 67 focused_view = access_policy_->GetViewForFocusChange(focused_view); | 71 focused_view = access_policy_->GetViewForFocusChange(focused_view); |
| 68 const mojo::Id focused_view_transport_id( | 72 const mojo::Id focused_view_transport_id( |
| 69 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); | 73 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); |
| 70 | 74 |
| 71 client->OnEmbed(id_, ViewToViewData(to_send.front()), tree.Pass(), | 75 client->OnEmbed(id_, ViewToViewData(to_send.front()), tree.Pass(), |
| 72 focused_view_transport_id); | 76 focused_view_transport_id, |
| 77 is_embed_root_ ? ViewTree::ACCESS_POLICY_EMBED_ROOT |
| 78 : ViewTree::ACCESS_POLICY_DEFAULT); |
| 73 } | 79 } |
| 74 | 80 |
| 75 const ServerView* ViewTreeImpl::GetView(const ViewId& id) const { | 81 const ServerView* ViewTreeImpl::GetView(const ViewId& id) const { |
| 76 if (id_ == id.connection_id) { | 82 if (id_ == id.connection_id) { |
| 77 ViewMap::const_iterator i = view_map_.find(id.view_id); | 83 ViewMap::const_iterator i = view_map_.find(id.view_id); |
| 78 return i == view_map_.end() ? NULL : i->second; | 84 return i == view_map_.end() ? NULL : i->second; |
| 79 } | 85 } |
| 80 return connection_manager_->GetView(id); | 86 return connection_manager_->GetView(id); |
| 81 } | 87 } |
| 82 | 88 |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 625 |
| 620 void ViewTreeImpl::SetViewTextInputState( | 626 void ViewTreeImpl::SetViewTextInputState( |
| 621 uint32_t view_id, | 627 uint32_t view_id, |
| 622 mojo::TextInputStatePtr state) { | 628 mojo::TextInputStatePtr state) { |
| 623 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 629 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 624 bool success = view && access_policy_->CanSetViewTextInputState(view); | 630 bool success = view && access_policy_->CanSetViewTextInputState(view); |
| 625 if (success) | 631 if (success) |
| 626 view->SetTextInputState(state.To<ui::TextInputState>()); | 632 view->SetTextInputState(state.To<ui::TextInputState>()); |
| 627 } | 633 } |
| 628 | 634 |
| 629 void ViewTreeImpl::SetImeVisibility(uint32_t view_id, | 635 void ViewTreeImpl::SetImeVisibility(Id transport_view_id, |
| 630 bool visible, | 636 bool visible, |
| 631 mojo::TextInputStatePtr state) { | 637 mojo::TextInputStatePtr state) { |
| 632 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 638 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
| 633 bool success = view && access_policy_->CanSetViewTextInputState(view); | 639 bool success = view && access_policy_->CanSetViewTextInputState(view); |
| 634 if (success) { | 640 if (success) { |
| 635 if (!state.is_null()) | 641 if (!state.is_null()) |
| 636 view->SetTextInputState(state.To<ui::TextInputState>()); | 642 view->SetTextInputState(state.To<ui::TextInputState>()); |
| 637 | 643 |
| 638 ViewTreeHostImpl* host = GetHost(); | 644 ViewTreeHostImpl* host = GetHost(); |
| 639 if (host) | 645 if (host) |
| 640 host->SetImeVisibility(view, visible); | 646 host->SetImeVisibility(view, visible); |
| 641 } | 647 } |
| 642 } | 648 } |
| 643 | 649 |
| 644 void ViewTreeImpl::SetEmbedRoot() { | 650 void ViewTreeImpl::SetAccessPolicy(Id transport_view_id, |
| 645 is_embed_root_ = true; | 651 uint32 policy_bitmask) { |
| 652 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| 653 ServerView* view = GetView(view_id); |
| 654 if (!view) |
| 655 return; |
| 656 |
| 657 ViewTreeImpl* existing_owner = |
| 658 connection_manager_->GetConnectionWithRoot(view_id); |
| 659 if (existing_owner) |
| 660 return; // Only allow changing the access policy when nothing is embedded. |
| 661 |
| 662 if (access_policy_->CanSetAccessPolicy(view)) |
| 663 view->set_pending_access_policy(policy_bitmask); |
| 646 } | 664 } |
| 647 | 665 |
| 648 void ViewTreeImpl::Embed(mojo::Id transport_view_id, | 666 void ViewTreeImpl::Embed(mojo::Id transport_view_id, |
| 649 mojo::ViewTreeClientPtr client, | 667 mojo::ViewTreeClientPtr client, |
| 650 const mojo::Callback<void(bool)>& callback) { | 668 const mojo::Callback<void(bool)>& callback) { |
| 651 callback.Run(Embed(ViewIdFromTransportId(transport_view_id), client.Pass())); | 669 callback.Run(Embed(ViewIdFromTransportId(transport_view_id), client.Pass())); |
| 652 } | 670 } |
| 653 | 671 |
| 654 void ViewTreeImpl::SetFocus(uint32_t view_id) { | 672 void ViewTreeImpl::SetFocus(uint32_t view_id) { |
| 655 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 673 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 676 ViewTreeImpl* connection = | 694 ViewTreeImpl* connection = |
| 677 connection_manager_->GetConnectionWithRoot(view->id()); | 695 connection_manager_->GetConnectionWithRoot(view->id()); |
| 678 return connection && connection != this; | 696 return connection && connection != this; |
| 679 } | 697 } |
| 680 | 698 |
| 681 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { | 699 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { |
| 682 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); | 700 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); |
| 683 } | 701 } |
| 684 | 702 |
| 685 } // namespace view_manager | 703 } // namespace view_manager |
| OLD | NEW |