summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-05-28 05:00:01 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-05-28 05:00:01 -0700
commitc26ba7928022ff08a5ff3e90aa9e8f4242350435 (patch)
tree3ae68f30e67b2db656ed842836dfc928c8eba476
parent0ae234c991f46a4fd6c9abb44edba7af89569718 (diff)
parentd205d5b57071dd9e53a42184f8a5fc5cd7398209 (diff)
downloadframeworks_base-c26ba7928022ff08a5ff3e90aa9e8f4242350435.zip
frameworks_base-c26ba7928022ff08a5ff3e90aa9e8f4242350435.tar.gz
frameworks_base-c26ba7928022ff08a5ff3e90aa9e8f4242350435.tar.bz2
Merge change 2525
* changes: add onPause and onResume apis, to inform the view when it can pause its activities associated with the DOM.
-rw-r--r--core/java/android/webkit/WebView.java50
-rw-r--r--core/java/android/webkit/WebViewCore.java18
2 files changed, 63 insertions, 5 deletions
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 8fff644..eef128b 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -370,6 +370,9 @@ public class WebView extends AbsoluteLayout
// Whether or not to draw the focus ring.
private boolean mDrawFocusRing = true;
+ // true if onPause has been called (and not onResume)
+ private boolean mIsPaused;
+
/**
* Customizable constant
*/
@@ -997,7 +1000,7 @@ public class WebView extends AbsoluteLayout
/**
* If platform notifications are enabled, this should be called
- * from onPause() or onStop().
+ * from the Activity's onPause() or onStop().
*/
public static void disablePlatformNotifications() {
Network.disablePlatformNotifications();
@@ -1938,22 +1941,59 @@ public class WebView extends AbsoluteLayout
}
/**
- * Pause all layout, parsing, and javascript timers. This can be useful if
- * the WebView is not visible or the application has been paused.
+ * Pause all layout, parsing, and javascript timers for all webviews. This
+ * is a global requests, not restricted to just this webview. This can be
+ * useful if the application has been paused.
*/
public void pauseTimers() {
mWebViewCore.sendMessage(EventHub.PAUSE_TIMERS);
}
/**
- * Resume all layout, parsing, and javascript timers. This will resume
- * dispatching all timers.
+ * Resume all layout, parsing, and javascript timers for all webviews.
+ * This will resume dispatching all timers.
*/
public void resumeTimers() {
mWebViewCore.sendMessage(EventHub.RESUME_TIMERS);
}
/**
+ * Call this to pause any extra processing associated with this view and
+ * its associated DOM/plugins/javascript/etc. For example, if the view is
+ * taken offscreen, this could be called to reduce unnecessary CPU and/or
+ * network traffic. When the view is again "active", call onResume().
+ *
+ * Note that this differs from pauseTimers(), which affects all views/DOMs
+ * @hide
+ */
+ public void onPause() {
+ if (!mIsPaused) {
+ mIsPaused = true;
+ mWebViewCore.sendMessage(EventHub.ON_PAUSE);
+ }
+ }
+
+ /**
+ * Call this to balanace a previous call to onPause()
+ * @hide
+ */
+ public void onResume() {
+ if (mIsPaused) {
+ mIsPaused = false;
+ mWebViewCore.sendMessage(EventHub.ON_RESUME);
+ }
+ }
+
+ /**
+ * Returns true if the view is paused, meaning onPause() was called. Calling
+ * onResume() sets the paused state back to false.
+ * @hide
+ */
+ public boolean isPaused() {
+ return mIsPaused;
+ }
+
+ /**
* Clear the resource cache. Note that the cache is per-application, so
* this will clear the cache for all WebViews used.
*
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index e4d08cf..f9bbc31 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -591,6 +591,8 @@ final class WebViewCore {
"TOUCH_UP", // = 140;
"TOUCH_EVENT", // = 141;
"SET_ACTIVE", // = 142;
+ "ON_PAUSE", // = 143
+ "ON_RESUME", // = 144
};
class EventHub {
@@ -647,6 +649,11 @@ final class WebViewCore {
// or not, based on whether the WebView has focus.
static final int SET_ACTIVE = 142;
+ // pause/resume activity for just this DOM (unlike pauseTimers, which
+ // is global)
+ static final int ON_PAUSE = 143;
+ static final int ON_RESUME = 144;
+
// Network-based messaging
static final int CLEAR_SSL_PREF_TABLE = 150;
@@ -841,6 +848,14 @@ final class WebViewCore {
}
break;
+ case ON_PAUSE:
+ nativePause();
+ break;
+
+ case ON_RESUME:
+ nativeResume();
+ break;
+
case SET_NETWORK_STATE:
if (BrowserFrame.sJavaBridge == null) {
throw new IllegalStateException("No WebView " +
@@ -1750,4 +1765,7 @@ final class WebViewCore {
}
}
+
+ private native void nativePause();
+ private native void nativeResume();
}