Commit 7ea2ea23 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: Add thread checks and docs for public callbacks.

Add UI thread checks for callbacks that are passed to the embedder.

Bug: none
Change-Id: I2cd643e406f056c112f1f77ab84e66ad8e96cd08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2326296
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792768}
parent db61c3a8
...@@ -9,6 +9,7 @@ import android.content.pm.PackageManager; ...@@ -9,6 +9,7 @@ import android.content.pm.PackageManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
...@@ -91,6 +92,7 @@ public final class DownloadCallbackProxy { ...@@ -91,6 +92,7 @@ public final class DownloadCallbackProxy {
ValueCallback<Boolean> callback = new ValueCallback<Boolean>() { ValueCallback<Boolean> callback = new ValueCallback<Boolean>() {
@Override @Override
public void onReceiveValue(Boolean result) { public void onReceiveValue(Boolean result) {
ThreadUtils.assertOnUiThread();
if (mNativeDownloadCallbackProxy == 0) { if (mNativeDownloadCallbackProxy == 0) {
throw new IllegalStateException("Called after destroy()"); throw new IllegalStateException("Called after destroy()");
} }
......
...@@ -7,6 +7,7 @@ package org.chromium.weblayer_private; ...@@ -7,6 +7,7 @@ package org.chromium.weblayer_private;
import android.os.RemoteException; import android.os.RemoteException;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
...@@ -46,6 +47,7 @@ public final class FullscreenCallbackProxy { ...@@ -46,6 +47,7 @@ public final class FullscreenCallbackProxy {
ValueCallback<Void> exitFullscreenCallback = new ValueCallback<Void>() { ValueCallback<Void> exitFullscreenCallback = new ValueCallback<Void>() {
@Override @Override
public void onReceiveValue(Void result) { public void onReceiveValue(Void result) {
ThreadUtils.assertOnUiThread();
if (mNativeFullscreenCallbackProxy == 0) { if (mNativeFullscreenCallbackProxy == 0) {
throw new IllegalStateException("Called after destroy()"); throw new IllegalStateException("Called after destroy()");
} }
......
...@@ -13,6 +13,7 @@ import android.util.AndroidRuntimeException; ...@@ -13,6 +13,7 @@ import android.util.AndroidRuntimeException;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
...@@ -178,6 +179,7 @@ public class MediaStreamManager { ...@@ -178,6 +179,7 @@ public class MediaStreamManager {
audio, video, ObjectWrapper.wrap(new ValueCallback<Boolean>() { audio, video, ObjectWrapper.wrap(new ValueCallback<Boolean>() {
@Override @Override
public void onReceiveValue(Boolean allowed) { public void onReceiveValue(Boolean allowed) {
ThreadUtils.assertOnUiThread();
respondToStreamRequest(requestId, allowed.booleanValue()); respondToStreamRequest(requestId, allowed.booleanValue());
} }
})); }));
......
...@@ -36,7 +36,8 @@ public abstract class DownloadCallback { ...@@ -36,7 +36,8 @@ public abstract class DownloadCallback {
* @param uri the target that is being downloaded * @param uri the target that is being downloaded
* @param requestMethod the method (GET/POST etc...) of the download * @param requestMethod the method (GET/POST etc...) of the download
* @param requestInitiator the initiating Uri, if present * @param requestInitiator the initiating Uri, if present
* @param callback a callback to allow or disallow the download. must be called to avoid leaks * @param callback a callback to allow or disallow the download. Must be called to avoid leaks,
* and must be called on the UI thread.
* *
* @since 81 * @since 81
*/ */
......
...@@ -17,7 +17,7 @@ public abstract class FullscreenCallback { ...@@ -17,7 +17,7 @@ public abstract class FullscreenCallback {
* running the supplied Runnable (calling exitFullscreenRunner.Run() results in calling * running the supplied Runnable (calling exitFullscreenRunner.Run() results in calling
* exitFullscreen()). * exitFullscreen()).
* *
* NOTE: the Runnable must not be used synchronously. * NOTE: the Runnable must not be used synchronously, and must be run on the UI thread.
*/ */
public abstract void onEnterFullscreen(@NonNull Runnable exitFullscreenRunner); public abstract void onEnterFullscreen(@NonNull Runnable exitFullscreenRunner);
......
...@@ -25,8 +25,8 @@ public abstract class MediaCaptureCallback { ...@@ -25,8 +25,8 @@ public abstract class MediaCaptureCallback {
* *
* @param audio if true, the new stream includes audio from a microphone. * @param audio if true, the new stream includes audio from a microphone.
* @param video if true, the new stream includes video from a camera. * @param video if true, the new stream includes video from a camera.
* @param requestResult a callback to be run with true if and when the stream * @param requestResult a callback to be run with true if and when the stream can start, or
* can start, or false if the stream should not start. * false if the stream should not start. Must be run on the UI thread.
*/ */
public void onMediaCaptureRequested( public void onMediaCaptureRequested(
boolean audio, boolean video, ValueCallback<Boolean> requestResult) {} boolean audio, boolean video, ValueCallback<Boolean> requestResult) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment