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

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

Issue 2305213002: Only allow VR presentation in response to a user gesture (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/VRDisplay.h" 5 #include "modules/vr/VRDisplay.h"
6 6
7 #include "core/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/Fullscreen.h" 8 #include "core/dom/Fullscreen.h"
9 #include "core/inspector/ConsoleMessage.h" 9 #include "core/inspector/ConsoleMessage.h"
10 #include "modules/vr/NavigatorVR.h" 10 #include "modules/vr/NavigatorVR.h"
11 #include "modules/vr/VRController.h" 11 #include "modules/vr/VRController.h"
12 #include "modules/vr/VRDisplayCapabilities.h" 12 #include "modules/vr/VRDisplayCapabilities.h"
13 #include "modules/vr/VREyeParameters.h" 13 #include "modules/vr/VREyeParameters.h"
14 #include "modules/vr/VRLayer.h" 14 #include "modules/vr/VRLayer.h"
15 #include "modules/vr/VRPose.h" 15 #include "modules/vr/VRPose.h"
16 #include "modules/vr/VRStageParameters.h" 16 #include "modules/vr/VRStageParameters.h"
17 #include "modules/webgl/WebGLRenderingContextBase.h" 17 #include "modules/webgl/WebGLRenderingContextBase.h"
18 #include "platform/UserGestureIndicator.h"
18 #include "public/platform/Platform.h" 19 #include "public/platform/Platform.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
22 namespace { 23 namespace {
23 24
24 VREye stringToVREye(const String& whichEye) 25 VREye stringToVREye(const String& whichEye)
25 { 26 {
26 if (whichEye == "left") 27 if (whichEye == "left")
27 return VREyeLeft; 28 return VREyeLeft;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 { 127 {
127 if (Document* document = m_navigatorVR->document()) 128 if (Document* document = m_navigatorVR->document())
128 document->cancelAnimationFrame(id); 129 document->cancelAnimationFrame(id);
129 } 130 }
130 131
131 ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState, const HeapVect or<VRLayer>& layers) 132 ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState, const HeapVect or<VRLayer>& layers)
132 { 133 {
133 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 134 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
134 ScriptPromise promise = resolver->promise(); 135 ScriptPromise promise = resolver->promise();
135 136
136 m_isPresenting = false; 137 // If the VRDisplay does not advertise the ability to present reject the req uest.
137
138 if (!m_capabilities->canPresent()) { 138 if (!m_capabilities->canPresent()) {
139 DOMException* exception = DOMException::create(InvalidStateError, "VRDis play cannot present"); 139 DOMException* exception = DOMException::create(InvalidStateError, "VRDis play cannot present.");
140 resolver->reject(exception); 140 resolver->reject(exception);
141 return promise; 141 return promise;
142 } 142 }
143 143
144 // Initiating VR presentation is only allowed in response to a user gesture.
145 // If the VRDisplay is already presenting, however, repeated calls are
146 // allowed outside a user gesture so that the presented content may be
147 // updated.
148 if (!m_isPresenting && !UserGestureIndicator::utilizeUserGesture()) {
149 DOMException* exception = DOMException::create(InvalidStateError, "API c an only be initiated by a user gesture.");
150 resolver->reject(exception);
151 return promise;
152 }
153
154 m_isPresenting = false;
155
156 // A valid number of layers must be provided in order to present.
144 if (layers.size() == 0 || layers.size() > m_capabilities->maxLayers()) { 157 if (layers.size() == 0 || layers.size() > m_capabilities->maxLayers()) {
145 DOMException* exception = DOMException::create(InvalidStateError, "Inval id number of layers."); 158 DOMException* exception = DOMException::create(InvalidStateError, "Inval id number of layers.");
146 if (m_isPresenting) { 159 if (m_isPresenting) {
147 exitPresent(scriptState); 160 exitPresent(scriptState);
148 } 161 }
149 resolver->reject(exception); 162 resolver->reject(exception);
150 return promise; 163 return promise;
151 } 164 }
152 165
153 m_layer = layers[0]; 166 m_layer = layers[0];
154 167
155 if (m_layer.source()) { 168 if (m_layer.source()) {
156 if (!m_capabilities->hasExternalDisplay()) { 169 if (!m_capabilities->hasExternalDisplay()) {
157 // TODO: Need a proper VR compositor, but for the moment on mobile 170 // TODO: Need a proper VR compositor, but for the moment on mobile
158 // we'll just make the canvas fullscreen so that VrShell can pick it 171 // we'll just make the canvas fullscreen so that VrShell can pick it
159 // up through the standard (high latency) compositing path. 172 // up through the standard (high latency) compositing path.
160 Fullscreen::from(m_layer.source()->document()).requestFullscreen(*m_ layer.source(), Fullscreen::UnprefixedRequest); 173 Fullscreen::from(m_layer.source()->document()).requestFullscreen(*m_ layer.source(), Fullscreen::UnprefixedRequest);
161 174
162 m_isPresenting = true; 175 m_isPresenting = true;
163 176
164 resolver->resolve(); 177 resolver->resolve();
165 178
166 m_navigatorVR->fireVRDisplayPresentChange(this); 179 m_navigatorVR->fireVRDisplayPresentChange(this);
167 180
168 // Check to see if the canvas is still the current fullscreen 181 // Check to see if the canvas is still the current fullscreen
169 // element once per second. 182 // element once per second.
170 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE); 183 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE);
171 } else { 184 } else {
172 DOMException* exception = DOMException::create(InvalidStateError, "V R Presentation not implemented for this VRDisplay"); 185 DOMException* exception = DOMException::create(InvalidStateError, "V R Presentation not implemented for this VRDisplay.");
173 resolver->reject(exception); 186 resolver->reject(exception);
174 } 187 }
175 } else { 188 } else {
176 DOMException* exception = DOMException::create(InvalidStateError, "Inval id layer source"); 189 DOMException* exception = DOMException::create(InvalidStateError, "Inval id layer source.");
177 resolver->reject(exception); 190 resolver->reject(exception);
178 } 191 }
179 192
180 return promise; 193 return promise;
181 } 194 }
182 195
183 ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) 196 ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState)
184 { 197 {
185 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 198 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
186 ScriptPromise promise = resolver->promise(); 199 ScriptPromise promise = resolver->promise();
187 200
188 if (!m_isPresenting) { 201 if (!m_isPresenting) {
189 // Can't stop presenting if we're not presenting. 202 // Can't stop presenting if we're not presenting.
190 DOMException* exception = DOMException::create(InvalidStateError, "VRDis play is not presenting"); 203 DOMException* exception = DOMException::create(InvalidStateError, "VRDis play is not presenting.");
191 resolver->reject(exception); 204 resolver->reject(exception);
192 return promise; 205 return promise;
193 } 206 }
194 207
195 if (!m_capabilities->hasExternalDisplay()) { 208 if (!m_capabilities->hasExternalDisplay()) {
196 Fullscreen::fullyExitFullscreen(m_layer.source()->document()); 209 Fullscreen::fullyExitFullscreen(m_layer.source()->document());
197 m_fullscreenCheckTimer.stop(); 210 m_fullscreenCheckTimer.stop();
198 } else { 211 } else {
199 // Can't get into this presentation mode, so nothing to do here. 212 // Can't get into this presentation mode, so nothing to do here.
200 } 213 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 visitor->trace(m_navigatorVR); 265 visitor->trace(m_navigatorVR);
253 visitor->trace(m_capabilities); 266 visitor->trace(m_capabilities);
254 visitor->trace(m_stageParameters); 267 visitor->trace(m_stageParameters);
255 visitor->trace(m_eyeParametersLeft); 268 visitor->trace(m_eyeParametersLeft);
256 visitor->trace(m_eyeParametersRight); 269 visitor->trace(m_eyeParametersRight);
257 visitor->trace(m_framePose); 270 visitor->trace(m_framePose);
258 visitor->trace(m_layer); 271 visitor->trace(m_layer);
259 } 272 }
260 273
261 } // namespace blink 274 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698