From e0155e955254f4ee4464d4c12545267727fcd89a Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Wed, 10 Jun 2009 15:35:45 -0400 Subject: [PATCH] Accept freeMemory messages and pass them to the native code --- core/java/android/webkit/WebView.java | 9 +++++++++ core/java/android/webkit/WebViewCore.java | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index da8d20b7660fe..31b976e79b418 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -1940,6 +1940,15 @@ public class WebView extends AbsoluteLayout return mIsPaused; } + /** + * Call this to inform the view that memory is low so that it can + * free any available memory. + * @hide + */ + public void freeMemory() { + mWebViewCore.sendMessage(EventHub.FREE_MEMORY); + } + /** * 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 797250ea0f0da..066729cad35de 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -590,6 +590,7 @@ final class WebViewCore { "SET_ACTIVE", // = 142; "ON_PAUSE", // = 143 "ON_RESUME", // = 144 + "FREE_MEMORY", // = 145 }; class EventHub { @@ -645,10 +646,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 + // lifecycle activities for just this DOM (unlike pauseTimers, which // is global) static final int ON_PAUSE = 143; static final int ON_RESUME = 144; + static final int FREE_MEMORY = 145; // Network-based messaging static final int CLEAR_SSL_PREF_TABLE = 150; @@ -848,6 +850,11 @@ final class WebViewCore { nativeResume(); break; + case FREE_MEMORY: + clearCache(false); + nativeFreeMemory(); + break; + case SET_NETWORK_STATE: if (BrowserFrame.sJavaBridge == null) { throw new IllegalStateException("No WebView " + @@ -858,10 +865,7 @@ final class WebViewCore { break; case CLEAR_CACHE: - mBrowserFrame.clearCache(); - if (msg.arg1 == 1) { - CacheManager.removeAllCacheFiles(); - } + clearCache(msg.arg1 == 1); break; case CLEAR_HISTORY: @@ -1223,6 +1227,13 @@ final class WebViewCore { // WebViewCore private methods //------------------------------------------------------------------------- + private void clearCache(boolean includeDiskFiles) { + mBrowserFrame.clearCache(); + if (includeDiskFiles) { + CacheManager.removeAllCacheFiles(); + } + } + private void loadUrl(String url) { if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, " CORE loadUrl " + url); mBrowserFrame.loadUrl(url); @@ -1721,4 +1732,5 @@ final class WebViewCore { private native void nativePause(); private native void nativeResume(); + private native void nativeFreeMemory(); }