OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "device/vr/vr_device.h" | 8 #include "device/vr/vr_device.h" |
9 #include "device/vr/vr_service_impl.h" | 9 #include "device/vr/vr_service_impl.h" |
10 | 10 |
11 namespace device { | 11 namespace device { |
12 | 12 |
13 VRDisplayImpl::VRDisplayImpl(device::VRDevice* device, VRServiceImpl* service) | 13 VRDisplayImpl::VRDisplayImpl(device::VRDevice* device, VRServiceImpl* service) |
14 : binding_(this), device_(device), service_(service) { | 14 : binding_(this), device_(device), service_(service) { |
15 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); | 15 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); |
16 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), | 16 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), |
17 mojo::GetProxy(&client_), | 17 mojo::GetProxy(&client_), |
18 std::move(display_info)); | 18 std::move(display_info)); |
19 } | 19 } |
20 | 20 |
21 VRDisplayImpl::~VRDisplayImpl() {} | 21 VRDisplayImpl::~VRDisplayImpl() {} |
22 | 22 |
23 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { | 23 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { |
24 callback.Run(device_->GetPose(service_.get())); | 24 if (!device_->IsAccessAllowed(service_.get())) { |
| 25 callback.Run(nullptr); |
| 26 return; |
| 27 } |
| 28 |
| 29 callback.Run(device_->GetPose()); |
25 } | 30 } |
26 | 31 |
27 void VRDisplayImpl::ResetPose() { | 32 void VRDisplayImpl::ResetPose() { |
28 device_->ResetPose(service_.get()); | 33 if (!device_->IsAccessAllowed(service_.get())) |
| 34 return; |
| 35 |
| 36 device_->ResetPose(); |
29 } | 37 } |
30 | 38 |
31 void VRDisplayImpl::RequestPresent(bool secureOrigin, | 39 void VRDisplayImpl::RequestPresent(bool secureOrigin, |
32 const RequestPresentCallback& callback) { | 40 const RequestPresentCallback& callback) { |
33 callback.Run(device_->RequestPresent(service_.get(), secureOrigin)); | 41 if (!device_->IsAccessAllowed(service_.get())) { |
| 42 callback.Run(false); |
| 43 return; |
| 44 } |
| 45 |
| 46 bool success = device_->RequestPresent(secureOrigin); |
| 47 if (success) { |
| 48 device_->SetPresentingService(service_.get()); |
| 49 } |
| 50 callback.Run(success); |
34 } | 51 } |
35 | 52 |
36 void VRDisplayImpl::ExitPresent() { | 53 void VRDisplayImpl::ExitPresent() { |
37 device_->ExitPresent(service_.get()); | 54 if (device_->IsPresentingService(service_.get())) |
| 55 device_->ExitPresent(); |
38 } | 56 } |
39 | 57 |
40 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { | 58 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { |
41 device_->SubmitFrame(service_.get(), std::move(pose)); | 59 if (!device_->IsPresentingService(service_.get())) |
| 60 return; |
| 61 device_->SubmitFrame(std::move(pose)); |
42 } | 62 } |
43 | 63 |
44 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr leftBounds, | 64 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr leftBounds, |
45 mojom::VRLayerBoundsPtr rightBounds) { | 65 mojom::VRLayerBoundsPtr rightBounds) { |
46 device_->UpdateLayerBounds(service_.get(), std::move(leftBounds), | 66 if (!device_->IsAccessAllowed(service_.get())) |
47 std::move(rightBounds)); | 67 return; |
| 68 |
| 69 device_->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds)); |
48 } | 70 } |
49 } | 71 } |
OLD | NEW |