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

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

Issue 2343023002: Switch WebVR to handle GvrApi management through VrShellDelegate (Closed)
Patch Set: Renamed onNativeLibraryReady to initializeNative Created 4 years, 3 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 826c000bcee49356b07d5d0d5b28390894035a8a..aa8b50be9c27fd596d4c9df37bc81901624474b9 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
@@ -15,6 +15,8 @@ import android.view.WindowManager;
import android.widget.FrameLayout;
import org.chromium.base.Log;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.tab.Tab;
@@ -24,6 +26,7 @@ import java.lang.reflect.InvocationTargetException;
/**
* Manages interactions with the VR Shell.
*/
+@JNINamespace("vr_shell")
public class VrShellDelegate {
private static final String TAG = "VrShellDelegate";
@@ -36,6 +39,7 @@ public class VrShellDelegate {
private boolean mInVr;
private int mRestoreSystemUiVisibilityFlag = -1;
private String mVrExtra;
+ private long mNativeVrShellDelegate;
public VrShellDelegate(ChromeTabbedActivity activity) {
mActivity = activity;
@@ -52,6 +56,16 @@ public class VrShellDelegate {
}
}
+ /**
+ * Should be called once the native library is loaded so that the native portion of this
+ * class can be initialized.
+ */
+ public void onNativeLibraryReady() {
+ if (mVrShellEnabled) {
+ mNativeVrShellDelegate = nativeInit();
+ }
+ }
+
@SuppressWarnings("unchecked")
private Class<? extends VrShellInterface> maybeFindVrShell() {
try {
@@ -67,10 +81,12 @@ public class VrShellDelegate {
*
* This function performs native initialization, and so must only be called after native
* libraries are ready.
- * @Returns Whether or not we are in VR when this function returns.
+ * @param inWebVR If true should begin displaying WebVR content rather than the VrShell UI.
+ * @return Whether or not we are in VR when this function returns.
*/
- public boolean enterVRIfNecessary() {
- if (!mVrShellEnabled) return false;
+ @CalledByNative
+ public boolean enterVRIfNecessary(boolean inWebVR) {
+ if (!mVrShellEnabled || mNativeVrShellDelegate == 0) return false;
Tab tab = mActivity.getActivityTab();
// TODO(mthiesse): When we have VR UI for opening new tabs, etc., allow VR Shell to be
// entered without any current tabs.
@@ -86,12 +102,24 @@ public class VrShellDelegate {
}
addVrViews();
setupVrModeWindowFlags();
- mVrShell.onNativeLibraryReady(tab);
+ mVrShell.initializeNative(tab, this);
+ if (inWebVR) mVrShell.setWebVrModeEnabled(true);
mVrShell.setVrModeEnabled(true);
mInVr = true;
return true;
}
+ @CalledByNative
+ private boolean exitWebVR() {
+ if (!mInVr) return false;
+ mVrShell.setWebVrModeEnabled(false);
+ // TODO(bajones): Once VR Shell can be invoked outside of WebVR this
+ // should no longer exit the shell outright. Need a way to determine
+ // how VrShell was created.
+ shutdownVR();
+ return true;
+ }
+
/**
* Resumes VR Shell.
*/
@@ -108,11 +136,26 @@ public class VrShellDelegate {
}
/**
- * Exits VR Shell, performing all necessary cleanup.
- * @Returns Whether or not we exited VR.
+ * Exits the current VR mode (WebVR or VRShell)
+ * @return Whether or not we exited VR.
*/
public boolean exitVRIfNecessary() {
if (!mInVr) return false;
+ // If WebVR is presenting instruct it to exit. VR mode should not
+ // exit in this scenario, in case we want to return to the VrShell.
+ if (!nativeExitWebVRIfNecessary(mNativeVrShellDelegate)) {
+ // If WebVR was not presenting, shutdown VR mode entirely.
+ shutdownVR();
+ }
+
+ return true;
+ }
+
+ /**
+ * Exits VR Shell, performing all necessary cleanup.
+ */
+ private void shutdownVR() {
+ if (!mInVr) return;
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
mVrShell.setVrModeEnabled(false);
mVrShell.pause();
@@ -120,7 +163,6 @@ public class VrShellDelegate {
clearVrModeWindowFlags();
destroyVrShell();
mInVr = false;
- return true;
}
private boolean createVrShell() {
@@ -205,4 +247,15 @@ public class VrShellDelegate {
public boolean isVrShellEnabled() {
return mVrShellEnabled;
}
+
+ /**
+ * @return Pointer to the native VrShellDelegate object.
+ */
+ @CalledByNative
+ private long getNativePointer() {
+ return mNativeVrShellDelegate;
+ }
+
+ private native long nativeInit();
+ private native boolean nativeExitWebVRIfNecessary(long nativeVrShellDelegate);
}

Powered by Google App Engine
This is Rietveld 408576698