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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java

Issue 2539763004: Don't dispatch vrdisplayactivate event if the page that listens for it is invisible (Closed)
Patch Set: Launch to VrHomescreen when transit from a non webvr tab 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 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 package org.chromium.chrome.browser.vr_shell; 5 package org.chromium.chrome.browser.vr_shell;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.PendingIntent; 8 import android.app.PendingIntent;
9 import android.content.ComponentName; 9 import android.content.ComponentName;
10 import android.content.Intent; 10 import android.content.Intent;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 private VrCoreVersionChecker mVrCoreVersionChecker; 77 private VrCoreVersionChecker mVrCoreVersionChecker;
78 78
79 private boolean mInVr; 79 private boolean mInVr;
80 private int mRestoreSystemUiVisibilityFlag = -1; 80 private int mRestoreSystemUiVisibilityFlag = -1;
81 private int mRestoreOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIE D; 81 private int mRestoreOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIE D;
82 private long mNativeVrShellDelegate; 82 private long mNativeVrShellDelegate;
83 private Tab mTab; 83 private Tab mTab;
84 private boolean mRequestedWebVR; 84 private boolean mRequestedWebVR;
85 private long mLastVRExit; 85 private long mLastVRExit;
86 private boolean mListeningForWebVrActivate; 86 private boolean mListeningForWebVrActivate;
87 private boolean mListeningForWebVrActivateBeforePause;
87 88
88 public VrShellDelegate(ChromeTabbedActivity activity) { 89 public VrShellDelegate(ChromeTabbedActivity activity) {
89 mActivity = activity; 90 mActivity = activity;
90 91
91 mVrAvailable = createVrClassesBuilder() && isVrCoreCompatible() && creat eVrDaydreamApi() 92 mVrAvailable = createVrClassesBuilder() && isVrCoreCompatible() && creat eVrDaydreamApi()
92 && mVrDaydreamApi.isDaydreamReadyDevice(); 93 && mVrDaydreamApi.isDaydreamReadyDevice();
93 if (mVrAvailable) { 94 if (mVrAvailable) {
94 mEnterVRIntent = mVrDaydreamApi.createVrIntent( 95 mEnterVRIntent = mVrDaydreamApi.createVrIntent(
95 new ComponentName(mActivity, VR_ACTIVITY_ALIAS)); 96 new ComponentName(mActivity, VR_ACTIVITY_ALIAS));
96 } else { 97 } else {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return false; 143 return false;
143 } 144 }
144 } 145 }
145 146
146 /** 147 /**
147 * Handle a VR intent, entering VR in the process unless we're unable to. 148 * Handle a VR intent, entering VR in the process unless we're unable to.
148 */ 149 */
149 public void enterVRFromIntent(Intent intent) { 150 public void enterVRFromIntent(Intent intent) {
150 if (!mVrAvailable) return; 151 if (!mVrAvailable) return;
151 assert isVrIntent(intent); 152 assert isVrIntent(intent);
152 if (mListeningForWebVrActivate && !mRequestedWebVR) { 153 if (mListeningForWebVrActivateBeforePause && !mRequestedWebVR) {
153 nativeDisplayActivate(mNativeVrShellDelegate); 154 nativeDisplayActivate(mNativeVrShellDelegate);
154 return; 155 return;
155 } 156 }
157 if (!mListeningForWebVrActivateBeforePause && !mRequestedWebVR && !isVrS hellEnabled()) {
mthiesse 2016/11/30 22:03:32 nit: add a comment about why we have to do this.
bshe 2016/11/30 23:10:12 Done.
158 mVrDaydreamApi.launchVrHomescreen();
159 return;
160 }
156 if (enterVR()) { 161 if (enterVR()) {
157 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, true); 162 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, true);
158 } else { 163 } else {
159 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, false); 164 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, false);
160 if (!mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) { 165 if (!mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) {
161 mVrDaydreamApi.setVrModeEnabled(false); 166 mVrDaydreamApi.setVrModeEnabled(false);
162 } 167 }
163 } 168 }
164 169
165 mRequestedWebVR = false; 170 mRequestedWebVR = false;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // how VrShell was created. 275 // how VrShell was created.
271 shutdownVR(true, !isVrShellEnabled()); 276 shutdownVR(true, !isVrShellEnabled());
272 return true; 277 return true;
273 } 278 }
274 279
275 /** 280 /**
276 * Resumes VR Shell. 281 * Resumes VR Shell.
277 */ 282 */
278 public void maybeResumeVR() { 283 public void maybeResumeVR() {
279 if (!mVrAvailable) return; 284 if (!mVrAvailable) return;
280 if (isVrShellEnabled() || mListeningForWebVrActivate) { 285 if (isVrShellEnabled() || mListeningForWebVrActivateBeforePause) {
281 registerDaydreamIntent(); 286 registerDaydreamIntent();
282 } 287 }
283 // If this is still set, it means the user backed out of the DON flow, a nd we won't be 288 // If this is still set, it means the user backed out of the DON flow, a nd we won't be
284 // receiving an intent from daydream. 289 // receiving an intent from daydream.
285 if (mRequestedWebVR) { 290 if (mRequestedWebVR) {
286 nativeSetPresentResult(mNativeVrShellDelegate, false); 291 nativeSetPresentResult(mNativeVrShellDelegate, false);
287 mRequestedWebVR = false; 292 mRequestedWebVR = false;
288 } 293 }
289 294
290 // TODO(bshe): Ideally, we do not need two gvr context exist at the same time. We can 295 // TODO(bshe): Ideally, we do not need two gvr context exist at the same time. We can
(...skipping 25 matching lines...) Expand all
316 } 321 }
317 } 322 }
318 323
319 /** 324 /**
320 * Pauses VR Shell. 325 * Pauses VR Shell.
321 */ 326 */
322 public void maybePauseVR() { 327 public void maybePauseVR() {
323 if (!mVrAvailable) return; 328 if (!mVrAvailable) return;
324 unregisterDaydreamIntent(); 329 unregisterDaydreamIntent();
325 330
331 // When the active web page has a vrdisplayactivate event handler,
332 // mListeningForWebVrActivate should be set to true, which means a vrdis playactive event
333 // should be fired once DON flow finished. However, DON flow will pause our activity, which
334 // makes the active page becomes invisible. And the event fires before t he active page
335 // becomes visible again after DON finished. So here we remember the val ue of
336 // mListeningForWebVrActivity before pause and use this value to decide if vrdisplayactivate
337 // event should be dispatched in enterVRFromIntent.
338 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate;
326 if (mNonPresentingGvrContext != null) { 339 if (mNonPresentingGvrContext != null) {
327 mNonPresentingGvrContext.pause(); 340 mNonPresentingGvrContext.pause();
328 } 341 }
329 342
330 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat es with Daydream 343 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat es with Daydream
331 // home, pause instead of exiting VR here. For now, because VR Apps shou ldn't show up in the 344 // home, pause instead of exiting VR here. For now, because VR Apps shou ldn't show up in the
332 // non-VR recents, and we don't want ChromeTabbedActivity disappearing, exit VR. 345 // non-VR recents, and we don't want ChromeTabbedActivity disappearing, exit VR.
333 exitVRIfNecessary(false); 346 exitVRIfNecessary(false);
334 } 347 }
335 348
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 */ 545 */
533 @CalledByNative 546 @CalledByNative
534 private long getNativePointer() { 547 private long getNativePointer() {
535 return mNativeVrShellDelegate; 548 return mNativeVrShellDelegate;
536 } 549 }
537 550
538 private native long nativeInit(); 551 private native long nativeInit();
539 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); 552 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result);
540 private native void nativeDisplayActivate(long nativeVrShellDelegate); 553 private native void nativeDisplayActivate(long nativeVrShellDelegate);
541 } 554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698