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

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

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

Powered by Google App Engine
This is Rietveld 408576698