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

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

Issue 2773903003: Add way to get native VR UI information from Java (Closed)
Patch Set: Address cjgrant@ comments + stability improvement Created 3 years, 9 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/VrShellImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
index 6112be34e224d80e8ea6d69d70165874a9ea9491..49379709b4e6da0a73009f945697ab00820bc5f7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
@@ -8,6 +8,7 @@ import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Point;
import android.os.StrictMode;
+import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
@@ -20,9 +21,13 @@ import android.widget.FrameLayout.LayoutParams;
import com.google.vr.ndk.base.AndroidCompat;
import com.google.vr.ndk.base.GvrLayout;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import org.chromium.base.CommandLine;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
+import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.ChromeActivity;
@@ -56,6 +61,9 @@ import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.display.DisplayAndroid;
import org.chromium.ui.display.VirtualDisplayAndroid;
+import java.util.HashMap;
+import java.util.Iterator;
+
/**
* This view extends from GvrLayout which wraps a GLSurfaceView that renders VR shell.
*/
@@ -97,6 +105,10 @@ public class VrShellImpl
private Surface mSurface;
private View mPresentationView;
+ private SparseArray<Runnable> mUiElementInfoReplyCallbacks;
mthiesse 2017/03/30 14:25:38 Why do we need multiple callbacks at once? Seems u
bsheedy 2017/03/30 21:05:14 For testing, a single callback should be sufficien
+ private HashMap<String, JSONObject> mUiElementInfoJson;
+ private int mCallbackCounter;
+
// The tab that holds the main ContentViewCore.
private Tab mTab;
private NativePage mNativePage;
@@ -628,6 +640,55 @@ public class VrShellImpl
@Override
public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver observer) {}
+ @VisibleForTesting
+ public WebContents getUiContentsForTesting() {
+ return mUiContents;
+ }
+
+ // Lazily instantiate since we don't need it in most cases.
+ private SparseArray<Runnable> getUiElementInfoReplyCallbacksForTesting() {
+ if (mUiElementInfoReplyCallbacks == null) {
+ mUiElementInfoReplyCallbacks = new SparseArray<Runnable>();
+ }
+ return mUiElementInfoReplyCallbacks;
+ }
+
+ // Lazily instantiate since we don't need it in most cases.
+ @VisibleForTesting
+ public HashMap<String, JSONObject> getUiElementInfoJsonForTesting() {
mthiesse 2017/03/30 14:25:39 Why expose this? Why not just create this object i
bsheedy 2017/03/30 21:05:14 Done.
+ if (mUiElementInfoJson == null) mUiElementInfoJson = new HashMap<String, JSONObject>();
+ return mUiElementInfoJson;
+ }
+
+ /**
+ * Sends an asynchronous request for native UI element information.
+ * @param elementIds The unique IDs of all the elements you want info on
+ * @param onReply The runnable that will be run when native replies
+ */
+ @VisibleForTesting
+ public void requestUiElementInfoFromNativeForTesting(String[] elementNames, Runnable onReply) {
+ getUiElementInfoReplyCallbacksForTesting().append(mCallbackCounter, onReply);
+ nativeRequestUiElementInfoForTesting(mNativeVrShell, elementNames, mCallbackCounter);
+ mCallbackCounter++;
+ }
+
+ @CalledByNative
+ public void replyToUiElementInfoRequestForTesting(String jsonString, int callbackId)
+ throws JSONException {
+ JSONObject reply = new JSONObject(jsonString);
+ HashMap<String, JSONObject> uiElementInfo = getUiElementInfoJsonForTesting();
+ for (Iterator<String> iter = reply.keys(); iter.hasNext();) {
+ String key = iter.next();
+ uiElementInfo.put(key, reply.optJSONObject(key));
+ }
+ SparseArray<Runnable> callbacks = getUiElementInfoReplyCallbacksForTesting();
+ Runnable callback = callbacks.get(callbackId);
+ if (callback != null) {
+ callback.run();
+ }
+ callbacks.remove(callbackId);
+ }
+
private native long nativeInit(WebContents uiWebContents, long nativeContentWindowAndroid,
long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delegate, long gvrApi,
boolean reprojectedRendering);
@@ -654,4 +715,6 @@ public class VrShellImpl
private native void nativeRestoreContentSurface(long nativeVrShell);
private native void nativeSetHistoryButtonsEnabled(
long nativeVrShell, boolean canGoBack, boolean canGoForward);
+ private native void nativeRequestUiElementInfoForTesting(
+ long nativeVrShell, String[] elementNames, int callbackId);
}

Powered by Google App Engine
This is Rietveld 408576698