OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/vr/VRController.h" | 5 #include "modules/vr/VRController.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
11 #include "modules/vr/NavigatorVR.h" | 11 #include "modules/vr/NavigatorVR.h" |
12 #include "modules/vr/VRGetDevicesCallback.h" | 12 #include "modules/vr/VRGetDevicesCallback.h" |
13 #include "public/platform/InterfaceProvider.h" | 13 #include "public/platform/InterfaceProvider.h" |
14 | 14 |
15 #include "wtf/Assertions.h" | 15 #include "wtf/Assertions.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 VRController::VRController(NavigatorVR* navigatorVR) | 19 VRController::VRController(NavigatorVR* navigatorVR) |
20 : ContextLifecycleObserver(navigatorVR->document()), | 20 : ContextLifecycleObserver(navigatorVR->document()), |
21 m_navigatorVR(navigatorVR), | 21 m_navigatorVR(navigatorVR), |
22 m_displaySynced(false), | 22 m_displaySynced(false), |
23 m_binding(this) { | 23 m_binding(this) { |
24 navigatorVR->document()->frame()->interfaceProvider()->getInterface( | 24 navigatorVR->document()->frame()->interfaceProvider()->getInterface( |
25 mojo::MakeRequest(&m_service)); | 25 mojo::MakeRequest(&m_service)); |
26 m_service->SetClient( | 26 m_service->SetClient( |
27 m_binding.CreateInterfacePtrAndBind(), | 27 m_binding.CreateInterfacePtrAndBind(), |
28 convertToBaseCallback( | 28 convertToBaseCallback( |
29 WTF::bind(&VRController::onDisplaysSynced, wrapPersistent(this)))); | 29 WTF::bind(&VRController::onDisplaysSynced, wrapPersistent(this)))); |
| 30 VLOG(1) << __FUNCTION__ << ": CONSTRUCTOR this=" << (void*)this << " *********
********************************************************************************
******************"; |
30 } | 31 } |
31 | 32 |
32 VRController::~VRController() {} | 33 VRController::~VRController() { |
| 34 VLOG(1) << __FUNCTION__ << ": CONSTRUCTOR this=" << (void*)this << " *********
********************************************************************************
******************"; |
| 35 } |
33 | 36 |
34 void VRController::getDisplays(ScriptPromiseResolver* resolver) { | 37 void VRController::getDisplays(ScriptPromiseResolver* resolver) { |
35 if (!m_service) { | 38 if (!m_service) { |
36 DOMException* exception = DOMException::create( | 39 DOMException* exception = DOMException::create( |
37 InvalidStateError, "The service is no longer active."); | 40 InvalidStateError, "The service is no longer active."); |
38 resolver->reject(exception); | 41 resolver->reject(exception); |
39 return; | 42 return; |
40 } | 43 } |
41 | 44 |
42 // If we've previously synced the VRDisplays just return the current list. | 45 // If we've previously synced the VRDisplays just return the current list. |
43 if (m_displaySynced) { | 46 if (m_displaySynced) { |
44 resolver->resolve(m_displays); | 47 resolver->resolve(m_displays); |
45 return; | 48 return; |
46 } | 49 } |
47 | 50 |
48 // Otherwise we're still waiting for the full list of displays to be populated | 51 // Otherwise we're still waiting for the full list of displays to be populated |
49 // so queue up the promise for resolution when onDisplaysSynced is called. | 52 // so queue up the promise for resolution when onDisplaysSynced is called. |
50 m_pendingGetDevicesCallbacks.append( | 53 m_pendingGetDevicesCallbacks.append( |
51 WTF::makeUnique<VRGetDevicesCallback>(resolver)); | 54 WTF::makeUnique<VRGetDevicesCallback>(resolver)); |
52 } | 55 } |
53 | 56 |
54 void VRController::setListeningForActivate(bool listening) { | 57 void VRController::setListeningForActivate(bool listening) { |
| 58 VLOG(1) << __FUNCTION__ << ": listening=" << listening << " m_service=" << m_s
ervice; |
55 if (m_service) | 59 if (m_service) |
56 m_service->SetListeningForActivate(listening); | 60 m_service->SetListeningForActivate(listening); |
57 } | 61 } |
58 | 62 |
59 // Each time a new VRDisplay is connected we'll recieve a VRDisplayPtr for it | 63 // Each time a new VRDisplay is connected we'll recieve a VRDisplayPtr for it |
60 // here. Upon calling SetClient in the constructor we should receive one call | 64 // here. Upon calling SetClient in the constructor we should receive one call |
61 // for each VRDisplay that was already connected at the time. | 65 // for each VRDisplay that was already connected at the time. |
62 void VRController::OnDisplayConnected( | 66 void VRController::OnDisplayConnected( |
63 device::mojom::blink::VRDisplayPtr display, | 67 device::mojom::blink::VRDisplayPtr display, |
64 device::mojom::blink::VRDisplayClientRequest request, | 68 device::mojom::blink::VRDisplayClientRequest request, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 113 } |
110 | 114 |
111 DEFINE_TRACE(VRController) { | 115 DEFINE_TRACE(VRController) { |
112 visitor->trace(m_navigatorVR); | 116 visitor->trace(m_navigatorVR); |
113 visitor->trace(m_displays); | 117 visitor->trace(m_displays); |
114 | 118 |
115 ContextLifecycleObserver::trace(visitor); | 119 ContextLifecycleObserver::trace(visitor); |
116 } | 120 } |
117 | 121 |
118 } // namespace blink | 122 } // namespace blink |
OLD | NEW |