Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: third_party/WebKit/Source/modules/vr/NavigatorVRDevice.cpp

Issue 1918143007: Updated Blink WebVR interfaces to WebVR v1 spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webvr_mojo
Patch Set: Fixed layout test Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "modules/vr/NavigatorVRDevice.h"
6
7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "core/dom/DOMException.h"
9 #include "core/dom/Document.h"
10 #include "core/dom/ExceptionCode.h"
11 #include "core/frame/LocalDOMWindow.h"
12 #include "core/frame/LocalFrame.h"
13 #include "core/frame/Navigator.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"
18 #include "modules/vr/VRGetDevicesCallback.h"
19 #include "modules/vr/VRHardwareUnit.h"
20 #include "modules/vr/VRHardwareUnitCollection.h"
21 #include "modules/vr/VRPositionState.h"
22 #include "wtf/PtrUtil.h"
23
24 namespace blink {
25
26 NavigatorVRDevice* NavigatorVRDevice::from(Document& document)
27 {
28 if (!document.frame() || !document.frame()->domWindow())
29 return 0;
30 Navigator& navigator = *document.frame()->domWindow()->navigator();
31 return &from(navigator);
32 }
33
34 NavigatorVRDevice& NavigatorVRDevice::from(Navigator& navigator)
35 {
36 NavigatorVRDevice* supplement = static_cast<NavigatorVRDevice*>(Supplement<N avigator>::from(navigator, supplementName()));
37 if (!supplement) {
38 supplement = new NavigatorVRDevice(navigator.frame());
39 provideTo(navigator, supplementName(), supplement);
40 }
41 return *supplement;
42 }
43
44 ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState, Navigato r& navigator)
45 {
46 return NavigatorVRDevice::from(navigator).getVRDevices(scriptState);
47 }
48
49 ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState)
50 {
51 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
52 ScriptPromise promise = resolver->promise();
53
54 Document* document = m_frame ? m_frame->document() : 0;
55
56 if (!document || !controller()) {
57 DOMException* exception = DOMException::create(InvalidStateError, "The o bject is no longer associated to a document.");
58 resolver->reject(exception);
59 return promise;
60 }
61
62 controller()->getDevices(WTF::wrapUnique(new VRGetDevicesCallback(resolver, m_hardwareUnits.get())));
63
64 return promise;
65 }
66
67 VRController* NavigatorVRDevice::controller()
68 {
69 if (!frame())
70 return 0;
71
72 return VRController::from(*frame());
73 }
74
75 DEFINE_TRACE(NavigatorVRDevice)
76 {
77 visitor->trace(m_hardwareUnits);
78
79 Supplement<Navigator>::trace(visitor);
80 DOMWindowProperty::trace(visitor);
81 }
82
83 NavigatorVRDevice::NavigatorVRDevice(LocalFrame* frame)
84 : DOMWindowProperty(frame)
85 {
86 m_hardwareUnits = new VRHardwareUnitCollection(this);
87 }
88
89 const char* NavigatorVRDevice::supplementName()
90 {
91 return "NavigatorVRDevice";
92 }
93
94 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/NavigatorVRDevice.h ('k') | third_party/WebKit/Source/modules/vr/NavigatorVRDevice.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698