From 6198e68ea71b5a1295532f304e8281897d7a652b Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 15 Dec 2011 17:16:50 +0000 Subject: Fix AppCache when either no path or an invalid path is supplied Only enable AppCache when it's been enabled with a call to WebSetting.setAppCacheEnabled() and if a valid path has been supplied to WebSetting.setAppCachePath(). Requires a corresponding change to frameworks/base: https://android-git.corp.google.com/g/155450 Bug: 5745181 Change-Id: I08d0016e19c436edef725f6ad2513bd369fda7b9 --- Source/WebKit/android/jni/WebSettings.cpp | 36 ++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'Source/WebKit/android') diff --git a/Source/WebKit/android/jni/WebSettings.cpp b/Source/WebKit/android/jni/WebSettings.cpp index 589615d..66524bd 100644 --- a/Source/WebKit/android/jni/WebSettings.cpp +++ b/Source/WebKit/android/jni/WebSettings.cpp @@ -420,22 +420,38 @@ public: #endif #if ENABLE(OFFLINE_WEB_APPLICATIONS) - flag = env->GetBooleanField(obj, gFieldIds->mAppCacheEnabled); - s->setOfflineWebApplicationCacheEnabled(flag); - str = (jstring)env->GetObjectField(obj, gFieldIds->mAppCachePath); - if (str) { - String path = jstringToWtfString(env, str); - if (path.length() && cacheStorage().cacheDirectory().isNull()) { - cacheStorage().setCacheDirectory(path); + // We only enable AppCache if it's been enabled with a call to + // setAppCacheEnabled() and if a valid path has been supplied to + // setAppCachePath(). Note that the path is applied to all WebViews + // whereas enabling is applied per WebView. + + // WebCore asserts that the path is only set once. Since the path is + // shared between WebViews, we can't do the required checks to guard + // against this in the Java WebSettings. + bool isPathValid = false; + if (cacheStorage().cacheDirectory().isNull()) { + str = static_cast(env->GetObjectField(obj, gFieldIds->mAppCachePath)); + // Check for non-null string as an optimization, as this is the common case. + if (str) { + String path = jstringToWtfString(env, str); + LOG_ASSERT(!path.empty(), "Java side should never send empty string for AppCache path"); // This database is created on the first load. If the file // doesn't exist, we create it and set its permissions. The // filename must match that in ApplicationCacheStorage.cpp. String filename = pathByAppendingComponent(path, "ApplicationCache.db"); - int fd = open(filename.utf8().data(), O_CREAT | O_EXCL, permissionFlags660); - if (fd >= 0) + int fd = open(filename.utf8().data(), O_CREAT, permissionFlags660); + if (fd >= 0) { close(fd); + cacheStorage().setCacheDirectory(path); + isPathValid = true; + } } - } + } else + isPathValid = true; + + flag = env->GetBooleanField(obj, gFieldIds->mAppCacheEnabled); + s->setOfflineWebApplicationCacheEnabled(flag && isPathValid); + jlong maxsize = env->GetLongField(obj, gFieldIds->mAppCacheMaxSize); cacheStorage().setMaximumSize(maxsize); #endif -- cgit v1.1