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

Side by Side 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: Rebase 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 unified diff | Download patch
OLDNEW
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.content.Intent; 8 import android.content.Intent;
9 import android.content.pm.ActivityInfo; 9 import android.content.pm.ActivityInfo;
10 import android.os.StrictMode; 10 import android.os.StrictMode;
11 import android.view.View; 11 import android.view.View;
12 import android.view.ViewGroup; 12 import android.view.ViewGroup;
13 import android.view.ViewGroup.LayoutParams; 13 import android.view.ViewGroup.LayoutParams;
14 import android.view.WindowManager; 14 import android.view.WindowManager;
15 15
16 import org.chromium.base.Log; 16 import org.chromium.base.Log;
17 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.base.annotations.JNINamespace;
17 import org.chromium.chrome.browser.ChromeTabbedActivity; 19 import org.chromium.chrome.browser.ChromeTabbedActivity;
18 20
19 import java.lang.reflect.Constructor; 21 import java.lang.reflect.Constructor;
20 import java.lang.reflect.InvocationTargetException; 22 import java.lang.reflect.InvocationTargetException;
21 23
22 /** 24 /**
23 * Manages interactions with the VR Shell. 25 * Manages interactions with the VR Shell.
24 */ 26 */
27 @JNINamespace("vr_shell")
25 public class VrShellDelegate { 28 public class VrShellDelegate {
26 private static final String TAG = "VrShellDelegate"; 29 private static final String TAG = "VrShellDelegate";
27 30
28 private ChromeTabbedActivity mActivity; 31 private ChromeTabbedActivity mActivity;
29 32
30 private boolean mVrShellEnabled; 33 private boolean mVrShellEnabled;
31 34
32 private Class<? extends VrShellInterface> mVrShellClass; 35 private Class<? extends VrShellInterface> mVrShellClass;
33 private VrShellInterface mVrShellView; 36 private VrShellInterface mVrShellView;
34 private boolean mInVr; 37 private boolean mInVr;
35 private int mRestoreSystemUiVisibilityFlag = -1; 38 private int mRestoreSystemUiVisibilityFlag = -1;
36 private ViewGroup mParentView; 39 private ViewGroup mParentView;
37 private String mVrExtra; 40 private String mVrExtra;
41 private long mNativeVrShellDelegate;
38 42
39 public VrShellDelegate(ChromeTabbedActivity activity, ViewGroup parentView) { 43 public VrShellDelegate(ChromeTabbedActivity activity, ViewGroup parentView) {
40 mActivity = activity; 44 mActivity = activity;
41 mParentView = parentView; 45 mParentView = parentView;
42 46
43 mVrShellClass = maybeFindVrShell(); 47 mVrShellClass = maybeFindVrShell();
44 if (mVrShellClass != null) { 48 if (mVrShellClass != null) {
45 mVrShellEnabled = true; 49 mVrShellEnabled = true;
46 try { 50 try {
47 mVrExtra = (String) mVrShellClass.getField("VR_EXTRA").get(null) ; 51 mVrExtra = (String) mVrShellClass.getField("VR_EXTRA").get(null) ;
48 } catch (IllegalAccessException | IllegalArgumentException | NoSuchF ieldException e) { 52 } catch (IllegalAccessException | IllegalArgumentException | NoSuchF ieldException e) {
49 Log.e(TAG, "Unable to read VR_EXTRA field", e); 53 Log.e(TAG, "Unable to read VR_EXTRA field", e);
50 mVrShellEnabled = false; 54 mVrShellEnabled = false;
51 } 55 }
52 } 56 }
53 } 57 }
54 58
59 public void onNativeLibraryReady() {
Ted C 2016/09/20 20:31:11 all public methods should have some sort of docume
60 mNativeVrShellDelegate = nativeInit();
61 }
62
55 @SuppressWarnings("unchecked") 63 @SuppressWarnings("unchecked")
56 private Class<? extends VrShellInterface> maybeFindVrShell() { 64 private Class<? extends VrShellInterface> maybeFindVrShell() {
57 try { 65 try {
58 return (Class<? extends VrShellInterface>) Class 66 return (Class<? extends VrShellInterface>) Class
59 .forName("org.chromium.chrome.browser.vr_shell.VrShell"); 67 .forName("org.chromium.chrome.browser.vr_shell.VrShell");
60 } catch (ClassNotFoundException e) { 68 } catch (ClassNotFoundException e) {
61 return null; 69 return null;
62 } 70 }
63 } 71 }
64 72
65 /** 73 /**
66 * Enters VR Shell, displaying browser UI and tab contents in VR. 74 * Enters VR Shell, displaying browser UI and tab contents in VR.
67 * 75 *
68 * This function performs native initialization, and so must only be called after native 76 * This function performs native initialization, and so must only be called after native
69 * libraries are ready. 77 * libraries are ready.
70 * @Returns Whether or not we are in VR when this function returns. 78 * @Returns Whether or not we are in VR when this function returns.
71 */ 79 */
72 public boolean enterVRIfNecessary() { 80 public boolean enterVRIfNecessary() {
Ted C 2016/09/20 20:31:11 could this just take a boolean param isWebVR? sam
73 if (!mVrShellEnabled) return false; 81 if (!mVrShellEnabled || mNativeVrShellDelegate == 0) return false;
74 if (mInVr) return true; 82 if (mInVr) return true;
75 // VrShell must be initialized in Landscape mode due to a bug in the GVR library. 83 // VrShell must be initialized in Landscape mode due to a bug in the GVR library.
76 mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSC APE); 84 mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSC APE);
77 if (!createVrShell()) { 85 if (!createVrShell()) {
78 mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UN SPECIFIED); 86 mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UN SPECIFIED);
79 return false; 87 return false;
80 } 88 }
81 addVrViews(); 89 addVrViews();
82 setupVrModeWindowFlags(); 90 setupVrModeWindowFlags();
83 mVrShellView.onNativeLibraryReady(); 91 mVrShellView.onNativeLibraryReady(mNativeVrShellDelegate);
84 mVrShellView.setVrModeEnabled(true); 92 mVrShellView.setVrModeEnabled(true);
85 mInVr = true; 93 mInVr = true;
86 return true; 94 return true;
87 } 95 }
88 96
97 @CalledByNative
98 public boolean enterWebVRIfNecessary() {
99 if (enterVRIfNecessary()) {
100 mVrShellView.setWebVrModeEnabled(true);
101 return true;
102 }
103 return false;
104 }
105
106 @CalledByNative
107 public boolean exitWebVRIfNecessary() {
108 if (!mInVr) return false;
109 mVrShellView.setWebVrModeEnabled(false);
110 // TODO(bajones): Once VR Shell can be invoked outside of WebVR this
111 // should no longer exit the shell outright. Need a way to determine
112 // how VrShell was created.
113 return exitVRIfNecessary();
114 }
115
89 /** 116 /**
90 * Resumes VR Shell. 117 * Resumes VR Shell.
91 */ 118 */
92 public void resumeVR() { 119 public void resumeVR() {
93 setupVrModeWindowFlags(); 120 setupVrModeWindowFlags();
94 mVrShellView.resume(); 121 mVrShellView.resume();
95 } 122 }
96 123
97 /** 124 /**
98 * Pauses VR Shell. 125 * Pauses VR Shell.
99 */ 126 */
100 public void pauseVR() { 127 public void pauseVR() {
101 mVrShellView.pause(); 128 mVrShellView.pause();
102 } 129 }
103 130
104 /** 131 /**
105 * Exits VR Shell, performing all necessary cleanup. 132 * Exits VR Shell, performing all necessary cleanup.
106 * @Returns Whether or not we exited VR. 133 * @Returns Whether or not we exited VR.
107 */ 134 */
108 public boolean exitVRIfNecessary() { 135 public boolean exitVRIfNecessary() {
109 if (!mInVr) return false; 136 if (!mInVr) return false;
137 if (nativeExitVRIfNecessary(mNativeVrShellDelegate)) {
138 // In this scenario we need to wait for WebVR to shut down before
139 // removing the VrShell. exitVRIfNecessary will be called again (by
140 // 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
141 return true;
142 }
110 mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPEC IFIED); 143 mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPEC IFIED);
111 mVrShellView.setVrModeEnabled(false); 144 mVrShellView.setVrModeEnabled(false);
112 mVrShellView.pause(); 145 mVrShellView.pause();
113 removeVrViews(); 146 removeVrViews();
114 clearVrModeWindowFlags(); 147 clearVrModeWindowFlags();
115 destroyVrShell(); 148 destroyVrShell();
116 mInVr = false; 149 mInVr = false;
117 return true; 150 return true;
118 } 151 }
119 152
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 public boolean isInVR() { 221 public boolean isInVR() {
189 return mInVr; 222 return mInVr;
190 } 223 }
191 224
192 /** 225 /**
193 * @return Whether or not VR Shell is currently enabled. 226 * @return Whether or not VR Shell is currently enabled.
194 */ 227 */
195 public boolean isVrShellEnabled() { 228 public boolean isVrShellEnabled() {
196 return mVrShellEnabled; 229 return mVrShellEnabled;
197 } 230 }
231
232 private native long nativeInit();
233
234 private native boolean nativeExitVRIfNecessary(long nativeVrShellDelegate);
198 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698