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.ActivityManager; | 8 import android.app.ActivityManager; |
9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
10 import android.content.BroadcastReceiver; | 10 import android.content.BroadcastReceiver; |
(...skipping 23 matching lines...) Expand all Loading... | |
34 import org.chromium.base.Log; | 34 import org.chromium.base.Log; |
35 import org.chromium.base.ThreadUtils; | 35 import org.chromium.base.ThreadUtils; |
36 import org.chromium.base.VisibleForTesting; | 36 import org.chromium.base.VisibleForTesting; |
37 import org.chromium.base.annotations.CalledByNative; | 37 import org.chromium.base.annotations.CalledByNative; |
38 import org.chromium.base.annotations.JNINamespace; | 38 import org.chromium.base.annotations.JNINamespace; |
39 import org.chromium.base.library_loader.LibraryLoader; | 39 import org.chromium.base.library_loader.LibraryLoader; |
40 import org.chromium.chrome.R; | 40 import org.chromium.chrome.R; |
41 import org.chromium.chrome.browser.ChromeActivity; | 41 import org.chromium.chrome.browser.ChromeActivity; |
42 import org.chromium.chrome.browser.ChromeFeatureList; | 42 import org.chromium.chrome.browser.ChromeFeatureList; |
43 import org.chromium.chrome.browser.ChromeTabbedActivity; | 43 import org.chromium.chrome.browser.ChromeTabbedActivity; |
44 import org.chromium.chrome.browser.IntentHandler; | |
44 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | 45 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
45 import org.chromium.chrome.browser.infobar.InfoBarIdentifier; | 46 import org.chromium.chrome.browser.infobar.InfoBarIdentifier; |
46 import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder; | 47 import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder; |
47 import org.chromium.chrome.browser.tab.Tab; | 48 import org.chromium.chrome.browser.tab.Tab; |
48 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 49 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
49 import org.chromium.chrome.browser.webapps.WebappActivity; | 50 import org.chromium.chrome.browser.webapps.WebappActivity; |
50 | 51 |
51 import java.lang.annotation.Retention; | 52 import java.lang.annotation.Retention; |
52 import java.lang.annotation.RetentionPolicy; | 53 import java.lang.annotation.RetentionPolicy; |
53 import java.lang.ref.WeakReference; | 54 import java.lang.ref.WeakReference; |
(...skipping 20 matching lines...) Expand all Loading... | |
74 private @interface EnterVRResult {} | 75 private @interface EnterVRResult {} |
75 | 76 |
76 private static final int VR_NOT_AVAILABLE = 0; | 77 private static final int VR_NOT_AVAILABLE = 0; |
77 private static final int VR_CARDBOARD = 1; | 78 private static final int VR_CARDBOARD = 1; |
78 private static final int VR_DAYDREAM = 2; // Supports both Cardboard and Day dream viewer. | 79 private static final int VR_DAYDREAM = 2; // Supports both Cardboard and Day dream viewer. |
79 | 80 |
80 @Retention(RetentionPolicy.SOURCE) | 81 @Retention(RetentionPolicy.SOURCE) |
81 @IntDef({VR_NOT_AVAILABLE, VR_CARDBOARD, VR_DAYDREAM}) | 82 @IntDef({VR_NOT_AVAILABLE, VR_CARDBOARD, VR_DAYDREAM}) |
82 private @interface VrSupportLevel {} | 83 private @interface VrSupportLevel {} |
83 | 84 |
85 private static final String DAYDREAM_VR_EXTRA = "android.intent.extra.VR_LAU NCH"; | |
86 | |
84 // Linter and formatter disagree on how the line below should be formatted. | 87 // Linter and formatter disagree on how the line below should be formatted. |
85 /* package */ | 88 /* package */ |
86 static final String VR_ENTRY_RESULT_ACTION = | 89 static final String VR_ENTRY_RESULT_ACTION = |
87 "org.chromium.chrome.browser.vr_shell.VrEntryResult"; | 90 "org.chromium.chrome.browser.vr_shell.VrEntryResult"; |
88 | 91 |
89 private static final long REENTER_VR_TIMEOUT_MS = 1000; | 92 private static final long REENTER_VR_TIMEOUT_MS = 1000; |
90 | 93 |
91 private static final int VR_SYSTEM_UI_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_STA BLE | 94 private static final int VR_SYSTEM_UI_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_STA BLE |
92 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_L AYOUT_FULLSCREEN | 95 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_L AYOUT_FULLSCREEN |
93 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCRE EN | 96 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCRE EN |
(...skipping 24 matching lines...) Expand all Loading... | |
118 // See further documentation here: https://developers.google.com/vr/daydream /guides/vr-entry | 121 // See further documentation here: https://developers.google.com/vr/daydream /guides/vr-entry |
119 private boolean mDonSucceeded; | 122 private boolean mDonSucceeded; |
120 private boolean mPaused; | 123 private boolean mPaused; |
121 private int mRestoreSystemUiVisibilityFlag = -1; | 124 private int mRestoreSystemUiVisibilityFlag = -1; |
122 private Integer mRestoreOrientation = null; | 125 private Integer mRestoreOrientation = null; |
123 private long mNativeVrShellDelegate; | 126 private long mNativeVrShellDelegate; |
124 private boolean mRequestedWebVr; | 127 private boolean mRequestedWebVr; |
125 private long mLastVrExit; | 128 private long mLastVrExit; |
126 private boolean mListeningForWebVrActivate; | 129 private boolean mListeningForWebVrActivate; |
127 private boolean mListeningForWebVrActivateBeforePause; | 130 private boolean mListeningForWebVrActivateBeforePause; |
131 // Whether or not we should autopresent WebVr. If this is set, it means that a first | |
132 // party app (e.g Daydream home) has asked us to autopresent WebVr content a nd we're waiting | |
133 // for the WebVr content to call requestPresent. | |
134 private boolean mAutopresentWebVr = false; | |
mthiesse
2017/05/10 14:52:14
To be on the safe side, you probably also want to
Ted C
2017/05/11 00:05:03
false/null/0 are defaults in java and including th
ymalik
2017/05/11 03:32:27
Are you referring to WebVr to WebVr? I thought tha
| |
128 | 135 |
129 private static class VrBroadcastReceiver extends BroadcastReceiver { | 136 private static class VrBroadcastReceiver extends BroadcastReceiver { |
130 private final WeakReference<ChromeActivity> mTargetActivity; | 137 private final WeakReference<ChromeActivity> mTargetActivity; |
131 | 138 |
132 public VrBroadcastReceiver(ChromeActivity activity) { | 139 public VrBroadcastReceiver(ChromeActivity activity) { |
133 mTargetActivity = new WeakReference<ChromeActivity>(activity); | 140 mTargetActivity = new WeakReference<ChromeActivity>(activity); |
134 } | 141 } |
135 | 142 |
136 @Override | 143 @Override |
137 public void onReceive(Context context, Intent intent) { | 144 public void onReceive(Context context, Intent intent) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 mVrShell.setWebVrModeEnabled(mRequestedWebVr || tentativeWebVrMode); | 512 mVrShell.setWebVrModeEnabled(mRequestedWebVr || tentativeWebVrMode); |
506 | 513 |
507 // onResume needs to be called on GvrLayout after initialization to make sure DON flow work | 514 // onResume needs to be called on GvrLayout after initialization to make sure DON flow work |
508 // properly. | 515 // properly. |
509 mVrShell.resume(); | 516 mVrShell.resume(); |
510 | 517 |
511 maybeSetPresentResult(true); | 518 maybeSetPresentResult(true); |
512 mVrShell.getContainer().setOnSystemUiVisibilityChangeListener(this); | 519 mVrShell.getContainer().setOnSystemUiVisibilityChangeListener(this); |
513 } | 520 } |
514 | 521 |
522 private boolean launchInVr() { | |
523 if (mVrDaydreamApi == null || mActivity == null) return false; | |
mthiesse
2017/05/10 14:52:14
mActivity should never be null. If you're worried,
ymalik
2017/05/11 03:32:27
Done.
| |
524 return mVrDaydreamApi.launchInVr(getEnterVrPendingIntent(mActivity)); | |
525 } | |
526 | |
527 private void onAutopresentIntent() { | |
528 // Autopresent intents are only expected from trusted first party apps w hile | |
529 // we're not in vr (e.g. deep-linked from day dream home). | |
530 assert !mInVr; | |
531 mAutopresentWebVr = true; | |
532 } | |
533 | |
534 /** | |
535 * This is called every time ChromeActivity gets a intent. Its currently use d to | |
536 * autopresent WebVr from Daydream Home. | |
537 */ | |
538 public static void onNewIntent(ChromeActivity activity, Intent intent) { | |
Ted C
2017/05/11 00:05:03
you should probably return a boolean here to give
ymalik
2017/05/11 03:32:27
That's right. This intent will have the url as wel
| |
539 if (intent.getBooleanExtra(DAYDREAM_VR_EXTRA, false) && activity.canAuto presentVr() | |
540 && IntentHandler.isIntentChromeOrFirstParty(intent)) { | |
541 VrShellDelegate instance = getInstance(activity); | |
542 if (instance == null) return; | |
543 Log.i(TAG, String.format("received intent to autopresent WebVr")); | |
mthiesse
2017/05/10 14:52:14
No need for String.format. Probably no need for th
ymalik
2017/05/11 03:32:27
Done.
| |
544 instance.onAutopresentIntent(); | |
545 } | |
546 } | |
547 | |
515 @Override | 548 @Override |
516 public void onSystemUiVisibilityChange(int visibility) { | 549 public void onSystemUiVisibilityChange(int visibility) { |
517 if (mInVr && !isWindowModeCorrectForVr()) { | 550 if (mInVr && !isWindowModeCorrectForVr()) { |
518 setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 551 setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
519 } | 552 } |
520 } | 553 } |
521 | 554 |
522 private boolean isWindowModeCorrectForVr() { | 555 private boolean isWindowModeCorrectForVr() { |
523 int flags = mActivity.getWindow().getDecorView().getSystemUiVisibility() ; | 556 int flags = mActivity.getWindow().getDecorView().getSystemUiVisibility() ; |
524 int orientation = mActivity.getResources().getConfiguration().orientatio n; | 557 int orientation = mActivity.getResources().getConfiguration().orientatio n; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 // For now we don't handle sad tab page. crbug.com/661609 | 590 // For now we don't handle sad tab page. crbug.com/661609 |
558 if (tab.isShowingSadTab()) { | 591 if (tab.isShowingSadTab()) { |
559 return false; | 592 return false; |
560 } | 593 } |
561 return true; | 594 return true; |
562 } | 595 } |
563 | 596 |
564 @CalledByNative | 597 @CalledByNative |
565 private void presentRequested() { | 598 private void presentRequested() { |
566 mRequestedWebVr = true; | 599 mRequestedWebVr = true; |
600 mAutopresentWebVr = false; | |
567 switch (enterVrInternal()) { | 601 switch (enterVrInternal()) { |
568 case ENTER_VR_NOT_NECESSARY: | 602 case ENTER_VR_NOT_NECESSARY: |
569 mVrShell.setWebVrModeEnabled(true); | 603 mVrShell.setWebVrModeEnabled(true); |
570 maybeSetPresentResult(true); | 604 maybeSetPresentResult(true); |
571 break; | 605 break; |
572 case ENTER_VR_CANCELLED: | 606 case ENTER_VR_CANCELLED: |
573 maybeSetPresentResult(false); | 607 maybeSetPresentResult(false); |
574 break; | 608 break; |
575 case ENTER_VR_REQUESTED: | 609 case ENTER_VR_REQUESTED: |
576 break; | 610 break; |
(...skipping 18 matching lines...) Expand all Loading... | |
595 | 629 |
596 if (mVrSupportLevel == VR_CARDBOARD || !mVrDaydreamApi.isDaydreamCurrent Viewer()) { | 630 if (mVrSupportLevel == VR_CARDBOARD || !mVrDaydreamApi.isDaydreamCurrent Viewer()) { |
597 // Avoid using launchInVr which would trigger DON flow regardless cu rrent viewer type | 631 // Avoid using launchInVr which would trigger DON flow regardless cu rrent viewer type |
598 // due to the lack of support for unexported activities. | 632 // due to the lack of support for unexported activities. |
599 enterVr(false); | 633 enterVr(false); |
600 } else { | 634 } else { |
601 // LANDSCAPE orientation is needed before we can safely enter VR. DO N can make sure that | 635 // LANDSCAPE orientation is needed before we can safely enter VR. DO N can make sure that |
602 // the device is at LANDSCAPE orientation once it is finished. So he re we use SENSOR to | 636 // the device is at LANDSCAPE orientation once it is finished. So he re we use SENSOR to |
603 // avoid forcing LANDSCAPE orientation in order to have a smoother t ransition. | 637 // avoid forcing LANDSCAPE orientation in order to have a smoother t ransition. |
604 setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_SENSOR); | 638 setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_SENSOR); |
605 if (!mVrDaydreamApi.launchInVr(getEnterVrPendingIntent(mActivity))) { | 639 if (!launchInVr()) { |
606 restoreWindowMode(); | 640 restoreWindowMode(); |
607 return ENTER_VR_CANCELLED; | 641 return ENTER_VR_CANCELLED; |
608 } | 642 } |
609 } | 643 } |
610 return ENTER_VR_REQUESTED; | 644 return ENTER_VR_REQUESTED; |
611 } | 645 } |
612 | 646 |
613 @CalledByNative | 647 @CalledByNative |
614 private boolean exitWebVRPresent() { | 648 private boolean exitWebVRPresent() { |
615 if (!mInVr) return false; | 649 if (!mInVr) return false; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 } | 759 } |
726 | 760 |
727 @CalledByNative | 761 @CalledByNative |
728 private void setListeningForWebVrActivate(boolean listening) { | 762 private void setListeningForWebVrActivate(boolean listening) { |
729 // Non-Daydream devices may not have the concept of display activate. So disable | 763 // Non-Daydream devices may not have the concept of display activate. So disable |
730 // mListeningForWebVrActivate for them. | 764 // mListeningForWebVrActivate for them. |
731 if (mVrSupportLevel != VR_DAYDREAM) return; | 765 if (mVrSupportLevel != VR_DAYDREAM) return; |
732 mListeningForWebVrActivate = listening; | 766 mListeningForWebVrActivate = listening; |
733 if (listening && !mPaused) { | 767 if (listening && !mPaused) { |
734 registerDaydreamIntent(mVrDaydreamApi, mActivity); | 768 registerDaydreamIntent(mVrDaydreamApi, mActivity); |
769 if (mAutopresentWebVr) { | |
770 // Dispatch vrdisplayactivate so that the WebVr page can call re questPresent | |
771 // to start presentation. | |
772 // TODO(ymalik): There will be a delay between when we're asked to autopresent and | |
773 // when the WebVr site calls requestPresent. In this time, the u ser sees 2D Chrome | |
774 // UI which is suboptimal. | |
775 nativeDisplayActivate(mNativeVrShellDelegate); | |
776 } | |
735 } else { | 777 } else { |
736 unregisterDaydreamIntent(mVrDaydreamApi); | 778 unregisterDaydreamIntent(mVrDaydreamApi); |
737 } | 779 } |
738 } | 780 } |
739 | 781 |
740 /** | 782 /** |
741 * Exits VR Shell, performing all necessary cleanup. | 783 * Exits VR Shell, performing all necessary cleanup. |
742 */ | 784 */ |
743 /* package */ void shutdownVr(boolean isPausing, boolean showTransition) { | 785 /* package */ void shutdownVr(boolean isPausing, boolean showTransition) { |
744 if (!mInVr) return; | 786 if (!mInVr) return; |
745 mInVr = false; | 787 mInVr = false; |
746 mRequestedWebVr = false; | 788 mRequestedWebVr = false; |
789 mAutopresentWebVr = false; | |
747 // Transition screen is not available for Cardboard only (non-Daydream) devices. | 790 // Transition screen is not available for Cardboard only (non-Daydream) devices. |
748 // TODO(bshe): Fix this once b/33490788 is fixed. | 791 // TODO(bshe): Fix this once b/33490788 is fixed. |
749 boolean transition = mVrSupportLevel == VR_DAYDREAM && showTransition; | 792 boolean transition = mVrSupportLevel == VR_DAYDREAM && showTransition; |
750 if (!isPausing) { | 793 if (!isPausing) { |
751 if (!transition || !mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new In tent())) { | 794 if (!transition || !mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new In tent())) { |
752 mVrClassesWrapper.setVrModeEnabled(mActivity, false); | 795 mVrClassesWrapper.setVrModeEnabled(mActivity, false); |
753 } | 796 } |
754 } else { | 797 } else { |
755 mVrClassesWrapper.setVrModeEnabled(mActivity, false); | 798 mVrClassesWrapper.setVrModeEnabled(mActivity, false); |
756 mLastVrExit = SystemClock.uptimeMillis(); | 799 mLastVrExit = SystemClock.uptimeMillis(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 private native long nativeInit(); | 957 private native long nativeInit(); |
915 private static native void nativeOnLibraryAvailable(); | 958 private static native void nativeOnLibraryAvailable(); |
916 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); | 959 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); |
917 private native void nativeDisplayActivate(long nativeVrShellDelegate); | 960 private native void nativeDisplayActivate(long nativeVrShellDelegate); |
918 private native void nativeUpdateVSyncInterval(long nativeVrShellDelegate, lo ng timebaseNanos, | 961 private native void nativeUpdateVSyncInterval(long nativeVrShellDelegate, lo ng timebaseNanos, |
919 double intervalSeconds); | 962 double intervalSeconds); |
920 private native void nativeOnPause(long nativeVrShellDelegate); | 963 private native void nativeOnPause(long nativeVrShellDelegate); |
921 private native void nativeOnResume(long nativeVrShellDelegate); | 964 private native void nativeOnResume(long nativeVrShellDelegate); |
922 private native void nativeDestroy(long nativeVrShellDelegate); | 965 private native void nativeDestroy(long nativeVrShellDelegate); |
923 } | 966 } |
OLD | NEW |