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/NavigatorVRDevice.h" | 5 #include "modules/vr/NavigatorVR.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/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/frame/LocalDOMWindow.h" | 11 #include "core/frame/LocalDOMWindow.h" |
12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
13 #include "core/frame/Navigator.h" | 13 #include "core/frame/Navigator.h" |
14 #include "core/page/Page.h" | 14 #include "core/page/Page.h" |
15 #include "modules/vr/HMDVRDevice.h" | |
16 #include "modules/vr/PositionSensorVRDevice.h" | |
17 #include "modules/vr/VRController.h" | 15 #include "modules/vr/VRController.h" |
| 16 #include "modules/vr/VRDisplay.h" |
| 17 #include "modules/vr/VRDisplayCollection.h" |
18 #include "modules/vr/VRGetDevicesCallback.h" | 18 #include "modules/vr/VRGetDevicesCallback.h" |
19 #include "modules/vr/VRHardwareUnit.h" | 19 #include "modules/vr/VRPose.h" |
20 #include "modules/vr/VRHardwareUnitCollection.h" | |
21 #include "modules/vr/VRPositionState.h" | |
22 #include "wtf/PtrUtil.h" | 20 #include "wtf/PtrUtil.h" |
23 | 21 |
24 namespace blink { | 22 namespace blink { |
25 | 23 |
26 NavigatorVRDevice* NavigatorVRDevice::from(Document& document) | 24 NavigatorVR* NavigatorVR::from(Document& document) |
27 { | 25 { |
28 if (!document.frame() || !document.frame()->domWindow()) | 26 if (!document.frame() || !document.frame()->domWindow()) |
29 return 0; | 27 return 0; |
30 Navigator& navigator = *document.frame()->domWindow()->navigator(); | 28 Navigator& navigator = *document.frame()->domWindow()->navigator(); |
31 return &from(navigator); | 29 return &from(navigator); |
32 } | 30 } |
33 | 31 |
34 NavigatorVRDevice& NavigatorVRDevice::from(Navigator& navigator) | 32 NavigatorVR& NavigatorVR::from(Navigator& navigator) |
35 { | 33 { |
36 NavigatorVRDevice* supplement = static_cast<NavigatorVRDevice*>(Supplement<N
avigator>::from(navigator, supplementName())); | 34 NavigatorVR* supplement = static_cast<NavigatorVR*>(Supplement<Navigator>::f
rom(navigator, supplementName())); |
37 if (!supplement) { | 35 if (!supplement) { |
38 supplement = new NavigatorVRDevice(navigator.frame()); | 36 supplement = new NavigatorVR(navigator.frame()); |
39 provideTo(navigator, supplementName(), supplement); | 37 provideTo(navigator, supplementName(), supplement); |
40 } | 38 } |
41 return *supplement; | 39 return *supplement; |
42 } | 40 } |
43 | 41 |
44 ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState, Navigato
r& navigator) | 42 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState, Navigator& na
vigator) |
45 { | 43 { |
46 return NavigatorVRDevice::from(navigator).getVRDevices(scriptState); | 44 return NavigatorVR::from(navigator).getVRDisplays(scriptState); |
47 } | 45 } |
48 | 46 |
49 ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState) | 47 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) |
50 { | 48 { |
51 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
52 ScriptPromise promise = resolver->promise(); | 50 ScriptPromise promise = resolver->promise(); |
53 | 51 |
54 Document* document = m_frame ? m_frame->document() : 0; | 52 Document* document = m_frame ? m_frame->document() : 0; |
55 | 53 |
56 if (!document || !controller()) { | 54 if (!document || !controller()) { |
57 DOMException* exception = DOMException::create(InvalidStateError, "The o
bject is no longer associated to a document."); | 55 DOMException* exception = DOMException::create(InvalidStateError, "The o
bject is no longer associated to a document."); |
58 resolver->reject(exception); | 56 resolver->reject(exception); |
59 return promise; | 57 return promise; |
60 } | 58 } |
61 | 59 |
62 controller()->getDevices(WTF::wrapUnique(new VRGetDevicesCallback(resolver,
m_hardwareUnits.get()))); | 60 controller()->getDevices(WTF::wrapUnique(new VRGetDevicesCallback(resolver,
m_displays.get()))); |
63 | 61 |
64 return promise; | 62 return promise; |
65 } | 63 } |
66 | 64 |
67 VRController* NavigatorVRDevice::controller() | 65 VRController* NavigatorVR::controller() |
68 { | 66 { |
69 if (!frame()) | 67 if (!frame()) |
70 return 0; | 68 return 0; |
71 | 69 |
72 return VRController::from(*frame()); | 70 return VRController::from(*frame()); |
73 } | 71 } |
74 | 72 |
75 DEFINE_TRACE(NavigatorVRDevice) | 73 Document* NavigatorVR::document() |
76 { | 74 { |
77 visitor->trace(m_hardwareUnits); | 75 return m_frame ? m_frame->document() : 0; |
| 76 } |
| 77 |
| 78 DEFINE_TRACE(NavigatorVR) |
| 79 { |
| 80 visitor->trace(m_displays); |
78 | 81 |
79 Supplement<Navigator>::trace(visitor); | 82 Supplement<Navigator>::trace(visitor); |
80 DOMWindowProperty::trace(visitor); | 83 DOMWindowProperty::trace(visitor); |
81 } | 84 } |
82 | 85 |
83 NavigatorVRDevice::NavigatorVRDevice(LocalFrame* frame) | 86 NavigatorVR::NavigatorVR(LocalFrame* frame) |
84 : DOMWindowProperty(frame) | 87 : DOMWindowProperty(frame) |
85 { | 88 { |
86 m_hardwareUnits = new VRHardwareUnitCollection(this); | 89 m_displays = new VRDisplayCollection(this); |
87 } | 90 } |
88 | 91 |
89 const char* NavigatorVRDevice::supplementName() | 92 NavigatorVR::~NavigatorVR() |
90 { | 93 { |
91 return "NavigatorVRDevice"; | 94 } |
| 95 |
| 96 const char* NavigatorVR::supplementName() |
| 97 { |
| 98 return "NavigatorVR"; |
92 } | 99 } |
93 | 100 |
94 } // namespace blink | 101 } // namespace blink |
OLD | NEW |