| 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 "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 9 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 10 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 11 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 11 #include "mojo/services/view_manager/connection_manager.h" | 12 #include "mojo/services/view_manager/connection_manager.h" |
| 12 #include "mojo/services/view_manager/default_access_policy.h" | 13 #include "mojo/services/view_manager/default_access_policy.h" |
| 13 #include "mojo/services/view_manager/server_view.h" | 14 #include "mojo/services/view_manager/server_view.h" |
| 14 #include "mojo/services/view_manager/window_manager_access_policy.h" | 15 #include "mojo/services/view_manager/window_manager_access_policy.h" |
| 15 | 16 |
| 16 namespace mojo { | 17 namespace mojo { |
| 17 namespace service { | 18 namespace service { |
| 18 | 19 |
| 19 ViewManagerServiceImpl::ViewManagerServiceImpl( | 20 ViewManagerServiceImpl::ViewManagerServiceImpl( |
| 20 ConnectionManager* connection_manager, | 21 ConnectionManager* connection_manager, |
| 21 ConnectionSpecificId creator_id, | 22 ConnectionSpecificId creator_id, |
| 22 const std::string& creator_url, | 23 const std::string& creator_url, |
| 23 const std::string& url, | 24 const std::string& url, |
| 24 const ViewId& root_id, | 25 const ViewId& root_id, |
| 25 InterfaceRequest<ServiceProvider> service_provider) | 26 InterfaceRequest<ServiceProvider> service_provider) |
| 26 : connection_manager_(connection_manager), | 27 : connection_manager_(connection_manager), |
| 27 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 28 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 28 url_(url), | 29 url_(url), |
| 29 creator_id_(creator_id), | 30 creator_id_(creator_id), |
| 30 creator_url_(creator_url), | 31 creator_url_(creator_url), |
| 31 delete_on_connection_error_(false), | |
| 32 service_provider_(service_provider.Pass()) { | 32 service_provider_(service_provider.Pass()) { |
| 33 CHECK(GetView(root_id)); | 33 CHECK(GetView(root_id)); |
| 34 roots_.insert(ViewIdToTransportId(root_id)); | 34 roots_.insert(ViewIdToTransportId(root_id)); |
| 35 if (root_id == RootViewId()) | 35 if (root_id == RootViewId()) |
| 36 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 36 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
| 37 else | 37 else |
| 38 access_policy_.reset(new DefaultAccessPolicy(id_, this)); | 38 access_policy_.reset(new DefaultAccessPolicy(id_, this)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 ViewManagerServiceImpl::~ViewManagerServiceImpl() { | 41 ViewManagerServiceImpl::~ViewManagerServiceImpl() { |
| 42 // Delete any views we created. | 42 DestroyViews(); |
| 43 if (!view_map_.empty()) { | |
| 44 ConnectionManager::ScopedChange change(this, connection_manager_, true); | |
| 45 while (!view_map_.empty()) | |
| 46 delete view_map_.begin()->second; | |
| 47 } | |
| 48 | |
| 49 connection_manager_->RemoveConnection(this); | |
| 50 } | 43 } |
| 51 | 44 |
| 52 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { | 45 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { |
| 53 if (id_ == id.connection_id) { | 46 if (id_ == id.connection_id) { |
| 54 ViewMap::const_iterator i = view_map_.find(id.view_id); | 47 ViewMap::const_iterator i = view_map_.find(id.view_id); |
| 55 return i == view_map_.end() ? NULL : i->second; | 48 return i == view_map_.end() ? NULL : i->second; |
| 56 } | 49 } |
| 57 return connection_manager_->GetView(id); | 50 return connection_manager_->GetView(id); |
| 58 } | 51 } |
| 59 | 52 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } else { | 187 } else { |
| 195 // View is being shown. View will be drawn if its parent is drawn. | 188 // View is being shown. View will be drawn if its parent is drawn. |
| 196 view_target_drawn_state = | 189 view_target_drawn_state = |
| 197 view->parent() && view->parent()->IsDrawn(connection_manager_->root()); | 190 view->parent() && view->parent()->IsDrawn(connection_manager_->root()); |
| 198 } | 191 } |
| 199 | 192 |
| 200 NotifyDrawnStateChanged(view, view_target_drawn_state); | 193 NotifyDrawnStateChanged(view, view_target_drawn_state); |
| 201 } | 194 } |
| 202 | 195 |
| 203 void ViewManagerServiceImpl::OnConnectionError() { | 196 void ViewManagerServiceImpl::OnConnectionError() { |
| 204 if (delete_on_connection_error_) | 197 connection_manager_->OnConnectionError(this); |
| 205 delete this; | |
| 206 } | 198 } |
| 207 | 199 |
| 208 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { | 200 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { |
| 209 return known_views_.count(ViewIdToTransportId(view->id())) > 0; | 201 return known_views_.count(ViewIdToTransportId(view->id())) > 0; |
| 210 } | 202 } |
| 211 | 203 |
| 212 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, | 204 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, |
| 213 const ServerView* relative_view, | 205 const ServerView* relative_view, |
| 214 OrderDirection direction) const { | 206 OrderDirection direction) const { |
| 215 if (!view || !relative_view) | 207 if (!view || !relative_view) |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 const ServerView* root = GetView(ViewIdFromTransportId(*i)); | 346 const ServerView* root = GetView(ViewIdFromTransportId(*i)); |
| 355 DCHECK(root); | 347 DCHECK(root); |
| 356 if (view->Contains(root) && | 348 if (view->Contains(root) && |
| 357 (new_drawn_value != root->IsDrawn(connection_manager_->root()))) { | 349 (new_drawn_value != root->IsDrawn(connection_manager_->root()))) { |
| 358 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()), | 350 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()), |
| 359 new_drawn_value); | 351 new_drawn_value); |
| 360 } | 352 } |
| 361 } | 353 } |
| 362 } | 354 } |
| 363 | 355 |
| 356 void ViewManagerServiceImpl::DestroyViews() { |
| 357 if (!view_map_.empty()) { |
| 358 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
| 359 // If we get here from the destructor we're not going to get |
| 360 // ProcessViewDeleted(). Copy the map and delete from the copy so that we |
| 361 // don't have to worry about whether |view_map_| changes or not. |
| 362 ViewMap view_map_copy; |
| 363 view_map_.swap(view_map_copy); |
| 364 STLDeleteValues(&view_map_copy); |
| 365 } |
| 366 } |
| 367 |
| 364 void ViewManagerServiceImpl::CreateView( | 368 void ViewManagerServiceImpl::CreateView( |
| 365 Id transport_view_id, | 369 Id transport_view_id, |
| 366 const Callback<void(ErrorCode)>& callback) { | 370 const Callback<void(ErrorCode)>& callback) { |
| 367 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | 371 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| 368 ErrorCode error_code = ERROR_CODE_NONE; | 372 ErrorCode error_code = ERROR_CODE_NONE; |
| 369 if (view_id.connection_id != id_) { | 373 if (view_id.connection_id != id_) { |
| 370 error_code = ERROR_CODE_ILLEGAL_ARGUMENT; | 374 error_code = ERROR_CODE_ILLEGAL_ARGUMENT; |
| 371 } else if (view_map_.find(view_id.view_id) != view_map_.end()) { | 375 } else if (view_map_.find(view_id.view_id) != view_map_.end()) { |
| 372 error_code = ERROR_CODE_VALUE_IN_USE; | 376 error_code = ERROR_CODE_VALUE_IN_USE; |
| 373 } else { | 377 } else { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 if (existing_owner) { | 539 if (existing_owner) { |
| 536 // Never message the originating connection. | 540 // Never message the originating connection. |
| 537 connection_manager_->OnConnectionMessagedClient(id_); | 541 connection_manager_->OnConnectionMessagedClient(id_); |
| 538 existing_owner->RemoveRoot(view_id); | 542 existing_owner->RemoveRoot(view_id); |
| 539 } | 543 } |
| 540 connection_manager_->EmbedAtView(id_, url, transport_view_id, spir.Pass()); | 544 connection_manager_->EmbedAtView(id_, url, transport_view_id, spir.Pass()); |
| 541 callback.Run(true); | 545 callback.Run(true); |
| 542 } | 546 } |
| 543 | 547 |
| 544 void ViewManagerServiceImpl::OnConnectionEstablished() { | 548 void ViewManagerServiceImpl::OnConnectionEstablished() { |
| 545 connection_manager_->AddConnection(this); | |
| 546 | |
| 547 std::vector<const ServerView*> to_send; | 549 std::vector<const ServerView*> to_send; |
| 548 for (ViewIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) | 550 for (ViewIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) |
| 549 GetUnknownViewsFrom(GetView(ViewIdFromTransportId(*i)), &to_send); | 551 GetUnknownViewsFrom(GetView(ViewIdFromTransportId(*i)), &to_send); |
| 550 | 552 |
| 551 client()->OnEmbed(id_, | 553 client()->OnEmbed(id_, |
| 552 creator_url_, | 554 creator_url_, |
| 553 ViewToViewData(to_send.front()), | 555 ViewToViewData(to_send.front()), |
| 554 service_provider_.Pass()); | 556 service_provider_.Pass()); |
| 555 } | 557 } |
| 556 | 558 |
| 557 const base::hash_set<Id>& | 559 const base::hash_set<Id>& |
| 558 ViewManagerServiceImpl::GetRootsForAccessPolicy() const { | 560 ViewManagerServiceImpl::GetRootsForAccessPolicy() const { |
| 559 return roots_; | 561 return roots_; |
| 560 } | 562 } |
| 561 | 563 |
| 562 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( | 564 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( |
| 563 const ServerView* view) const { | 565 const ServerView* view) const { |
| 564 return IsViewKnown(view); | 566 return IsViewKnown(view); |
| 565 } | 567 } |
| 566 | 568 |
| 567 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 569 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
| 568 const ServerView* view) const { | 570 const ServerView* view) const { |
| 569 ViewManagerServiceImpl* connection = | 571 ViewManagerServiceImpl* connection = |
| 570 connection_manager_->GetConnectionWithRoot(view->id()); | 572 connection_manager_->GetConnectionWithRoot(view->id()); |
| 571 return connection && connection != this; | 573 return connection && connection != this; |
| 572 } | 574 } |
| 573 | 575 |
| 574 } // namespace service | 576 } // namespace service |
| 575 } // namespace mojo | 577 } // namespace mojo |
| OLD | NEW |