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

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

Issue 2873843002: Support autopresenting WebVr content. (Closed)
Patch Set: Created 3 years, 7 months 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 side-by-side diff with in-line comments
Download patch
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..5c7e2981fcdede0f4422b1ee1aa8dcb5bbae3f64 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 = 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
private static class VrBroadcastReceiver extends BroadcastReceiver {
private final WeakReference<ChromeActivity> mTargetActivity;
@@ -512,6 +519,32 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
mVrShell.getContainer().setOnSystemUiVisibilityChangeListener(this);
}
+ private boolean launchInVr() {
+ 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.
+ 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(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
+ if (intent.getBooleanExtra(DAYDREAM_VR_EXTRA, false) && activity.canAutopresentVr()
+ && IntentHandler.isIntentChromeOrFirstParty(intent)) {
+ VrShellDelegate instance = getInstance(activity);
+ if (instance == null) return;
+ 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.
+ instance.onAutopresentIntent();
+ }
+ }
+
@Override
public void onSystemUiVisibilityChange(int visibility) {
if (mInVr && !isWindowModeCorrectForVr()) {
@@ -564,6 +597,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 +636,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 +766,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 +786,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;

Powered by Google App Engine
This is Rietveld 408576698