OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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) { |
mthiesse
2016/11/30 19:02:03
Should add a block for if (!mListeningForWebVrActi
bshe
2016/11/30 19:16:28
Agree it should be fixed. But this is a different
mthiesse
2016/11/30 19:31:42
I think it's an issue that's caused by this CL, so
bshe
2016/11/30 22:01:09
Discussed offline. There is another issue which re
| |
153 nativeDisplayActivate(mNativeVrShellDelegate); | 154 nativeDisplayActivate(mNativeVrShellDelegate); |
154 return; | 155 return; |
155 } | 156 } |
156 if (enterVR()) { | 157 if (enterVR()) { |
157 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, true); | 158 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, true); |
158 } else { | 159 } else { |
159 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, false); | 160 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, false); |
160 if (!mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) { | 161 if (!mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) { |
161 mVrDaydreamApi.setVrModeEnabled(false); | 162 mVrDaydreamApi.setVrModeEnabled(false); |
162 } | 163 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 // how VrShell was created. | 271 // how VrShell was created. |
271 shutdownVR(true, !isVrShellEnabled()); | 272 shutdownVR(true, !isVrShellEnabled()); |
272 return true; | 273 return true; |
273 } | 274 } |
274 | 275 |
275 /** | 276 /** |
276 * Resumes VR Shell. | 277 * Resumes VR Shell. |
277 */ | 278 */ |
278 public void maybeResumeVR() { | 279 public void maybeResumeVR() { |
279 if (!mVrAvailable) return; | 280 if (!mVrAvailable) return; |
280 if (isVrShellEnabled() || mListeningForWebVrActivate) { | 281 if (isVrShellEnabled() || mListeningForWebVrActivateBeforePause) { |
281 registerDaydreamIntent(); | 282 registerDaydreamIntent(); |
282 } | 283 } |
283 // If this is still set, it means the user backed out of the DON flow, a nd we won't be | 284 // 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. | 285 // receiving an intent from daydream. |
285 if (mRequestedWebVR) { | 286 if (mRequestedWebVR) { |
286 nativeSetPresentResult(mNativeVrShellDelegate, false); | 287 nativeSetPresentResult(mNativeVrShellDelegate, false); |
287 mRequestedWebVR = false; | 288 mRequestedWebVR = false; |
288 } | 289 } |
289 | 290 |
290 // TODO(bshe): Ideally, we do not need two gvr context exist at the same time. We can | 291 // TODO(bshe): Ideally, we do not need two gvr context exist at the same time. We can |
(...skipping 25 matching lines...) Expand all Loading... | |
316 } | 317 } |
317 } | 318 } |
318 | 319 |
319 /** | 320 /** |
320 * Pauses VR Shell. | 321 * Pauses VR Shell. |
321 */ | 322 */ |
322 public void maybePauseVR() { | 323 public void maybePauseVR() { |
323 if (!mVrAvailable) return; | 324 if (!mVrAvailable) return; |
324 unregisterDaydreamIntent(); | 325 unregisterDaydreamIntent(); |
325 | 326 |
327 // When the active web page has a vrdisplayactivate event handler, | |
328 // mListeningForWebVrActivate should be set to true, which means a vrdis playactive event | |
329 // should be fired once DON flow finished. However, DON flow will pause our activity, which | |
330 // makes the active page becomes invisible. And the event fires before t he active page | |
331 // becomes visible again after DON finished. So here we remember the val ue of | |
332 // mListeningForWebVrActivity before pause and use this value to decide if vrdisplayactivate | |
333 // event should be dispatched in enterVRFromIntent. | |
334 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate; | |
326 if (mNonPresentingGvrContext != null) { | 335 if (mNonPresentingGvrContext != null) { |
327 mNonPresentingGvrContext.pause(); | 336 mNonPresentingGvrContext.pause(); |
328 } | 337 } |
329 | 338 |
330 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat es with Daydream | 339 // 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 | 340 // 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. | 341 // non-VR recents, and we don't want ChromeTabbedActivity disappearing, exit VR. |
333 exitVRIfNecessary(false); | 342 exitVRIfNecessary(false); |
334 } | 343 } |
335 | 344 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 */ | 541 */ |
533 @CalledByNative | 542 @CalledByNative |
534 private long getNativePointer() { | 543 private long getNativePointer() { |
535 return mNativeVrShellDelegate; | 544 return mNativeVrShellDelegate; |
536 } | 545 } |
537 | 546 |
538 private native long nativeInit(); | 547 private native long nativeInit(); |
539 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); | 548 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); |
540 private native void nativeDisplayActivate(long nativeVrShellDelegate); | 549 private native void nativeDisplayActivate(long nativeVrShellDelegate); |
541 } | 550 } |
OLD | NEW |