Skip to content

Commit cba778d

Browse files
author
Ben Murdoch
committed
Pause the WebCore thread watchdog at the right time.
There are times when we deliberately put the WebCore thread to sleep (i.e. waiting for a user to complete a JS prompt or dismiss an alert). In this case, we don't want the WebCore thread watchdog to fire. Pause the watchdog before we put the WebCore thread to sleep and resume it again when the thread wakes up. Factor out the repeated send/pause/wait/resume code into it's own function. Bug: 6366520 Change-Id: I17ecf9d466ce21b25a9e5cb8ff4cb0e5fab7605b
1 parent eb65757 commit cba778d

File tree

1 file changed

+22
-86
lines changed

1 file changed

+22
-86
lines changed

core/java/android/webkit/CallbackProxy.java

Lines changed: 22 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,15 +1047,7 @@ public boolean shouldOverrideUrlLoading(String url) {
10471047
Message msg = obtainMessage(OVERRIDE_URL);
10481048
msg.getData().putString("url", url);
10491049
msg.obj = res;
1050-
synchronized (this) {
1051-
sendMessage(msg);
1052-
try {
1053-
wait();
1054-
} catch (InterruptedException e) {
1055-
Log.e(LOGTAG, "Caught exception while waiting for overrideUrl");
1056-
Log.e(LOGTAG, Log.getStackTraceString(e));
1057-
}
1058-
}
1050+
sendMessageToUiThreadSync(msg);
10591051
return res.getResult().booleanValue();
10601052
}
10611053

