-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webview: Fix exception handling in evaluateJavascript.
This case was converted to use PostTask along with all the other cases in the file, but because the PostTask queue is managed in native (once native is initialized) this fails to achieve the original goal of posting it described in the comment: to make sure there is no native code on the stack, so that we can handle the app's callback throwing an exception without crashing in native. Introduce an AwThreadUtils class that contains specifically-documented methods for posting tasks in the desired way, and use it in evaluateJavascript and other methods which want this exception-handling behaviour, to make it clear that using Handler directly is intentional and necessary. Fixed: 719396 Bug: 944437 Change-Id: I95cc029801e632a22987eb92e00cc28d4c292332 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144461 Commit-Queue: Richard Coles <torne@chromium.org> Commit-Queue: Bo <boliu@chromium.org> Auto-Submit: Richard Coles <torne@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Cr-Commit-Position: refs/heads/master@{#759845}
- Loading branch information
Showing
5 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
android_webview/java/src/org/chromium/android_webview/AwThreadUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.android_webview; | ||
|
||
import android.os.Handler; | ||
|
||
import org.chromium.base.ThreadUtils; | ||
|
||
/** | ||
* Provides WebView-specific threading utilities. | ||
*/ | ||
public class AwThreadUtils { | ||
/** | ||
* Post a task to the current thread, ensuring that it runs on the underlying Android looper | ||
* without any native code present on the stack. This allows uncaught Java exceptions to be | ||
* handled correctly by Android's crash reporting mechanisms. | ||
*/ | ||
public static void postToCurrentLooper(Runnable r) { | ||
new Handler().post(r); | ||
} | ||
|
||
/** | ||
* Post a task to the UI thread, ensuring that it runs on the underlying Android looper without | ||
* any native code present on the stack. This allows uncaught Java exceptions to be handled | ||
* correctly by Android's crash reporting mechanisms. | ||
*/ | ||
public static void postToUiThreadLooper(Runnable r) { | ||
ThreadUtils.getUiThreadHandler().post(r); | ||
} | ||
} |