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) { |
153 nativeDisplayActivate(mNativeVrShellDelegate); | 154 nativeDisplayActivate(mNativeVrShellDelegate); |
154 return; | 155 return; |
155 } | 156 } |
| 157 // Normally, if the active page doesn't have a vrdisplayactivate listene
r, and WebVR was not |
| 158 // presenting and VrShell was not enabled, we shouldn't enter VR and Day
dream Homescreen |
| 159 // should show after DON flow. But due to a failure in unregisterDaydrea
mIntent, we still |
| 160 // try to enterVR. Here we detect this case and force switch to Daydream
Homescreen. |
| 161 if (!mListeningForWebVrActivateBeforePause && !mRequestedWebVR && !isVrS
hellEnabled()) { |
| 162 mVrDaydreamApi.launchVrHomescreen(); |
| 163 return; |
| 164 } |
156 if (enterVR()) { | 165 if (enterVR()) { |
157 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate,
true); | 166 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate,
true); |
158 } else { | 167 } else { |
159 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate,
false); | 168 if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate,
false); |
160 if (!mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) { | 169 if (!mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) { |
161 mVrDaydreamApi.setVrModeEnabled(false); | 170 mVrDaydreamApi.setVrModeEnabled(false); |
162 } | 171 } |
163 } | 172 } |
164 | 173 |
165 mRequestedWebVR = false; | 174 mRequestedWebVR = false; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // how VrShell was created. | 279 // how VrShell was created. |
271 shutdownVR(true, !isVrShellEnabled()); | 280 shutdownVR(true, !isVrShellEnabled()); |
272 return true; | 281 return true; |
273 } | 282 } |
274 | 283 |
275 /** | 284 /** |
276 * Resumes VR Shell. | 285 * Resumes VR Shell. |
277 */ | 286 */ |
278 public void maybeResumeVR() { | 287 public void maybeResumeVR() { |
279 if (!mVrAvailable) return; | 288 if (!mVrAvailable) return; |
280 if (isVrShellEnabled() || mListeningForWebVrActivate) { | 289 if (isVrShellEnabled() || mListeningForWebVrActivateBeforePause) { |
281 registerDaydreamIntent(); | 290 registerDaydreamIntent(); |
282 } | 291 } |
283 // If this is still set, it means the user backed out of the DON flow, a
nd we won't be | 292 // 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. | 293 // receiving an intent from daydream. |
285 if (mRequestedWebVR) { | 294 if (mRequestedWebVR) { |
286 nativeSetPresentResult(mNativeVrShellDelegate, false); | 295 nativeSetPresentResult(mNativeVrShellDelegate, false); |
287 mRequestedWebVR = false; | 296 mRequestedWebVR = false; |
288 } | 297 } |
289 | 298 |
290 // TODO(bshe): Ideally, we do not need two gvr context exist at the same
time. We can | 299 // 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 } | 325 } |
317 } | 326 } |
318 | 327 |
319 /** | 328 /** |
320 * Pauses VR Shell. | 329 * Pauses VR Shell. |
321 */ | 330 */ |
322 public void maybePauseVR() { | 331 public void maybePauseVR() { |
323 if (!mVrAvailable) return; | 332 if (!mVrAvailable) return; |
324 unregisterDaydreamIntent(); | 333 unregisterDaydreamIntent(); |
325 | 334 |
| 335 // When the active web page has a vrdisplayactivate event handler, |
| 336 // mListeningForWebVrActivate should be set to true, which means a vrdis
playactive event |
| 337 // should be fired once DON flow finished. However, DON flow will pause
our activity, which |
| 338 // makes the active page becomes invisible. And the event fires before t
he active page |
| 339 // becomes visible again after DON finished. So here we remember the val
ue of |
| 340 // mListeningForWebVrActivity before pause and use this value to decide
if vrdisplayactivate |
| 341 // event should be dispatched in enterVRFromIntent. |
| 342 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate; |
326 if (mNonPresentingGvrContext != null) { | 343 if (mNonPresentingGvrContext != null) { |
327 mNonPresentingGvrContext.pause(); | 344 mNonPresentingGvrContext.pause(); |
328 } | 345 } |
329 | 346 |
330 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat
es with Daydream | 347 // 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 | 348 // 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. | 349 // non-VR recents, and we don't want ChromeTabbedActivity disappearing,
exit VR. |
333 exitVRIfNecessary(false); | 350 exitVRIfNecessary(false); |
334 } | 351 } |
335 | 352 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 */ | 549 */ |
533 @CalledByNative | 550 @CalledByNative |
534 private long getNativePointer() { | 551 private long getNativePointer() { |
535 return mNativeVrShellDelegate; | 552 return mNativeVrShellDelegate; |
536 } | 553 } |
537 | 554 |
538 private native long nativeInit(); | 555 private native long nativeInit(); |
539 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole
an result); | 556 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole
an result); |
540 private native void nativeDisplayActivate(long nativeVrShellDelegate); | 557 private native void nativeDisplayActivate(long nativeVrShellDelegate); |
541 } | 558 } |
OLD | NEW |