Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| index 6ea8491b9e3b41178fd4b9e600c6f154c81474e1..b8e9dedeff99295cace07a8e7678f30e90929943 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| @@ -41,6 +41,7 @@ import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.ChromeActivity; |
| import org.chromium.chrome.browser.ChromeFeatureList; |
| import org.chromium.chrome.browser.ChromeTabbedActivity; |
| +import org.chromium.chrome.browser.IntentHandler; |
| import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
| import org.chromium.chrome.browser.infobar.InfoBarIdentifier; |
| import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder; |
| @@ -81,6 +82,8 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| @IntDef({VR_NOT_AVAILABLE, VR_CARDBOARD, VR_DAYDREAM}) |
| private @interface VrSupportLevel {} |
| + private static final String DAYDREAM_VR_EXTRA = "android.intent.extra.VR_LAUNCH"; |
| + |
| // Linter and formatter disagree on how the line below should be formatted. |
| /* package */ |
| static final String VR_ENTRY_RESULT_ACTION = |
| @@ -125,6 +128,10 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| private long mLastVrExit; |
| private boolean mListeningForWebVrActivate; |
| private boolean mListeningForWebVrActivateBeforePause; |
| + // Whether or not we should autopresent WebVr. If this is set, it means that a first |
| + // party app (e.g Daydream home) has asked us to autopresent WebVr content and we're waiting |
| + // for the WebVr content to call requestPresent. |
| + private boolean mAutopresentWebVr; |
| private static class VrBroadcastReceiver extends BroadcastReceiver { |
| private final WeakReference<ChromeActivity> mTargetActivity; |
| @@ -309,6 +316,10 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| || activity instanceof WebappActivity; |
| } |
| + private static boolean activitySupportsAutopresentation(Activity activity) { |
| + return activity instanceof ChromeTabbedActivity; |
| + } |
| + |
| private static boolean activitySupportsVrBrowsing(Activity activity) { |
| return activity instanceof ChromeTabbedActivity || activity instanceof CustomTabActivity; |
| } |
| @@ -512,6 +523,34 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| mVrShell.getContainer().setOnSystemUiVisibilityChangeListener(this); |
| } |
| + private boolean launchInVr() { |
| + assert mActivity != null && mVrSupportLevel != VR_NOT_AVAILABLE; |
| + return mVrDaydreamApi.launchInVr(getEnterVrPendingIntent(mActivity)); |
| + } |
| + |
| + private void onAutopresentIntent() { |
| + // Autopresent intents are only expected from trusted first party apps while |
| + // we're not in vr (e.g. deep-linked from day dream home). |
| + assert !mInVr; |
| + mAutopresentWebVr = true; |
| + } |
| + |
| + /** |
| + * This is called every time ChromeActivity gets a intent. Its currently used to |
| + * autopresent WebVr from Daydream Home. |
| + */ |
| + public static void onNewIntent(Intent intent) { |
| + if (intent.getBooleanExtra(DAYDREAM_VR_EXTRA, false) |
|
Ted C
2017/05/11 21:51:17
nit, I would use IntentUtils.safeGetBooleanExtra
ymalik
2017/05/11 22:44:23
Done.
|
| + && activitySupportsAutopresentation( |
| + ApplicationStatus.getLastTrackedFocusedActivity()) |
| + && IntentHandler.isIntentChromeOrFirstParty(intent) |
| + && !IntentHandler.wasIntentSenderChrome(intent)) { |
| + VrShellDelegate instance = getInstance(); |
| + if (instance == null) return; |
| + instance.onAutopresentIntent(); |
| + } |
| + } |
| + |
| @Override |
| public void onSystemUiVisibilityChange(int visibility) { |
| if (mInVr && !isWindowModeCorrectForVr()) { |
| @@ -564,6 +603,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| @CalledByNative |
| private void presentRequested() { |
| mRequestedWebVr = true; |
| + mAutopresentWebVr = false; |
| switch (enterVrInternal()) { |
| case ENTER_VR_NOT_NECESSARY: |
| mVrShell.setWebVrModeEnabled(true); |
| @@ -602,7 +642,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| // the device is at LANDSCAPE orientation once it is finished. So here we use SENSOR to |
| // avoid forcing LANDSCAPE orientation in order to have a smoother transition. |
| setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_SENSOR); |
| - if (!mVrDaydreamApi.launchInVr(getEnterVrPendingIntent(mActivity))) { |
| + if (!launchInVr()) { |
| restoreWindowMode(); |
| return ENTER_VR_CANCELLED; |
| } |
| @@ -732,6 +772,14 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| mListeningForWebVrActivate = listening; |
| if (listening && !mPaused) { |
| registerDaydreamIntent(mVrDaydreamApi, mActivity); |
| + if (mAutopresentWebVr) { |
| + // Dispatch vrdisplayactivate so that the WebVr page can call requestPresent |
| + // to start presentation. |
| + // TODO(ymalik): There will be a delay between when we're asked to autopresent and |
| + // when the WebVr site calls requestPresent. In this time, the user sees 2D Chrome |
| + // UI which is suboptimal. |
| + nativeDisplayActivate(mNativeVrShellDelegate); |
| + } |
| } else { |
| unregisterDaydreamIntent(mVrDaydreamApi); |
| } |
| @@ -744,6 +792,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener, |
| if (!mInVr) return; |
| mInVr = false; |
| mRequestedWebVr = false; |
| + mAutopresentWebVr = false; |
| // Transition screen is not available for Cardboard only (non-Daydream) devices. |
| // TODO(bshe): Fix this once b/33490788 is fixed. |
| boolean transition = mVrSupportLevel == VR_DAYDREAM && showTransition; |