Chromium Code Reviews| 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..7e99903b2f6904967f123e14a6c936f932b5bbe3 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,8 @@ import org.chromium.ui.base.WindowAndroid; |
| import org.chromium.ui.display.DisplayAndroid; |
| import org.chromium.ui.display.VirtualDisplayAndroid; |
| +import java.util.Iterator; |
| + |
| /** |
| * This view extends from GvrLayout which wraps a GLSurfaceView that renders VR shell. |
| */ |
| @@ -97,6 +104,10 @@ public class VrShellImpl |
| private Surface mSurface; |
| private View mPresentationView; |
| + private SparseArray<Runnable> mUiElementInfoReplyCallbacks; |
| + private SparseArray<JSONObject> mUiElementInfoJson; |
| + private int mCallbackCounter; |
| + |
| // The tab that holds the main ContentViewCore. |
| private Tab mTab; |
| private NativePage mNativePage; |
| @@ -628,6 +639,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 |
|
tiborg
2017/03/27 15:14:32
Nit: end sentence with full stop.
bsheedy
2017/03/27 17:49:09
Done.
|
| + private SparseArray<Runnable> getUiElementInfoReplyCallbacks() { |
|
tiborg
2017/03/27 15:14:33
Should we append ForTesting to make sure it is onl
bsheedy
2017/03/27 17:49:09
If this is only ever going to be used for testing
tiborg
2017/03/27 19:59:59
I'm not aware of any plans to use this functionali
|
| + if (mUiElementInfoReplyCallbacks == null) { |
| + mUiElementInfoReplyCallbacks = new SparseArray<Runnable>(); |
| + } |
| + return mUiElementInfoReplyCallbacks; |
| + } |
| + |
| + // Lazily instantiate since we don't need it in most cases |
|
tiborg
2017/03/27 15:14:33
Nit: end sentence with full stop.
bsheedy
2017/03/27 17:49:09
Done.
|
| + @VisibleForTesting |
| + public SparseArray<JSONObject> getUiElementInfoJson() { |
|
tiborg
2017/03/27 15:14:33
Here, too, append ForTesting?
bsheedy
2017/03/27 17:49:09
Same as above.
|
| + if (mUiElementInfoJson == null) mUiElementInfoJson = new SparseArray<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 requestUiElementInfoFromNative(int[] elementIds, Runnable onReply) { |
|
tiborg
2017/03/27 15:14:33
Here, too, append ForTesting?
bsheedy
2017/03/27 17:49:09
Same as above.
|
| + getUiElementInfoReplyCallbacks().append(mCallbackCounter, onReply); |
| + nativeRequestUiElementInfo(mNativeVrShell, elementIds, mCallbackCounter); |
| + mCallbackCounter++; |
| + } |
| + |
| + @CalledByNative |
| + public void replyToUiElementInfoRequest(String jsonString, int callbackId) |
|
tiborg
2017/03/27 15:14:33
Here, too, append ForTesting?
bsheedy
2017/03/27 17:49:09
Same as above.
|
| + throws JSONException { |
| + JSONObject reply = new JSONObject(jsonString); |
| + SparseArray<JSONObject> uiElementInfo = getUiElementInfoJson(); |
| + for (Iterator<String> iter = reply.keys(); iter.hasNext();) { |
| + String key = iter.next(); |
| + uiElementInfo.put(Integer.parseInt(key), reply.optJSONObject(key)); |
| + } |
| + SparseArray<Runnable> callbacks = getUiElementInfoReplyCallbacks(); |
| + 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 +714,6 @@ public class VrShellImpl |
| private native void nativeRestoreContentSurface(long nativeVrShell); |
| private native void nativeSetHistoryButtonsEnabled( |
| long nativeVrShell, boolean canGoBack, boolean canGoForward); |
| + private native void nativeRequestUiElementInfo( |
| + long nativeVrShell, int[] elementIds, int callbackId); |
| } |