| 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 "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" |
| 11 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 11 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 12 #include "mojo/services/view_manager/connection_manager.h" | 12 #include "mojo/services/view_manager/connection_manager.h" |
| 13 #include "mojo/services/view_manager/default_access_policy.h" | 13 #include "mojo/services/view_manager/default_access_policy.h" |
| 14 #include "mojo/services/view_manager/server_view.h" | 14 #include "mojo/services/view_manager/server_view.h" |
| 15 #include "mojo/services/view_manager/window_manager_access_policy.h" | 15 #include "mojo/services/view_manager/window_manager_access_policy.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace service { | 18 namespace service { |
| 19 | 19 |
| 20 ViewManagerServiceImpl::ViewManagerServiceImpl( | 20 ViewManagerServiceImpl::ViewManagerServiceImpl( |
| 21 ConnectionManager* connection_manager, | 21 ConnectionManager* connection_manager, |
| 22 ConnectionSpecificId creator_id, | 22 ConnectionSpecificId creator_id, |
| 23 const std::string& creator_url, | 23 const std::string& creator_url, |
| 24 const std::string& url, | 24 const std::string& url, |
| 25 const ViewId& root_id) | 25 const ViewId& root_id) |
| 26 : connection_manager_(connection_manager), | 26 : connection_manager_(connection_manager), |
| 27 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 27 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 28 url_(url), | 28 url_(url), |
| 29 creator_id_(creator_id), | 29 creator_id_(creator_id), |
| 30 creator_url_(creator_url) { | 30 creator_url_(creator_url), |
| 31 client_(nullptr) { |
| 31 CHECK(GetView(root_id)); | 32 CHECK(GetView(root_id)); |
| 32 root_.reset(new ViewId(root_id)); | 33 root_.reset(new ViewId(root_id)); |
| 33 if (root_id == RootViewId()) | 34 if (root_id == RootViewId()) |
| 34 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 35 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
| 35 else | 36 else |
| 36 access_policy_.reset(new DefaultAccessPolicy(id_, this)); | 37 access_policy_.reset(new DefaultAccessPolicy(id_, this)); |
| 37 } | 38 } |
| 38 | 39 |
| 39 ViewManagerServiceImpl::~ViewManagerServiceImpl() { | 40 ViewManagerServiceImpl::~ViewManagerServiceImpl() { |
| 40 DestroyViews(); | 41 DestroyViews(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void ViewManagerServiceImpl::Init( | 44 void ViewManagerServiceImpl::Init( |
| 45 ViewManagerClient* client, |
| 44 InterfaceRequest<ServiceProvider> service_provider) { | 46 InterfaceRequest<ServiceProvider> service_provider) { |
| 47 DCHECK(!client_); |
| 48 client_ = client; |
| 45 std::vector<const ServerView*> to_send; | 49 std::vector<const ServerView*> to_send; |
| 46 if (root_.get()) | 50 if (root_.get()) |
| 47 GetUnknownViewsFrom(GetView(*root_), &to_send); | 51 GetUnknownViewsFrom(GetView(*root_), &to_send); |
| 48 | 52 |
| 49 MessagePipe pipe; | 53 MessagePipe pipe; |
| 50 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient( | 54 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient( |
| 51 id_, pipe.handle1.Pass()); | 55 id_, pipe.handle1.Pass()); |
| 52 client()->OnEmbed(id_, | 56 client->OnEmbed(id_, creator_url_, ViewToViewData(to_send.front()), |
| 53 creator_url_, | 57 service_provider.Pass(), pipe.handle0.Pass()); |
| 54 ViewToViewData(to_send.front()), | |
| 55 service_provider.Pass(), | |
| 56 pipe.handle0.Pass()); | |
| 57 } | 58 } |
| 58 | 59 |
| 59 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { | 60 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { |
| 60 if (id_ == id.connection_id) { | 61 if (id_ == id.connection_id) { |
| 61 ViewMap::const_iterator i = view_map_.find(id.view_id); | 62 ViewMap::const_iterator i = view_map_.find(id.view_id); |
| 62 return i == view_map_.end() ? NULL : i->second; | 63 return i == view_map_.end() ? NULL : i->second; |
| 63 } | 64 } |
| 64 return connection_manager_->GetView(id); | 65 return connection_manager_->GetView(id); |
| 65 } | 66 } |
| 66 | 67 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 view_target_drawn_state = false; | 210 view_target_drawn_state = false; |
| 210 } else { | 211 } else { |
| 211 // View is being shown. View will be drawn if its parent is drawn. | 212 // View is being shown. View will be drawn if its parent is drawn. |
| 212 view_target_drawn_state = | 213 view_target_drawn_state = |
| 213 view->parent() && view->parent()->IsDrawn(connection_manager_->root()); | 214 view->parent() && view->parent()->IsDrawn(connection_manager_->root()); |
| 214 } | 215 } |
| 215 | 216 |
| 216 NotifyDrawnStateChanged(view, view_target_drawn_state); | 217 NotifyDrawnStateChanged(view, view_target_drawn_state); |
| 217 } | 218 } |
| 218 | 219 |
| 219 void ViewManagerServiceImpl::OnConnectionError() { | |
| 220 connection_manager_->OnConnectionError(this); | |
| 221 } | |
| 222 | |
| 223 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { | 220 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { |
| 224 return known_views_.count(ViewIdToTransportId(view->id())) > 0; | 221 return known_views_.count(ViewIdToTransportId(view->id())) > 0; |
| 225 } | 222 } |
| 226 | 223 |
| 227 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, | 224 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, |
| 228 const ServerView* relative_view, | 225 const ServerView* relative_view, |
| 229 OrderDirection direction) const { | 226 OrderDirection direction) const { |
| 230 if (!view || !relative_view) | 227 if (!view || !relative_view) |
| 231 return false; | 228 return false; |
| 232 | 229 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 573 |
| 577 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 574 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
| 578 const ServerView* view) const { | 575 const ServerView* view) const { |
| 579 ViewManagerServiceImpl* connection = | 576 ViewManagerServiceImpl* connection = |
| 580 connection_manager_->GetConnectionWithRoot(view->id()); | 577 connection_manager_->GetConnectionWithRoot(view->id()); |
| 581 return connection && connection != this; | 578 return connection && connection != this; |
| 582 } | 579 } |
| 583 | 580 |
| 584 } // namespace service | 581 } // namespace service |
| 585 } // namespace mojo | 582 } // namespace mojo |
| OLD | NEW |