Skip to content

Commit e00e8a7

Browse files
committed
Pause WebKit drawing when WebView loses window focus.
This prevents animations and other live page content from consuming too many resources while the user is interacting with a popup window. Bug 5300522 Change-Id: I40fb6d16d56b540c431172052a1ae7fead7109be
1 parent aeb1167 commit e00e8a7

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

core/java/android/webkit/WebSettings.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,10 @@ public boolean getLoadWithOverviewMode() {
643643

644644
/**
645645
* Set whether the WebView will enable smooth transition while panning or
646-
* zooming. If it is true, WebView will choose a solution to maximize the
647-
* performance. e.g. the WebView's content may not be updated during the
648-
* transition. If it is false, WebView will keep its fidelity. The default
649-
* value is false.
646+
* zooming or while the window hosting the WebView does not have focus.
647+
* If it is true, WebView will choose a solution to maximize the performance.
648+
* e.g. the WebView's content may not be updated during the transition.
649+
* If it is false, WebView will keep its fidelity. The default value is false.
650650
*/
651651
public void setEnableSmoothTransition(boolean enable) {
652652
mEnableSmoothTransition = enable;

core/java/android/webkit/WebView.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,9 @@ public void onTrimMemory(int level) {
908908
// used for serializing asynchronously handled touch events.
909909
private final TouchEventQueue mTouchEventQueue = new TouchEventQueue();
910910

911+
// Used to track whether picture updating was paused due to a window focus change.
912+
private boolean mPictureUpdatePausedForFocusChange = false;
913+
911914
// Used to notify listeners of a new picture.
912915
private PictureListener mPictureListener;
913916
/**
@@ -5570,8 +5573,20 @@ public void onWindowFocusChanged(boolean hasWindowFocus) {
55705573
setActive(hasWindowFocus);
55715574
if (hasWindowFocus) {
55725575
JWebCoreJavaBridge.setActiveWebView(this);
5576+
if (mPictureUpdatePausedForFocusChange) {
5577+
WebViewCore.resumeUpdatePicture(mWebViewCore);
5578+
nativeSetIsScrolling(false);
5579+
mPictureUpdatePausedForFocusChange = false;
5580+
}
55735581
} else {
55745582
JWebCoreJavaBridge.removeActiveWebView(this);
5583+
final WebSettings settings = getSettings();
5584+
if (settings != null && settings.enableSmoothTransition() &&
5585+
mWebViewCore != null && !WebViewCore.isUpdatePicturePaused(mWebViewCore)) {
5586+
WebViewCore.pauseUpdatePicture(mWebViewCore);
5587+
nativeSetIsScrolling(true);
5588+
mPictureUpdatePausedForFocusChange = true;
5589+
}
55755590
}
55765591
super.onWindowFocusChanged(hasWindowFocus);
55775592
}

core/java/android/webkit/WebViewCore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,10 @@ static void resumeUpdatePicture(WebViewCore core) {
21072107
}
21082108
}
21092109

2110+
static boolean isUpdatePicturePaused(WebViewCore core) {
2111+
return core != null ? core.mDrawIsPaused : false;
2112+
}
2113+
21102114
//////////////////////////////////////////////////////////////////////////
21112115

21122116
private void restoreState(int index) {

0 commit comments

Comments
 (0)