Commit 16a88111 authored by Torne (Richard Coles)'s avatar Torne (Richard Coles) Committed by Commit Bot

webview: Fix exception handling in various places.

These cases were converted to use PostTask some time ago, but because
the PostTask queue is managed in native (once native is initialized)
this means that uncaught exceptions cause native crashes instead of
being reported as Java exceptions.

Use AwThreadUtils to make it clear that posting directly to the Android
looper is intentional.

Change-Id: If7dcf8b98bb42886d02532a9d27eafcc58bab829
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302945
Auto-Submit: Richard Coles <torne@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789261}
parent 8151eeab
......@@ -62,6 +62,7 @@ import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContentsStatics;
import org.chromium.android_webview.AwPrintDocumentAdapter;
import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.AwThreadUtils;
import org.chromium.android_webview.gfx.AwDrawFnImpl;
import org.chromium.android_webview.renderer_priority.RendererPriority;
import org.chromium.base.BuildInfo;
......@@ -441,12 +442,7 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
private void checkThread() {
if (!ThreadUtils.runningOnUiThread()) {
final RuntimeException threadViolation = createThreadException();
PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
@Override
public void run() {
throw threadViolation;
}
});
AwThreadUtils.postToUiThreadLooper(() -> { throw threadViolation; });
throw createThreadException();
}
}
......
......@@ -27,6 +27,7 @@ import org.chromium.android_webview.AwLocaleConfig;
import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
import org.chromium.android_webview.AwProxyController;
import org.chromium.android_webview.AwServiceWorkerController;
import org.chromium.android_webview.AwThreadUtils;
import org.chromium.android_webview.AwTracingController;
import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.android_webview.ProductConfig;
......@@ -283,7 +284,7 @@ public class WebViewChromiumAwInit {
// We must post to the UI thread to cover the case that the user has invoked Chromium
// startup by using the (thread-safe) CookieManager rather than creating a WebView.
PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
AwThreadUtils.postToUiThreadLooper(new Runnable() {
@Override
public void run() {
synchronized (mLock) {
......
......@@ -3275,7 +3275,7 @@ public class AwContents implements SmartClipProvider {
@CalledByNative
private static void generateMHTMLCallback(String path, long size, Callback<String> callback) {
if (callback == null) return;
callback.onResult(size < 0 ? null : path);
AwThreadUtils.postToUiThreadLooper(() -> { callback.onResult(size < 0 ? null : path); });
}
@CalledByNative
......@@ -3358,7 +3358,7 @@ public class AwContents implements SmartClipProvider {
if (isDestroyed(NO_WARN)) return;
// Posting avoids invoking the callback inside invoking_composite_
// (see synchronous_compositor_impl.cc and crbug/452530).
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> callback.onComplete(requestId));
AwThreadUtils.postToUiThreadLooper(() -> callback.onComplete(requestId));
}
// Called as a result of AwContentsJni.get().updateLastHitTestData.
......@@ -3544,7 +3544,7 @@ public class AwContents implements SmartClipProvider {
if (path == null || isDestroyed(WARN)) {
if (callback == null) return;
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, callback.bind(null));
AwThreadUtils.postToUiThreadLooper(callback.bind(null));
} else {
AwContentsJni.get().generateMHTML(mNativeAwContents, AwContents.this, path, callback);
}
......
......@@ -6,8 +6,6 @@ package org.chromium.android_webview;
import android.content.SharedPreferences;
import org.chromium.base.task.PostTask;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.net.GURLUtils;
import java.util.HashSet;
......@@ -101,7 +99,7 @@ public final class AwGeolocationPermissions {
*/
public void getAllowed(String origin, final org.chromium.base.Callback<Boolean> callback) {
final boolean finalAllowed = isOriginAllowed(origin);
PostTask.postTask(UiThreadTaskTraits.DEFAULT, callback.bind(finalAllowed));
AwThreadUtils.postToUiThreadLooper(callback.bind(finalAllowed));
}
/**
......@@ -114,7 +112,7 @@ public final class AwGeolocationPermissions {
origins.add(name.substring(PREF_PREFIX.length()));
}
}
PostTask.postTask(UiThreadTaskTraits.DEFAULT, callback.bind(origins));
AwThreadUtils.postToUiThreadLooper(callback.bind(origins));
}
/**
......
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