Skip to content

Commit a95e9da

Browse files
Ben MurdochAndroid (Google) Code Review
authored andcommitted
Merge "Make the WebCore thread watchdog opt in." into jb-dev
2 parents fd82448 + 2b5d668 commit a95e9da

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

core/java/android/webkit/WebViewClassic.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8494,6 +8494,11 @@ private void postInvalidate() {
84948494
mWebView.postInvalidate();
84958495
}
84968496

8497+
// Note: must be called before first WebViewClassic is created.
8498+
public static void setShouldMonitorWebCoreThread() {
8499+
WebViewCore.setShouldMonitorWebCoreThread();
8500+
}
8501+
84978502
private native void nativeCreate(int ptr, String drawableDir, boolean isHighEndGfx);
84988503
private native void nativeDebugDump();
84998504
private native void nativeDestroy();

core/java/android/webkit/WebViewCore.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public final class WebViewCore {
144144
private int mChromeCanFocusDirection;
145145
private int mTextSelectionChangeReason = TextSelectionData.REASON_UNKNOWN;
146146

147+
// Used to determine if we should monitor the WebCore thread for responsiveness.
148+
// If it "hangs", for example a web page enters a while(true) loop, we will
149+
// prompt the user with a dialog allowing them to terminate the process.
150+
private static boolean sShouldMonitorWebCoreThread;
151+
147152
// The thread name used to identify the WebCore thread and for use in
148153
// debugging other classes that require operation within the WebCore thread.
149154
/* package */ static final String THREAD_NAME = "WebViewCoreThread";
@@ -176,9 +181,13 @@ public WebViewCore(Context context, WebViewClassic w, CallbackProxy proxy,
176181
Log.e(LOGTAG, Log.getStackTraceString(e));
177182
}
178183

179-
// Start the singleton watchdog which will monitor the WebCore thread
180-
// to verify it's still processing messages.
181-
WebCoreThreadWatchdog.start(sWebCoreHandler);
184+
if (sShouldMonitorWebCoreThread) {
185+
// Start the singleton watchdog which will monitor the WebCore thread
186+
// to verify it's still processing messages. Note that this is the only
187+
// time we need to check the value as all the other public methods on
188+
// the WebCoreThreadWatchdog are no-ops if start() is not called.
189+
WebCoreThreadWatchdog.start(sWebCoreHandler);
190+
}
182191
}
183192
// Make sure the Watchdog is aware of this new WebView.
184193
WebCoreThreadWatchdog.registerWebView(w);
@@ -3061,6 +3070,10 @@ protected DeviceOrientationService getDeviceOrientationService() {
30613070
return mDeviceOrientationService;
30623071
}
30633072

3073+
static void setShouldMonitorWebCoreThread() {
3074+
sShouldMonitorWebCoreThread = true;
3075+
}
3076+
30643077
private native void nativeSetIsPaused(int nativeClass, boolean isPaused);
30653078
private native void nativePause(int nativeClass);
30663079
private native void nativeResume(int nativeClass);

0 commit comments

Comments
 (0)