Accept freeMemory messages and pass them to the native code
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index da8d20b..31b976e7 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -1941,6 +1941,15 @@
}
/**
+ * 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 797250e..066729c 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -590,6 +590,7 @@
"SET_ACTIVE", // = 142;
"ON_PAUSE", // = 143
"ON_RESUME", // = 144
+ "FREE_MEMORY", // = 145
};
class EventHub {
@@ -645,10 +646,11 @@
// 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 @@
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 @@
break;
case CLEAR_CACHE:
- mBrowserFrame.clearCache();
- if (msg.arg1 == 1) {
- CacheManager.removeAllCacheFiles();
- }
+ clearCache(msg.arg1 == 1);
break;
case CLEAR_HISTORY:
@@ -1223,6 +1227,13 @@
// 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 @@
private native void nativePause();
private native void nativeResume();
+ private native void nativeFreeMemory();
}