OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "mojo/services/view_manager/view_manager_service_impl.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" |
| 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 11 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 12 #include "mojo/services/view_manager/connection_manager.h" |
| 13 #include "mojo/services/view_manager/default_access_policy.h" |
| 14 #include "mojo/services/view_manager/display_manager.h" |
| 15 #include "mojo/services/view_manager/server_view.h" |
| 16 #include "mojo/services/view_manager/window_manager_access_policy.h" |
| 17 #include "third_party/mojo_services/src/window_manager/public/interfaces/window_
manager_internal.mojom.h" |
| 18 |
| 19 using mojo::Array; |
| 20 using mojo::Callback; |
| 21 using mojo::Id; |
| 22 using mojo::InterfaceRequest; |
| 23 using mojo::OrderDirection; |
| 24 using mojo::Rect; |
| 25 using mojo::ServiceProvider; |
| 26 using mojo::ServiceProviderPtr; |
| 27 using mojo::String; |
| 28 using mojo::ViewDataPtr; |
| 29 |
| 30 namespace view_manager { |
| 31 |
| 32 ViewManagerServiceImpl::ViewManagerServiceImpl( |
| 33 ConnectionManager* connection_manager, |
| 34 mojo::ConnectionSpecificId creator_id, |
| 35 const std::string& creator_url, |
| 36 const std::string& url, |
| 37 const ViewId& root_id) |
| 38 : connection_manager_(connection_manager), |
| 39 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 40 url_(url), |
| 41 creator_id_(creator_id), |
| 42 creator_url_(creator_url), |
| 43 client_(nullptr) { |
| 44 CHECK(GetView(root_id)); |
| 45 root_.reset(new ViewId(root_id)); |
| 46 if (root_id == RootViewId()) |
| 47 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
| 48 else |
| 49 access_policy_.reset(new DefaultAccessPolicy(id_, this)); |
| 50 } |
| 51 |
| 52 ViewManagerServiceImpl::~ViewManagerServiceImpl() { |
| 53 DestroyViews(); |
| 54 } |
| 55 |
| 56 void ViewManagerServiceImpl::Init(mojo::ViewManagerClient* client, |
| 57 mojo::ViewManagerServicePtr service_ptr, |
| 58 InterfaceRequest<ServiceProvider> services, |
| 59 ServiceProviderPtr exposed_services) { |
| 60 DCHECK(!client_); |
| 61 client_ = client; |
| 62 std::vector<const ServerView*> to_send; |
| 63 if (root_.get()) |
| 64 GetUnknownViewsFrom(GetView(*root_), &to_send); |
| 65 |
| 66 mojo::MessagePipe pipe; |
| 67 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient( |
| 68 id_, pipe.handle1.Pass()); |
| 69 client->OnEmbed(id_, creator_url_, ViewToViewData(to_send.front()), |
| 70 service_ptr.Pass(), services.Pass(), exposed_services.Pass(), |
| 71 pipe.handle0.Pass()); |
| 72 } |
| 73 |
| 74 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { |
| 75 if (id_ == id.connection_id) { |
| 76 ViewMap::const_iterator i = view_map_.find(id.view_id); |
| 77 return i == view_map_.end() ? NULL : i->second; |
| 78 } |
| 79 return connection_manager_->GetView(id); |
| 80 } |
| 81 |
| 82 bool ViewManagerServiceImpl::IsRoot(const ViewId& id) const { |
| 83 return root_.get() && *root_ == id; |
| 84 } |
| 85 |
| 86 void ViewManagerServiceImpl::OnWillDestroyViewManagerServiceImpl( |
| 87 ViewManagerServiceImpl* connection) { |
| 88 if (creator_id_ == connection->id()) |
| 89 creator_id_ = kInvalidConnectionId; |
| 90 if (connection->root_ && connection->root_->connection_id == id_ && |
| 91 view_map_.count(connection->root_->view_id) > 0) { |
| 92 client()->OnEmbeddedAppDisconnected( |
| 93 ViewIdToTransportId(*connection->root_)); |
| 94 } |
| 95 if (root_.get() && root_->connection_id == connection->id()) |
| 96 root_.reset(); |
| 97 } |
| 98 |
| 99 mojo::ErrorCode ViewManagerServiceImpl::CreateView(const ViewId& view_id) { |
| 100 if (view_id.connection_id != id_) |
| 101 return mojo::ERROR_CODE_ILLEGAL_ARGUMENT; |
| 102 if (view_map_.find(view_id.view_id) != view_map_.end()) |
| 103 return mojo::ERROR_CODE_VALUE_IN_USE; |
| 104 view_map_[view_id.view_id] = new ServerView(connection_manager_, view_id); |
| 105 known_views_.insert(ViewIdToTransportId(view_id)); |
| 106 return mojo::ERROR_CODE_NONE; |
| 107 } |
| 108 |
| 109 bool ViewManagerServiceImpl::AddView(const ViewId& parent_id, |
| 110 const ViewId& child_id) { |
| 111 ServerView* parent = GetView(parent_id); |
| 112 ServerView* child = GetView(child_id); |
| 113 if (parent && child && child->parent() != parent && |
| 114 !child->Contains(parent) && access_policy_->CanAddView(parent, child)) { |
| 115 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 116 parent->Add(child); |
| 117 return true; |
| 118 } |
| 119 return false; |
| 120 } |
| 121 |
| 122 std::vector<const ServerView*> ViewManagerServiceImpl::GetViewTree( |
| 123 const ViewId& view_id) const { |
| 124 const ServerView* view = GetView(view_id); |
| 125 std::vector<const ServerView*> views; |
| 126 if (view) |
| 127 GetViewTreeImpl(view, &views); |
| 128 return views; |
| 129 } |
| 130 |
| 131 bool ViewManagerServiceImpl::SetViewVisibility(const ViewId& view_id, |
| 132 bool visible) { |
| 133 ServerView* view = GetView(view_id); |
| 134 if (!view || view->visible() == visible || |
| 135 !access_policy_->CanChangeViewVisibility(view)) { |
| 136 return false; |
| 137 } |
| 138 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 139 view->SetVisible(visible); |
| 140 return true; |
| 141 } |
| 142 |
| 143 bool ViewManagerServiceImpl::EmbedUrl( |
| 144 const std::string& url, |
| 145 const ViewId& view_id, |
| 146 InterfaceRequest<ServiceProvider> services, |
| 147 ServiceProviderPtr exposed_services) { |
| 148 if (!PrepareForEmbed(view_id)) |
| 149 return false; |
| 150 connection_manager_->EmbedAtView(id_, url, view_id, services.Pass(), |
| 151 exposed_services.Pass()); |
| 152 return true; |
| 153 } |
| 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 |
| 163 void ViewManagerServiceImpl::ProcessViewBoundsChanged( |
| 164 const ServerView* view, |
| 165 const gfx::Rect& old_bounds, |
| 166 const gfx::Rect& new_bounds, |
| 167 bool originated_change) { |
| 168 if (originated_change || !IsViewKnown(view)) |
| 169 return; |
| 170 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), |
| 171 Rect::From(old_bounds), |
| 172 Rect::From(new_bounds)); |
| 173 } |
| 174 |
| 175 void ViewManagerServiceImpl::ProcessViewportMetricsChanged( |
| 176 const mojo::ViewportMetrics& old_metrics, |
| 177 const mojo::ViewportMetrics& new_metrics, |
| 178 bool originated_change) { |
| 179 client()->OnViewViewportMetricsChanged(old_metrics.Clone(), |
| 180 new_metrics.Clone()); |
| 181 } |
| 182 |
| 183 void ViewManagerServiceImpl::ProcessWillChangeViewHierarchy( |
| 184 const ServerView* view, |
| 185 const ServerView* new_parent, |
| 186 const ServerView* old_parent, |
| 187 bool originated_change) { |
| 188 if (originated_change) |
| 189 return; |
| 190 |
| 191 const bool old_drawn = view->IsDrawn(connection_manager_->root()); |
| 192 const bool new_drawn = view->visible() && new_parent && |
| 193 new_parent->IsDrawn(connection_manager_->root()); |
| 194 if (old_drawn == new_drawn) |
| 195 return; |
| 196 |
| 197 NotifyDrawnStateChanged(view, new_drawn); |
| 198 } |
| 199 |
| 200 void ViewManagerServiceImpl::ProcessViewPropertyChanged( |
| 201 const ServerView* view, |
| 202 const std::string& name, |
| 203 const std::vector<uint8_t>* new_data, |
| 204 bool originated_change) { |
| 205 if (originated_change) |
| 206 return; |
| 207 |
| 208 Array<uint8_t> data; |
| 209 if (new_data) |
| 210 data = Array<uint8_t>::From(*new_data); |
| 211 |
| 212 client()->OnViewSharedPropertyChanged(ViewIdToTransportId(view->id()), |
| 213 String(name), data.Pass()); |
| 214 } |
| 215 |
| 216 void ViewManagerServiceImpl::ProcessViewHierarchyChanged( |
| 217 const ServerView* view, |
| 218 const ServerView* new_parent, |
| 219 const ServerView* old_parent, |
| 220 bool originated_change) { |
| 221 if (originated_change && !IsViewKnown(view) && new_parent && |
| 222 IsViewKnown(new_parent)) { |
| 223 std::vector<const ServerView*> unused; |
| 224 GetUnknownViewsFrom(view, &unused); |
| 225 } |
| 226 if (originated_change || connection_manager_->is_processing_delete_view() || |
| 227 connection_manager_->DidConnectionMessageClient(id_)) { |
| 228 return; |
| 229 } |
| 230 |
| 231 if (!access_policy_->ShouldNotifyOnHierarchyChange( |
| 232 view, &new_parent, &old_parent)) { |
| 233 return; |
| 234 } |
| 235 // Inform the client of any new views and update the set of views we know |
| 236 // about. |
| 237 std::vector<const ServerView*> to_send; |
| 238 if (!IsViewKnown(view)) |
| 239 GetUnknownViewsFrom(view, &to_send); |
| 240 const ViewId new_parent_id(new_parent ? new_parent->id() : ViewId()); |
| 241 const ViewId old_parent_id(old_parent ? old_parent->id() : ViewId()); |
| 242 client()->OnViewHierarchyChanged(ViewIdToTransportId(view->id()), |
| 243 ViewIdToTransportId(new_parent_id), |
| 244 ViewIdToTransportId(old_parent_id), |
| 245 ViewsToViewDatas(to_send)); |
| 246 connection_manager_->OnConnectionMessagedClient(id_); |
| 247 } |
| 248 |
| 249 void ViewManagerServiceImpl::ProcessViewReorder(const ServerView* view, |
| 250 const ServerView* relative_view, |
| 251 OrderDirection direction, |
| 252 bool originated_change) { |
| 253 if (originated_change || !IsViewKnown(view) || !IsViewKnown(relative_view)) |
| 254 return; |
| 255 |
| 256 client()->OnViewReordered(ViewIdToTransportId(view->id()), |
| 257 ViewIdToTransportId(relative_view->id()), |
| 258 direction); |
| 259 } |
| 260 |
| 261 void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view, |
| 262 bool originated_change) { |
| 263 if (view.connection_id == id_) |
| 264 view_map_.erase(view.view_id); |
| 265 |
| 266 const bool in_known = known_views_.erase(ViewIdToTransportId(view)) > 0; |
| 267 |
| 268 if (IsRoot(view)) |
| 269 root_.reset(); |
| 270 |
| 271 if (originated_change) |
| 272 return; |
| 273 |
| 274 if (in_known) { |
| 275 client()->OnViewDeleted(ViewIdToTransportId(view)); |
| 276 connection_manager_->OnConnectionMessagedClient(id_); |
| 277 } |
| 278 } |
| 279 |
| 280 void ViewManagerServiceImpl::ProcessWillChangeViewVisibility( |
| 281 const ServerView* view, |
| 282 bool originated_change) { |
| 283 if (originated_change) |
| 284 return; |
| 285 |
| 286 if (IsViewKnown(view)) { |
| 287 client()->OnViewVisibilityChanged(ViewIdToTransportId(view->id()), |
| 288 !view->visible()); |
| 289 return; |
| 290 } |
| 291 |
| 292 bool view_target_drawn_state; |
| 293 if (view->visible()) { |
| 294 // View is being hidden, won't be drawn. |
| 295 view_target_drawn_state = false; |
| 296 } else { |
| 297 // View is being shown. View will be drawn if its parent is drawn. |
| 298 view_target_drawn_state = |
| 299 view->parent() && view->parent()->IsDrawn(connection_manager_->root()); |
| 300 } |
| 301 |
| 302 NotifyDrawnStateChanged(view, view_target_drawn_state); |
| 303 } |
| 304 |
| 305 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { |
| 306 return known_views_.count(ViewIdToTransportId(view->id())) > 0; |
| 307 } |
| 308 |
| 309 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, |
| 310 const ServerView* relative_view, |
| 311 OrderDirection direction) const { |
| 312 if (!view || !relative_view) |
| 313 return false; |
| 314 |
| 315 if (!view->parent() || view->parent() != relative_view->parent()) |
| 316 return false; |
| 317 |
| 318 if (!access_policy_->CanReorderView(view, relative_view, direction)) |
| 319 return false; |
| 320 |
| 321 std::vector<const ServerView*> children = view->parent()->GetChildren(); |
| 322 const size_t child_i = |
| 323 std::find(children.begin(), children.end(), view) - children.begin(); |
| 324 const size_t target_i = |
| 325 std::find(children.begin(), children.end(), relative_view) - |
| 326 children.begin(); |
| 327 if ((direction == mojo::ORDER_DIRECTION_ABOVE && child_i == target_i + 1) || |
| 328 (direction == mojo::ORDER_DIRECTION_BELOW && child_i + 1 == target_i)) { |
| 329 return false; |
| 330 } |
| 331 |
| 332 return true; |
| 333 } |
| 334 |
| 335 bool ViewManagerServiceImpl::DeleteViewImpl(ViewManagerServiceImpl* source, |
| 336 ServerView* view) { |
| 337 DCHECK(view); |
| 338 DCHECK_EQ(view->id().connection_id, id_); |
| 339 ConnectionManager::ScopedChange change(source, connection_manager_, true); |
| 340 delete view; |
| 341 return true; |
| 342 } |
| 343 |
| 344 void ViewManagerServiceImpl::GetUnknownViewsFrom( |
| 345 const ServerView* view, |
| 346 std::vector<const ServerView*>* views) { |
| 347 if (IsViewKnown(view) || !access_policy_->CanGetViewTree(view)) |
| 348 return; |
| 349 views->push_back(view); |
| 350 known_views_.insert(ViewIdToTransportId(view->id())); |
| 351 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
| 352 return; |
| 353 std::vector<const ServerView*> children(view->GetChildren()); |
| 354 for (size_t i = 0 ; i < children.size(); ++i) |
| 355 GetUnknownViewsFrom(children[i], views); |
| 356 } |
| 357 |
| 358 void ViewManagerServiceImpl::RemoveFromKnown( |
| 359 const ServerView* view, |
| 360 std::vector<ServerView*>* local_views) { |
| 361 if (view->id().connection_id == id_) { |
| 362 if (local_views) |
| 363 local_views->push_back(GetView(view->id())); |
| 364 return; |
| 365 } |
| 366 known_views_.erase(ViewIdToTransportId(view->id())); |
| 367 std::vector<const ServerView*> children = view->GetChildren(); |
| 368 for (size_t i = 0; i < children.size(); ++i) |
| 369 RemoveFromKnown(children[i], local_views); |
| 370 } |
| 371 |
| 372 void ViewManagerServiceImpl::RemoveRoot() { |
| 373 CHECK(root_.get()); |
| 374 const ViewId root_id(*root_); |
| 375 root_.reset(); |
| 376 // No need to do anything if we created the view. |
| 377 if (root_id.connection_id == id_) |
| 378 return; |
| 379 |
| 380 client()->OnViewDeleted(ViewIdToTransportId(root_id)); |
| 381 connection_manager_->OnConnectionMessagedClient(id_); |
| 382 |
| 383 // This connection no longer knows about the view. Unparent any views that |
| 384 // were parented to views in the root. |
| 385 std::vector<ServerView*> local_views; |
| 386 RemoveFromKnown(GetView(root_id), &local_views); |
| 387 for (size_t i = 0; i < local_views.size(); ++i) |
| 388 local_views[i]->parent()->Remove(local_views[i]); |
| 389 } |
| 390 |
| 391 void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed( |
| 392 const ViewId& view_id) { |
| 393 ServerView* view = GetView(view_id); |
| 394 CHECK(view); |
| 395 CHECK(view->id().connection_id == view_id.connection_id); |
| 396 std::vector<ServerView*> children = view->GetChildren(); |
| 397 for (size_t i = 0; i < children.size(); ++i) |
| 398 view->Remove(children[i]); |
| 399 } |
| 400 |
| 401 Array<ViewDataPtr> ViewManagerServiceImpl::ViewsToViewDatas( |
| 402 const std::vector<const ServerView*>& views) { |
| 403 Array<ViewDataPtr> array(views.size()); |
| 404 for (size_t i = 0; i < views.size(); ++i) |
| 405 array[i] = ViewToViewData(views[i]).Pass(); |
| 406 return array.Pass(); |
| 407 } |
| 408 |
| 409 ViewDataPtr ViewManagerServiceImpl::ViewToViewData(const ServerView* view) { |
| 410 DCHECK(IsViewKnown(view)); |
| 411 const ServerView* parent = view->parent(); |
| 412 // If the parent isn't known, it means the parent is not visible to us (not |
| 413 // in roots), and should not be sent over. |
| 414 if (parent && !IsViewKnown(parent)) |
| 415 parent = NULL; |
| 416 ViewDataPtr view_data(mojo::ViewData::New()); |
| 417 view_data->parent_id = ViewIdToTransportId(parent ? parent->id() : ViewId()); |
| 418 view_data->view_id = ViewIdToTransportId(view->id()); |
| 419 view_data->bounds = Rect::From(view->bounds()); |
| 420 view_data->properties = |
| 421 mojo::Map<String, Array<uint8_t>>::From(view->properties()); |
| 422 view_data->visible = view->visible(); |
| 423 view_data->drawn = view->IsDrawn(connection_manager_->root()); |
| 424 view_data->viewport_metrics = |
| 425 connection_manager_->display_manager()->GetViewportMetrics().Clone(); |
| 426 return view_data.Pass(); |
| 427 } |
| 428 |
| 429 void ViewManagerServiceImpl::GetViewTreeImpl( |
| 430 const ServerView* view, |
| 431 std::vector<const ServerView*>* views) const { |
| 432 DCHECK(view); |
| 433 |
| 434 if (!access_policy_->CanGetViewTree(view)) |
| 435 return; |
| 436 |
| 437 views->push_back(view); |
| 438 |
| 439 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
| 440 return; |
| 441 |
| 442 std::vector<const ServerView*> children(view->GetChildren()); |
| 443 for (size_t i = 0 ; i < children.size(); ++i) |
| 444 GetViewTreeImpl(children[i], views); |
| 445 } |
| 446 |
| 447 void ViewManagerServiceImpl::NotifyDrawnStateChanged(const ServerView* view, |
| 448 bool new_drawn_value) { |
| 449 // Even though we don't know about view, it may be an ancestor of our root, in |
| 450 // which case the change may effect our roots drawn state. |
| 451 if (!root_.get()) |
| 452 return; |
| 453 |
| 454 const ServerView* root = GetView(*root_); |
| 455 DCHECK(root); |
| 456 if (view->Contains(root) && |
| 457 (new_drawn_value != root->IsDrawn(connection_manager_->root()))) { |
| 458 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()), |
| 459 new_drawn_value); |
| 460 } |
| 461 } |
| 462 |
| 463 void ViewManagerServiceImpl::DestroyViews() { |
| 464 if (!view_map_.empty()) { |
| 465 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
| 466 // If we get here from the destructor we're not going to get |
| 467 // ProcessViewDeleted(). Copy the map and delete from the copy so that we |
| 468 // don't have to worry about whether |view_map_| changes or not. |
| 469 ViewMap view_map_copy; |
| 470 view_map_.swap(view_map_copy); |
| 471 STLDeleteValues(&view_map_copy); |
| 472 } |
| 473 } |
| 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 |
| 494 void ViewManagerServiceImpl::CreateView( |
| 495 Id transport_view_id, |
| 496 const Callback<void(mojo::ErrorCode)>& callback) { |
| 497 callback.Run(CreateView(ViewIdFromTransportId(transport_view_id))); |
| 498 } |
| 499 |
| 500 void ViewManagerServiceImpl::DeleteView( |
| 501 Id transport_view_id, |
| 502 const Callback<void(bool)>& callback) { |
| 503 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
| 504 bool success = false; |
| 505 if (view && access_policy_->CanDeleteView(view)) { |
| 506 ViewManagerServiceImpl* connection = |
| 507 connection_manager_->GetConnection(view->id().connection_id); |
| 508 success = connection && connection->DeleteViewImpl(this, view); |
| 509 } |
| 510 callback.Run(success); |
| 511 } |
| 512 |
| 513 void ViewManagerServiceImpl::AddView( |
| 514 Id parent_id, |
| 515 Id child_id, |
| 516 const Callback<void(bool)>& callback) { |
| 517 callback.Run(AddView(ViewIdFromTransportId(parent_id), |
| 518 ViewIdFromTransportId(child_id))); |
| 519 } |
| 520 |
| 521 void ViewManagerServiceImpl::RemoveViewFromParent( |
| 522 Id view_id, |
| 523 const Callback<void(bool)>& callback) { |
| 524 bool success = false; |
| 525 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 526 if (view && view->parent() && access_policy_->CanRemoveViewFromParent(view)) { |
| 527 success = true; |
| 528 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 529 view->parent()->Remove(view); |
| 530 } |
| 531 callback.Run(success); |
| 532 } |
| 533 |
| 534 void ViewManagerServiceImpl::ReorderView(Id view_id, |
| 535 Id relative_view_id, |
| 536 OrderDirection direction, |
| 537 const Callback<void(bool)>& callback) { |
| 538 bool success = false; |
| 539 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 540 ServerView* relative_view = GetView(ViewIdFromTransportId(relative_view_id)); |
| 541 if (CanReorderView(view, relative_view, direction)) { |
| 542 success = true; |
| 543 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 544 view->parent()->Reorder(view, relative_view, direction); |
| 545 connection_manager_->ProcessViewReorder(view, relative_view, direction); |
| 546 } |
| 547 callback.Run(success); |
| 548 } |
| 549 |
| 550 void ViewManagerServiceImpl::GetViewTree( |
| 551 Id view_id, |
| 552 const Callback<void(Array<ViewDataPtr>)>& callback) { |
| 553 std::vector<const ServerView*> views( |
| 554 GetViewTree(ViewIdFromTransportId(view_id))); |
| 555 callback.Run(ViewsToViewDatas(views)); |
| 556 } |
| 557 |
| 558 void ViewManagerServiceImpl::SetViewSurfaceId( |
| 559 Id view_id, |
| 560 mojo::SurfaceIdPtr surface_id, |
| 561 const Callback<void(bool)>& callback) { |
| 562 // TODO(sky): add coverage of not being able to set for random node. |
| 563 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 564 if (!view || !access_policy_->CanSetViewSurfaceId(view)) { |
| 565 callback.Run(false); |
| 566 return; |
| 567 } |
| 568 view->SetSurfaceId(surface_id.To<cc::SurfaceId>()); |
| 569 callback.Run(true); |
| 570 } |
| 571 |
| 572 void ViewManagerServiceImpl::SetViewBounds( |
| 573 Id view_id, |
| 574 mojo::RectPtr bounds, |
| 575 const Callback<void(bool)>& callback) { |
| 576 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 577 const bool success = view && access_policy_->CanSetViewBounds(view); |
| 578 if (success) { |
| 579 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 580 view->SetBounds(bounds.To<gfx::Rect>()); |
| 581 } |
| 582 callback.Run(success); |
| 583 } |
| 584 |
| 585 void ViewManagerServiceImpl::SetViewVisibility( |
| 586 Id transport_view_id, |
| 587 bool visible, |
| 588 const Callback<void(bool)>& callback) { |
| 589 callback.Run( |
| 590 SetViewVisibility(ViewIdFromTransportId(transport_view_id), visible)); |
| 591 } |
| 592 |
| 593 void ViewManagerServiceImpl::SetViewProperty( |
| 594 uint32_t view_id, |
| 595 const mojo::String& name, |
| 596 mojo::Array<uint8_t> value, |
| 597 const mojo::Callback<void(bool)>& callback) { |
| 598 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 599 const bool success = view && access_policy_->CanSetViewProperties(view); |
| 600 if (success) { |
| 601 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 602 |
| 603 if (value.is_null()) { |
| 604 view->SetProperty(name, nullptr); |
| 605 } else { |
| 606 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); |
| 607 view->SetProperty(name, &data); |
| 608 } |
| 609 } |
| 610 callback.Run(success); |
| 611 } |
| 612 |
| 613 void ViewManagerServiceImpl::EmbedUrl( |
| 614 const String& url, |
| 615 Id transport_view_id, |
| 616 InterfaceRequest<ServiceProvider> services, |
| 617 ServiceProviderPtr exposed_services, |
| 618 const Callback<void(bool)>& callback) { |
| 619 callback.Run(EmbedUrl(url.To<std::string>(), |
| 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())); |
| 628 } |
| 629 |
| 630 void ViewManagerServiceImpl::PerformAction( |
| 631 mojo::Id transport_view_id, |
| 632 const mojo::String& action, |
| 633 const mojo::Callback<void(bool)>& callback) { |
| 634 connection_manager_->GetWindowManagerViewManagerClient()->OnPerformAction( |
| 635 transport_view_id, action, callback); |
| 636 } |
| 637 |
| 638 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId& id) const { |
| 639 return IsRoot(id); |
| 640 } |
| 641 |
| 642 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( |
| 643 const ServerView* view) const { |
| 644 return IsViewKnown(view); |
| 645 } |
| 646 |
| 647 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
| 648 const ServerView* view) const { |
| 649 ViewManagerServiceImpl* connection = |
| 650 connection_manager_->GetConnectionWithRoot(view->id()); |
| 651 return connection && connection != this; |
| 652 } |
| 653 |
| 654 } // namespace view_manager |
OLD | NEW |