| 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/NavigatorVR.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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState, Navigator& na
vigator) | 42 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState, Navigator& na
vigator) |
| 43 { | 43 { |
| 44 return NavigatorVR::from(navigator).getVRDisplays(scriptState); | 44 return NavigatorVR::from(navigator).getVRDisplays(scriptState); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) | 47 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) |
| 48 { | 48 { |
| 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 50 ScriptPromise promise = resolver->promise(); | 50 ScriptPromise promise = resolver->promise(); |
| 51 | 51 |
| 52 Document* document = m_frame ? m_frame->document() : 0; | 52 Document* document = frame() ? frame()->document() : 0; |
| 53 | 53 |
| 54 if (!document || !controller()) { | 54 if (!document || !controller()) { |
| 55 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."); |
| 56 resolver->reject(exception); | 56 resolver->reject(exception); |
| 57 return promise; | 57 return promise; |
| 58 } | 58 } |
| 59 | 59 |
| 60 UseCounter::count(*document, UseCounter::VRGetDisplays); | 60 UseCounter::count(*document, UseCounter::VRGetDisplays); |
| 61 | 61 |
| 62 controller()->getDisplays(resolver); | 62 controller()->getDisplays(resolver); |
| 63 | 63 |
| 64 return promise; | 64 return promise; |
| 65 } | 65 } |
| 66 | 66 |
| 67 VRController* NavigatorVR::controller() | 67 VRController* NavigatorVR::controller() |
| 68 { | 68 { |
| 69 if (!frame()) | 69 if (!frame()) |
| 70 return 0; | 70 return 0; |
| 71 | 71 |
| 72 if (!m_controller) { | 72 if (!m_controller) { |
| 73 m_controller = new VRController(this); | 73 m_controller = new VRController(this); |
| 74 } | 74 } |
| 75 | 75 |
| 76 return m_controller; | 76 return m_controller; |
| 77 } | 77 } |
| 78 | 78 |
| 79 Document* NavigatorVR::document() | 79 Document* NavigatorVR::document() |
| 80 { | 80 { |
| 81 return m_frame ? m_frame->document() : 0; | 81 return frame() ? frame()->document() : 0; |
| 82 } | 82 } |
| 83 | 83 |
| 84 DEFINE_TRACE(NavigatorVR) | 84 DEFINE_TRACE(NavigatorVR) |
| 85 { | 85 { |
| 86 visitor->trace(m_controller); | 86 visitor->trace(m_controller); |
| 87 | 87 |
| 88 Supplement<Navigator>::trace(visitor); | 88 Supplement<Navigator>::trace(visitor); |
| 89 DOMWindowProperty::trace(visitor); | 89 DOMWindowProperty::trace(visitor); |
| 90 } | 90 } |
| 91 | 91 |
| 92 NavigatorVR::NavigatorVR(LocalFrame* frame) | 92 NavigatorVR::NavigatorVR(LocalFrame* frame) |
| 93 : DOMWindowProperty(frame) | 93 : DOMWindowProperty(frame) |
| 94 { | 94 { |
| 95 } | 95 } |
| 96 | 96 |
| 97 NavigatorVR::~NavigatorVR() | 97 NavigatorVR::~NavigatorVR() |
| 98 { | 98 { |
| 99 } | 99 } |
| 100 | 100 |
| 101 const char* NavigatorVR::supplementName() | 101 const char* NavigatorVR::supplementName() |
| 102 { | 102 { |
| 103 return "NavigatorVR"; | 103 return "NavigatorVR"; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void NavigatorVR::fireVRDisplayPresentChange(VRDisplay* display) | 106 void NavigatorVR::fireVRDisplayPresentChange(VRDisplay* display) |
| 107 { | 107 { |
| 108 if (m_frame && m_frame->localDOMWindow()) { | 108 if (frame() && frame()->localDOMWindow()) { |
| 109 m_frame->localDOMWindow()->enqueueWindowEvent( | 109 frame()->localDOMWindow()->enqueueWindowEvent( |
| 110 VRDisplayEvent::create(EventTypeNames::vrdisplaypresentchange, true,
false, display, "")); | 110 VRDisplayEvent::create(EventTypeNames::vrdisplaypresentchange, true,
false, display, "")); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void NavigatorVR::fireVREvent(VRDisplayEvent* event) | 114 void NavigatorVR::fireVREvent(VRDisplayEvent* event) |
| 115 { | 115 { |
| 116 if (m_frame && m_frame->localDOMWindow()) { | 116 if (frame() && frame()->localDOMWindow()) { |
| 117 m_frame->localDOMWindow()->enqueueWindowEvent(event); | 117 frame()->localDOMWindow()->enqueueWindowEvent(event); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace blink | 121 } // namespace blink |
| OLD | NEW |