Skip to content

Commit

Permalink
webview: Fix exception handling in various places.
Browse files Browse the repository at this point in the history
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: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789261}
  • Loading branch information
tornewuff authored and Commit Bot committed Jul 16, 2020
1 parent 8151eea commit 16a8811
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
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;
Expand Down Expand Up @@ -441,12 +442,7 @@ protected boolean checkNeedsPost() {
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -283,7 +284,7 @@ void startYourEngines(boolean onMainThread) {

// 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,7 @@ private long onCreateTouchHandle() {
@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
Expand Down Expand Up @@ -3358,7 +3358,7 @@ public void invokeVisualStateCallback(
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.
Expand Down Expand Up @@ -3544,7 +3544,7 @@ private void saveWebArchiveInternal(String path, final Callback<String> callback
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

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;
Expand Down Expand Up @@ -101,7 +99,7 @@ public boolean hasOrigin(String origin) {
*/
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));
}

/**
Expand All @@ -114,7 +112,7 @@ public void getOrigins(final org.chromium.base.Callback<Set<String>> callback) {
origins.add(name.substring(PREF_PREFIX.length()));
}
}
PostTask.postTask(UiThreadTaskTraits.DEFAULT, callback.bind(origins));
AwThreadUtils.postToUiThreadLooper(callback.bind(origins));
}

/**
Expand Down

0 comments on commit 16a8811

Please sign in to comment.