OSDN Git Service

Fixes cookiejar and webicon permissions
authorJohn Reck <jreck@google.com>
Tue, 7 Dec 2010 22:51:01 +0000 (14:51 -0800)
committerJohn Reck <jreck@google.com>
Fri, 10 Dec 2010 18:44:53 +0000 (10:44 -0800)
 Bug: 3244281

Change-Id: Ib7359e5524aeaf4f82f52603e83dde3e99c507c2

WebKit/android/WebCoreSupport/WebCookieJar.cpp
WebKit/android/jni/WebIconDatabase.cpp

index afa87c2..374dcd9 100644 (file)
@@ -94,6 +94,16 @@ WebCookieJar::WebCookieJar(const std::string& databaseFilePath)
     // This is needed for the page cycler. See http://b/2944150
     net::CookieMonster::EnableFileScheme();
 
+    // Setup the permissions for the file
+    const char* cDatabasePath = databaseFilePath.c_str();
+    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+    if (access(cDatabasePath, F_OK) == 0)
+        chmod(cDatabasePath, mode);
+    else {
+        int fd = open(cDatabasePath, O_CREAT, mode);
+        if (fd >= 0)
+            close(fd);
+    }
     FilePath cookiePath(databaseFilePath.c_str());
     m_cookieDb = new SQLitePersistentCookieStore(cookiePath);
     m_cookieStore = new net::CookieMonster(m_cookieDb.get(), 0);
index a9f6b05..2a660d1 100644 (file)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "WebIconDatabase.h"
 
+#include "FileSystem.h"
 #include "GraphicsJNI.h"
 #include "IconDatabase.h"
 #include "Image.h"
@@ -140,10 +141,27 @@ static void Open(JNIEnv* env, jobject obj, jstring path)
     iconDb->setClient(gIconDatabaseClient);
     LOG_ASSERT(path, "No path given to nativeOpen");
     WTF::String pathStr = jstringToWtfString(env, path);
-    LOGV("Opening WebIconDatabase file '%s'", pathStr.latin1().data());
-    bool res = iconDb->open(pathStr);
-    if (!res)
-        LOGE("Open failed!");
+    WTF::CString fullPath = WebCore::pathByAppendingComponent(pathStr,
+            WebCore::IconDatabase::defaultDatabaseFilename()).utf8();
+    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+    bool didSetPermissions = false;
+    if (access(fullPath.data(), F_OK) == 0) {
+        if (chmod(fullPath.data(), mode) == 0)
+            didSetPermissions = true;
+    } else {
+        int fd = open(fullPath.data(), O_CREAT, mode);
+        if (fd >= 0) {
+            close(fd);
+            didSetPermissions = true;
+        }
+    }
+    if (didSetPermissions) {
+        LOGV("Opening WebIconDatabase file '%s'", pathStr.latin1().data());
+        bool res = iconDb->open(pathStr);
+        if (!res)
+            LOGE("Open failed!");
+    } else
+        LOGE("Failed to set permissions on '%s'", fullPath.data());
 }
 
 static void Close(JNIEnv* env, jobject obj)