| 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 "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 10 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" |
| 10 #include "mojo/services/view_manager/connection_manager.h" | 11 #include "mojo/services/view_manager/connection_manager.h" |
| 11 #include "mojo/services/view_manager/default_access_policy.h" | 12 #include "mojo/services/view_manager/default_access_policy.h" |
| 12 #include "mojo/services/view_manager/server_view.h" | 13 #include "mojo/services/view_manager/server_view.h" |
| 13 #include "mojo/services/view_manager/window_manager_access_policy.h" | 14 #include "mojo/services/view_manager/window_manager_access_policy.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | |
| 15 #include "ui/aura/window.h" | |
| 16 #include "ui/gfx/codec/png_codec.h" | |
| 17 | 15 |
| 18 namespace mojo { | 16 namespace mojo { |
| 19 namespace service { | 17 namespace service { |
| 20 | 18 |
| 21 ViewManagerServiceImpl::ViewManagerServiceImpl( | 19 ViewManagerServiceImpl::ViewManagerServiceImpl( |
| 22 ConnectionManager* connection_manager, | 20 ConnectionManager* connection_manager, |
| 23 ConnectionSpecificId creator_id, | 21 ConnectionSpecificId creator_id, |
| 24 const std::string& creator_url, | 22 const std::string& creator_url, |
| 25 const std::string& url, | 23 const std::string& url, |
| 26 const ViewId& root_id, | 24 const ViewId& root_id, |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 const Callback<void(Array<ViewDataPtr>)>& callback) { | 388 const Callback<void(Array<ViewDataPtr>)>& callback) { |
| 391 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 389 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 392 std::vector<const ServerView*> views; | 390 std::vector<const ServerView*> views; |
| 393 if (view) { | 391 if (view) { |
| 394 GetViewTreeImpl(view, &views); | 392 GetViewTreeImpl(view, &views); |
| 395 // TODO(sky): this should map in views that weren't none. | 393 // TODO(sky): this should map in views that weren't none. |
| 396 } | 394 } |
| 397 callback.Run(ViewsToViewDatas(views)); | 395 callback.Run(ViewsToViewDatas(views)); |
| 398 } | 396 } |
| 399 | 397 |
| 400 void ViewManagerServiceImpl::SetViewContents( | 398 void ViewManagerServiceImpl::SetViewSurfaceId( |
| 401 Id view_id, | 399 Id view_id, |
| 402 ScopedSharedBufferHandle buffer, | 400 SurfaceIdPtr surface_id, |
| 403 uint32_t buffer_size, | |
| 404 const Callback<void(bool)>& callback) { | 401 const Callback<void(bool)>& callback) { |
| 405 // TODO(sky): add coverage of not being able to set for random view. | 402 // TODO(sky): add coverage of not being able to set for random node. |
| 406 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 403 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 407 if (!view || !access_policy_->CanSetViewContents(view)) { | 404 if (!view || !access_policy_->CanSetViewSurfaceId(view)) { |
| 408 callback.Run(false); | 405 callback.Run(false); |
| 409 return; | 406 return; |
| 410 } | 407 } |
| 411 void* handle_data; | 408 view->SetSurfaceId(surface_id.To<cc::SurfaceId>()); |
| 412 if (MapBuffer(buffer.get(), 0, buffer_size, &handle_data, | |
| 413 MOJO_MAP_BUFFER_FLAG_NONE) != MOJO_RESULT_OK) { | |
| 414 callback.Run(false); | |
| 415 return; | |
| 416 } | |
| 417 SkBitmap bitmap; | |
| 418 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), | |
| 419 buffer_size, &bitmap); | |
| 420 view->SetBitmap(bitmap); | |
| 421 UnmapBuffer(handle_data); | |
| 422 callback.Run(true); | 409 callback.Run(true); |
| 423 } | 410 } |
| 424 | 411 |
| 425 void ViewManagerServiceImpl::SetViewBounds( | 412 void ViewManagerServiceImpl::SetViewBounds( |
| 426 Id view_id, | 413 Id view_id, |
| 427 RectPtr bounds, | 414 RectPtr bounds, |
| 428 const Callback<void(bool)>& callback) { | 415 const Callback<void(bool)>& callback) { |
| 429 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 416 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 430 const bool success = view && access_policy_->CanSetViewBounds(view); | 417 const bool success = view && access_policy_->CanSetViewBounds(view); |
| 431 if (success) { | 418 if (success) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 528 |
| 542 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 529 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
| 543 const ServerView* view) const { | 530 const ServerView* view) const { |
| 544 ViewManagerServiceImpl* connection = | 531 ViewManagerServiceImpl* connection = |
| 545 connection_manager_->GetConnectionWithRoot(view->id()); | 532 connection_manager_->GetConnectionWithRoot(view->id()); |
| 546 return connection && connection != this; | 533 return connection && connection != this; |
| 547 } | 534 } |
| 548 | 535 |
| 549 } // namespace service | 536 } // namespace service |
| 550 } // namespace mojo | 537 } // namespace mojo |
| OLD | NEW |