@@ -1223,16 +1215,7 @@ public boolean onSavePassword(String schemePlusHost, String username,
12231215
bundle.putString("host", schemePlusHost);
12241216
bundle.putString("username", username);
12251217
bundle.putString("password", password);
1226-
synchronized (this) {
1227-
sendMessage(msg);
1228-
try {
1229-
wait();
1230-
} catch (InterruptedException e) {
1231-
Log.e(LOGTAG,
1232-
"Caught exception while waiting for onSavePassword");
1233-
Log.e(LOGTAG, Log.getStackTraceString(e));
1234-
}
1235-
}
1218+
sendMessageToUiThreadSync(msg);
12361219
// Doesn't matter here
12371220
return false;
12381221
}
@@ -1281,18 +1264,8 @@ public BrowserFrame createWindow(boolean dialog, boolean userGesture) {
12811264
mWebView.getWebView().new WebViewTransport();
12821265
final Message msg = obtainMessage(NOTIFY);
12831266
msg.obj = transport;
1284-
synchronized (this) {
1285-
sendMessage(obtainMessage(CREATE_WINDOW, dialog ? 1 : 0,
1286-
userGesture ? 1 : 0, msg));
1287-
try {
1288-
wait();
1289-
} catch (InterruptedException e) {
1290-
Log.e(LOGTAG,
1291-
"Caught exception while waiting for createWindow");
1292-
Log.e(LOGTAG, Log.getStackTraceString(e));
1293-
}
1294-
}
1295-
1267+
sendMessageToUiThreadSync(obtainMessage(CREATE_WINDOW, dialog ? 1 : 0,
1268+
userGesture ? 1 : 0, msg));
12961269
WebViewClassic w = WebViewClassic.fromWebView(transport.getWebView());
12971270
if (w != null) {
12981271
WebViewCore core = w.getWebViewCore();
@@ -1375,15 +1348,7 @@ public void onJsAlert(String url, String message) {
13751348
Message alert = obtainMessage(JS_ALERT, result);
13761349
alert.getData().putString("message", message);
13771350
alert.getData().putString("url", url);
1378-
synchronized (this) {
1379-
sendMessage(alert);
1380-
try {
1381-
wait();
1382-
} catch (InterruptedException e) {
1383-
Log.e(LOGTAG, "Caught exception while waiting for jsAlert");
1384-
Log.e(LOGTAG, Log.getStackTraceString(e));
1385-
}
1386-
}
1351+
sendMessageToUiThreadSync(alert);
13871352
}
13881353

13891354
public boolean onJsConfirm(String url, String message) {
@@ -1396,15 +1361,7 @@ public boolean onJsConfirm(String url, String message) {
13961361
Message confirm = obtainMessage(JS_CONFIRM, result);
13971362
confirm.getData().putString("message", message);
13981363
confirm.getData().putString("url", url);
1399-
synchronized (this) {
1400-
sendMessage(confirm);
1401-
try {
1402-
wait();
1403-
} catch (InterruptedException e) {
1404-
Log.e(LOGTAG, "Caught exception while waiting for jsConfirm");
1405-
Log.e(LOGTAG, Log.getStackTraceString(e));
1406-
}
1407-
}
1364+
sendMessageToUiThreadSync(confirm);
14081365
return result.mJsResult.getResult();
14091366
}
14101367

@@ -1419,15 +1376,7 @@ public String onJsPrompt(String url, String message, String defaultValue) {
14191376
prompt.getData().putString("message", message);
14201377
prompt.getData().putString("default", defaultValue);
14211378
prompt.getData().putString("url", url);
1422-
synchronized (this) {
1423-
sendMessage(prompt);
1424-
try {
1425-
wait();
1426-
} catch (InterruptedException e) {
1427-
Log.e(LOGTAG, "Caught exception while waiting for jsPrompt");
1428-
Log.e(LOGTAG, Log.getStackTraceString(e));
1429-
}
1430-
}
1379+
sendMessageToUiThreadSync(prompt);
14311380
return result.mJsResult.getStringResult();
14321381
}
14331382

@@ -1441,15 +1390,7 @@ public boolean onJsBeforeUnload(String url, String message) {
14411390
Message confirm = obtainMessage(JS_UNLOAD, result);
14421391
confirm.getData().putString("message", message);
14431392
confirm.getData().putString("url", url);
1444-
synchronized (this) {
1445-
sendMessage(confirm);
1446-
try {
1447-
wait();
1448-
} catch (InterruptedException e) {
1449-
Log.e(LOGTAG, "Caught exception while waiting for jsUnload");
1450-
Log.e(LOGTAG, Log.getStackTraceString(e));
1451-
}
1452-
}
1393+
sendMessageToUiThreadSync(confirm);
14531394
return result.mJsResult.getResult();
14541395
}
14551396

@@ -1586,15 +1527,7 @@ public boolean onJsTimeout() {
15861527
}
15871528
JsResultReceiver result = new JsResultReceiver();
15881529
Message timeout = obtainMessage(JS_TIMEOUT, result);
1589-
synchronized (this) {
1590-
sendMessage(timeout);
1591-
try {
1592-
wait();
1593-
} catch (InterruptedException e) {
1594-
Log.e(LOGTAG, "Caught exception while waiting for jsUnload");
1595-
Log.e(LOGTAG, Log.getStackTraceString(e));
1596-
}
1597-
}
1530+
sendMessageToUiThreadSync(timeout);
15981531
return result.mJsResult.getResult();
15991532
}
16001533

@@ -1655,16 +1588,7 @@ public Uri getResult() {
16551588
UploadFile uploadFile = new UploadFile();
16561589
UploadFileMessageData data = new UploadFileMessageData(uploadFile, acceptType, capture);
16571590
myMessage.obj = data;
1658-
synchronized (this) {
1659-
sendMessage(myMessage);
1660-
try {
1661-
wait();
1662-
} catch (InterruptedException e) {
1663-
Log.e(LOGTAG,
1664-
"Caught exception while waiting for openFileChooser");
1665-
Log.e(LOGTAG, Log.getStackTraceString(e));
1666-
}
1667-
}
1591+
sendMessageToUiThreadSync(myMessage);
16681592
return uploadFile.getResult();
16691593
}
16701594

@@ -1723,4 +1647,16 @@ void onSearchboxDispatchCompleteCallback(String function, int id, boolean succes
17231647

17241648
sendMessage(msg);
17251649
}
1650+
1651+
private synchronized void sendMessageToUiThreadSync(Message msg) {
1652+
sendMessage(msg);
1653+
WebCoreThreadWatchdog.pause();
1654+
try {
1655+
wait();
1656+
} catch (InterruptedException e) {
1657+
Log.e(LOGTAG, "Caught exception waiting for synchronous UI message to be processed");
1658+
Log.e(LOGTAG, Log.getStackTraceString(e));
1659+
}
1660+
WebCoreThreadWatchdog.resume();
1661+
}
17261662
}

0 commit comments

Comments
 (0)