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

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

Issue 2668003003: Provide WebVR pose data only to the focused frame. (Closed)
Patch Set: Address comment Created 3 years, 10 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
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"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/dom/Fullscreen.h" 12 #include "core/dom/Fullscreen.h"
13 #include "core/frame/LocalDOMWindow.h" 13 #include "core/frame/LocalDOMWindow.h"
14 #include "core/frame/LocalFrame.h" 14 #include "core/frame/LocalFrame.h"
15 #include "core/frame/Navigator.h" 15 #include "core/frame/Navigator.h"
16 #include "core/frame/UseCounter.h" 16 #include "core/frame/UseCounter.h"
17 #include "core/page/FocusController.h"
17 #include "core/page/Page.h" 18 #include "core/page/Page.h"
18 #include "modules/vr/VRController.h" 19 #include "modules/vr/VRController.h"
19 #include "modules/vr/VRDisplay.h" 20 #include "modules/vr/VRDisplay.h"
20 #include "modules/vr/VRGetDevicesCallback.h" 21 #include "modules/vr/VRGetDevicesCallback.h"
21 #include "modules/vr/VRPose.h" 22 #include "modules/vr/VRPose.h"
22 #include "platform/UserGestureIndicator.h" 23 #include "platform/UserGestureIndicator.h"
23 #include "public/platform/Platform.h" 24 #include "public/platform/Platform.h"
24 #include "wtf/PtrUtil.h" 25 #include "wtf/PtrUtil.h"
25 26
26 namespace blink { 27 namespace blink {
27 28
29 namespace {
30 bool isFrameFocused(LocalFrame* frame) {
haraken 2017/02/03 18:46:18 I'd move this to FocusChangedObserver.
mthiesse 2017/02/03 20:47:29 Done.
31 if (!frame)
32 return false;
33 Page* page = frame->page();
34 if (!page)
35 return false;
36 const FocusController& controller = page->focusController();
37 return controller.isFocused() && (controller.focusedOrMainFrame() == frame);
38 }
39 } // namespace
40
28 NavigatorVR* NavigatorVR::from(Document& document) { 41 NavigatorVR* NavigatorVR::from(Document& document) {
29 if (!document.frame() || !document.frame()->domWindow()) 42 if (!document.frame() || !document.frame()->domWindow())
30 return 0; 43 return 0;
31 Navigator& navigator = *document.frame()->domWindow()->navigator(); 44 Navigator& navigator = *document.frame()->domWindow()->navigator();
32 return &from(navigator); 45 return &from(navigator);
33 } 46 }
34 47
35 NavigatorVR& NavigatorVR::from(Navigator& navigator) { 48 NavigatorVR& NavigatorVR::from(Navigator& navigator) {
36 NavigatorVR* supplement = static_cast<NavigatorVR*>( 49 NavigatorVR* supplement = static_cast<NavigatorVR*>(
37 Supplement<Navigator>::from(navigator, supplementName())); 50 Supplement<Navigator>::from(navigator, supplementName()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 83
71 return promise; 84 return promise;
72 } 85 }
73 86
74 VRController* NavigatorVR::controller() { 87 VRController* NavigatorVR::controller() {
75 if (!supplementable()->frame()) 88 if (!supplementable()->frame())
76 return 0; 89 return 0;
77 90
78 if (!m_controller) { 91 if (!m_controller) {
79 m_controller = new VRController(this); 92 m_controller = new VRController(this);
93 m_controller->setListeningForActivate(m_focused && m_listeningForActivate);
94 m_controller->focusChanged(m_focused);
80 } 95 }
81 96
82 return m_controller; 97 return m_controller;
83 } 98 }
84 99
85 Document* NavigatorVR::document() { 100 Document* NavigatorVR::document() {
86 return supplementable()->frame() ? supplementable()->frame()->document() 101 return supplementable()->frame() ? supplementable()->frame()->document()
87 : nullptr; 102 : nullptr;
88 } 103 }
89 104
90 DEFINE_TRACE(NavigatorVR) { 105 DEFINE_TRACE(NavigatorVR) {
91 visitor->trace(m_controller); 106 visitor->trace(m_controller);
92 Supplement<Navigator>::trace(visitor); 107 Supplement<Navigator>::trace(visitor);
93 PageVisibilityObserver::trace(visitor);
94 } 108 }
95 109
96 NavigatorVR::NavigatorVR(Navigator& navigator) 110 NavigatorVR::NavigatorVR(Navigator& navigator)
97 : Supplement<Navigator>(navigator), 111 : Supplement<Navigator>(navigator) {
98 PageVisibilityObserver(navigator.frame()->page()) {
99 navigator.frame()->domWindow()->registerEventListenerObserver(this); 112 navigator.frame()->domWindow()->registerEventListenerObserver(this);
113 navigator.frame()->page()->focusController().registerFocusChangedObserver(
114 this);
115 focusedFrameChanged();
100 } 116 }
101 117
102 NavigatorVR::~NavigatorVR() {} 118 NavigatorVR::~NavigatorVR() {}
103 119
104 const char* NavigatorVR::supplementName() { 120 const char* NavigatorVR::supplementName() {
105 return "NavigatorVR"; 121 return "NavigatorVR";
106 } 122 }
107 123
108 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { 124 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) {
109 if (supplementable()->frame()) { 125 if (supplementable()->frame()) {
110 supplementable()->frame()->domWindow()->enqueueWindowEvent(event); 126 supplementable()->frame()->domWindow()->enqueueWindowEvent(event);
111 } 127 }
112 } 128 }
113 129
114 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { 130 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) {
115 if (!(supplementable()->frame())) 131 if (!(supplementable()->frame()))
116 return; 132 return;
117 UserGestureIndicator gestureIndicator( 133 UserGestureIndicator gestureIndicator(
118 DocumentUserGestureToken::create(document())); 134 DocumentUserGestureToken::create(document()));
119 LocalDOMWindow* window = supplementable()->frame()->domWindow(); 135 LocalDOMWindow* window = supplementable()->frame()->domWindow();
120 DCHECK(window); 136 DCHECK(window);
121 event->setTarget(window); 137 event->setTarget(window);
122 window->dispatchEvent(event); 138 window->dispatchEvent(event);
123 } 139 }
124 140
125 void NavigatorVR::pageVisibilityChanged() { 141 void NavigatorVR::focusedFrameChanged() {
126 if (!page()) 142 bool focused = isFrameFocused(supplementable()->frame());
143 if (focused == m_focused)
127 return; 144 return;
145 m_focused = focused;
128 if (m_controller) { 146 if (m_controller) {
129 m_controller->setListeningForActivate(page()->isPageVisible() && 147 m_controller->setListeningForActivate(m_listeningForActivate && focused);
130 m_listeningForActivate); 148 m_controller->focusChanged(focused);
131 } 149 }
132 } 150 }
133 151
134 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, 152 void NavigatorVR::didAddEventListener(LocalDOMWindow* window,
135 const AtomicString& eventType) { 153 const AtomicString& eventType) {
136 // TODO(mthiesse): Remove fullscreen requirement for presentation. See 154 // TODO(mthiesse): Remove fullscreen requirement for presentation. See
137 // crbug.com/687369 155 // crbug.com/687369
138 if (eventType == EventTypeNames::vrdisplayactivate && 156 if (eventType == EventTypeNames::vrdisplayactivate &&
139 supplementable()->frame() && supplementable()->frame()->document() && 157 supplementable()->frame() && supplementable()->frame()->document() &&
140 Fullscreen::fullscreenEnabled(*supplementable()->frame()->document())) { 158 Fullscreen::fullscreenEnabled(*supplementable()->frame()->document())) {
141 controller()->setListeningForActivate(true);
142 m_listeningForActivate = true; 159 m_listeningForActivate = true;
160 controller()->setListeningForActivate(m_focused);
143 } else if (eventType == EventTypeNames::vrdisplayconnect) { 161 } else if (eventType == EventTypeNames::vrdisplayconnect) {
144 // If the page is listening for connection events make sure we've created a 162 // If the page is listening for connection events make sure we've created a
145 // controller so that we'll be notified of new devices. 163 // controller so that we'll be notified of new devices.
146 controller(); 164 controller();
147 } 165 }
148 } 166 }
149 167
150 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, 168 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window,
151 const AtomicString& eventType) { 169 const AtomicString& eventType) {
152 if (eventType == EventTypeNames::vrdisplayactivate && 170 if (eventType == EventTypeNames::vrdisplayactivate &&
153 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { 171 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) {
172 m_listeningForActivate = false;
154 controller()->setListeningForActivate(false); 173 controller()->setListeningForActivate(false);
155 m_listeningForActivate = false;
156 } 174 }
157 } 175 }
158 176
159 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { 177 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) {
160 if (m_controller) { 178 if (m_controller) {
161 m_controller->setListeningForActivate(false); 179 m_controller->setListeningForActivate(false);
162 m_listeningForActivate = false; 180 m_listeningForActivate = false;
163 } 181 }
164 } 182 }
165 183
166 } // namespace blink 184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698