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 46a55a1fa806a86f66f032cb89be127d95396dac..6e4f2f79c18d32f9596ab2b809cb0f5261717f46 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 |
| @@ -14,6 +14,8 @@ import android.view.ViewGroup.LayoutParams; |
| import android.view.WindowManager; |
| import org.chromium.base.Log; |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| import org.chromium.chrome.browser.ChromeTabbedActivity; |
| import java.lang.reflect.Constructor; |
| @@ -22,6 +24,7 @@ import java.lang.reflect.InvocationTargetException; |
| /** |
| * Manages interactions with the VR Shell. |
| */ |
| +@JNINamespace("vr_shell") |
| public class VrShellDelegate { |
| private static final String TAG = "VrShellDelegate"; |
| @@ -35,6 +38,7 @@ public class VrShellDelegate { |
| private int mRestoreSystemUiVisibilityFlag = -1; |
| private ViewGroup mParentView; |
| private String mVrExtra; |
| + private long mNativeVrShellDelegate; |
| public VrShellDelegate(ChromeTabbedActivity activity, ViewGroup parentView) { |
| mActivity = activity; |
| @@ -52,6 +56,10 @@ public class VrShellDelegate { |
| } |
| } |
| + public void onNativeLibraryReady() { |
|
Ted C
2016/09/20 20:31:11
all public methods should have some sort of docume
|
| + mNativeVrShellDelegate = nativeInit(); |
| + } |
| + |
| @SuppressWarnings("unchecked") |
| private Class<? extends VrShellInterface> maybeFindVrShell() { |
| try { |
| @@ -70,7 +78,7 @@ public class VrShellDelegate { |
| * @Returns Whether or not we are in VR when this function returns. |
| */ |
| public boolean enterVRIfNecessary() { |
|
Ted C
2016/09/20 20:31:11
could this just take a boolean param isWebVR? sam
|
| - if (!mVrShellEnabled) return false; |
| + if (!mVrShellEnabled || mNativeVrShellDelegate == 0) return false; |
| if (mInVr) return true; |
| // VrShell must be initialized in Landscape mode due to a bug in the GVR library. |
| mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| @@ -80,12 +88,31 @@ public class VrShellDelegate { |
| } |
| addVrViews(); |
| setupVrModeWindowFlags(); |
| - mVrShellView.onNativeLibraryReady(); |
| + mVrShellView.onNativeLibraryReady(mNativeVrShellDelegate); |
| mVrShellView.setVrModeEnabled(true); |
| mInVr = true; |
| return true; |
| } |
| + @CalledByNative |
| + public boolean enterWebVRIfNecessary() { |
| + if (enterVRIfNecessary()) { |
| + mVrShellView.setWebVrModeEnabled(true); |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + @CalledByNative |
| + public boolean exitWebVRIfNecessary() { |
| + if (!mInVr) return false; |
| + mVrShellView.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. |
| + return exitVRIfNecessary(); |
| + } |
| + |
| /** |
| * Resumes VR Shell. |
| */ |
| @@ -107,6 +134,12 @@ public class VrShellDelegate { |
| */ |
| public boolean exitVRIfNecessary() { |
| if (!mInVr) return false; |
| + if (nativeExitVRIfNecessary(mNativeVrShellDelegate)) { |
| + // In this scenario we need to wait for WebVR to shut down before |
| + // removing the VrShell. exitVRIfNecessary will be called again (by |
| + // exitWebVRIfNecessary) when it's safe to destroy the VrShell. |
|
Ted C
2016/09/20 20:31:11
that is an odd semantics. should we pull out a di
|
| + return true; |
| + } |
| mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| mVrShellView.setVrModeEnabled(false); |
| mVrShellView.pause(); |
| @@ -195,4 +228,8 @@ public class VrShellDelegate { |
| public boolean isVrShellEnabled() { |
| return mVrShellEnabled; |
| } |
| + |
| + private native long nativeInit(); |
| + |
| + private native boolean nativeExitVRIfNecessary(long nativeVrShellDelegate); |
| } |