| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 Document* NavigatorVR::document() { | 86 Document* NavigatorVR::document() { |
| 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 PageVisibilityObserver::trace(visitor); |
| 95 } | 96 } |
| 96 | 97 |
| 97 NavigatorVR::NavigatorVR(LocalFrame* frame) : DOMWindowProperty(frame) { | 98 NavigatorVR::NavigatorVR(LocalFrame* frame) |
| 99 : DOMWindowProperty(frame), PageVisibilityObserver(frame->page()) { |
| 98 frame->localDOMWindow()->registerEventListenerObserver(this); | 100 frame->localDOMWindow()->registerEventListenerObserver(this); |
| 99 } | 101 } |
| 100 | 102 |
| 101 NavigatorVR::~NavigatorVR() {} | 103 NavigatorVR::~NavigatorVR() {} |
| 102 | 104 |
| 103 const char* NavigatorVR::supplementName() { | 105 const char* NavigatorVR::supplementName() { |
| 104 return "NavigatorVR"; | 106 return "NavigatorVR"; |
| 105 } | 107 } |
| 106 | 108 |
| 107 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { | 109 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { |
| 108 if (frame() && frame()->localDOMWindow()) { | 110 if (frame() && frame()->localDOMWindow()) { |
| 109 frame()->localDOMWindow()->enqueueWindowEvent(event); | 111 frame()->localDOMWindow()->enqueueWindowEvent(event); |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { | 115 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { |
| 114 if (frame() && frame()->localDOMWindow()) { | 116 if (frame() && frame()->localDOMWindow()) { |
| 115 UserGestureIndicator gestureIndicator( | 117 UserGestureIndicator gestureIndicator( |
| 116 DocumentUserGestureToken::create(frame()->document())); | 118 DocumentUserGestureToken::create(frame()->document())); |
| 117 event->setTarget(frame()->localDOMWindow()); | 119 event->setTarget(frame()->localDOMWindow()); |
| 118 frame()->localDOMWindow()->dispatchEvent(event); | 120 frame()->localDOMWindow()->dispatchEvent(event); |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 124 void NavigatorVR::pageVisibilityChanged() { |
| 125 if (!page()) |
| 126 return; |
| 127 if (m_controller) { |
| 128 m_controller->setListeningForActivate(page()->isPageVisible() && |
| 129 m_listeningForActivate); |
| 130 } |
| 131 } |
| 132 |
| 122 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, | 133 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, |
| 123 const AtomicString& eventType) { | 134 const AtomicString& eventType) { |
| 124 if (eventType == EventTypeNames::vrdisplayactivate) { | 135 if (eventType == EventTypeNames::vrdisplayactivate) { |
| 125 controller()->setListeningForActivate(true); | 136 controller()->setListeningForActivate(true); |
| 137 m_listeningForActivate = true; |
| 126 } else if (eventType == EventTypeNames::vrdisplayconnect) { | 138 } else if (eventType == EventTypeNames::vrdisplayconnect) { |
| 127 // If the page is listening for connection events make sure we've created a | 139 // 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. | 140 // controller so that we'll be notified of new devices. |
| 129 controller(); | 141 controller(); |
| 130 } | 142 } |
| 131 } | 143 } |
| 132 | 144 |
| 133 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, | 145 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, |
| 134 const AtomicString& eventType) { | 146 const AtomicString& eventType) { |
| 135 if (eventType == EventTypeNames::vrdisplayactivate && | 147 if (eventType == EventTypeNames::vrdisplayactivate && |
| 136 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { | 148 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { |
| 137 controller()->setListeningForActivate(false); | 149 controller()->setListeningForActivate(false); |
| 150 m_listeningForActivate = false; |
| 138 } | 151 } |
| 139 } | 152 } |
| 140 | 153 |
| 141 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { | 154 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { |
| 142 if (m_controller) { | 155 if (m_controller) { |
| 143 m_controller->setListeningForActivate(false); | 156 m_controller->setListeningForActivate(false); |
| 157 m_listeningForActivate = false; |
| 144 } | 158 } |
| 145 } | 159 } |
| 146 | 160 |
| 147 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |