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/DocumentUserGestureToken.h" | 10 #include "core/dom/DocumentUserGestureToken.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 return frame() ? frame()->document() : 0; | 87 return frame() ? frame()->document() : 0; |
88 } | 88 } |
89 | 89 |
90 DEFINE_TRACE(NavigatorVR) { | 90 DEFINE_TRACE(NavigatorVR) { |
91 visitor->trace(m_controller); | 91 visitor->trace(m_controller); |
92 | 92 |
93 Supplement<Navigator>::trace(visitor); | 93 Supplement<Navigator>::trace(visitor); |
94 DOMWindowProperty::trace(visitor); | 94 DOMWindowProperty::trace(visitor); |
95 } | 95 } |
96 | 96 |
97 NavigatorVR::NavigatorVR(LocalFrame* frame) : DOMWindowProperty(frame) {} | 97 NavigatorVR::NavigatorVR(LocalFrame* frame) : DOMWindowProperty(frame) { |
| 98 frame->localDOMWindow()->registerEventListenerObserver(this); |
| 99 } |
98 | 100 |
99 NavigatorVR::~NavigatorVR() {} | 101 NavigatorVR::~NavigatorVR() {} |
100 | 102 |
101 const char* NavigatorVR::supplementName() { | 103 const char* NavigatorVR::supplementName() { |
102 return "NavigatorVR"; | 104 return "NavigatorVR"; |
103 } | 105 } |
104 | 106 |
105 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { | 107 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { |
106 if (frame() && frame()->localDOMWindow()) { | 108 if (frame() && frame()->localDOMWindow()) { |
107 frame()->localDOMWindow()->enqueueWindowEvent(event); | 109 frame()->localDOMWindow()->enqueueWindowEvent(event); |
108 } | 110 } |
109 } | 111 } |
110 | 112 |
111 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { | 113 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { |
112 if (frame() && frame()->localDOMWindow()) { | 114 if (frame() && frame()->localDOMWindow()) { |
113 UserGestureIndicator gestureIndicator( | 115 UserGestureIndicator gestureIndicator( |
114 DocumentUserGestureToken::create(frame()->document())); | 116 DocumentUserGestureToken::create(frame()->document())); |
115 event->setTarget(frame()->localDOMWindow()); | 117 event->setTarget(frame()->localDOMWindow()); |
116 frame()->localDOMWindow()->dispatchEvent(event); | 118 frame()->localDOMWindow()->dispatchEvent(event); |
117 } | 119 } |
118 } | 120 } |
119 | 121 |
| 122 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, |
| 123 const AtomicString& eventType) { |
| 124 if (eventType == EventTypeNames::vrdisplayactivate) { |
| 125 controller()->setListeningForActivate(true); |
| 126 } else if (eventType == EventTypeNames::vrdisplayconnect) { |
| 127 // If the page is listening for connection events make sure we've created a |
| 128 // controller so that we'll be notified of new devices. |
| 129 controller(); |
| 130 } |
| 131 } |
| 132 |
| 133 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, |
| 134 const AtomicString& eventType) { |
| 135 if (eventType == EventTypeNames::vrdisplayactivate && |
| 136 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { |
| 137 controller()->setListeningForActivate(false); |
| 138 } |
| 139 } |
| 140 |
| 141 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { |
| 142 if (m_controller) { |
| 143 m_controller->setListeningForActivate(false); |
| 144 } |
| 145 } |
| 146 |
120 } // namespace blink | 147 } // namespace blink |
OLD | NEW |