changeset 3690:cb31383a05ed

RT-29592: File input doesn't store size of selected file(s) properly
author Vasiliy Baranov <vasiliy.baranov@oracle.com>
date Mon, 27 May 2013 13:06:46 +0400
parents 531ed15ca4e1
children 4974dfa78b67
files webview/native/Source/WebCore/platform/java/FileSystemJava.cpp webview/src/com/sun/webkit/FileSystem.java
diffstat 2 files changed, 58 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/webview/native/Source/WebCore/platform/java/FileSystemJava.cpp	Mon May 27 14:38:58 2013 +0400
+++ b/webview/native/Source/WebCore/platform/java/FileSystemJava.cpp	Mon May 27 13:06:46 2013 +0400
@@ -7,22 +7,11 @@
 #include "FileMetadata.h"
 #include "JavaEnv.h"
 
-static JGClass fileSystemClass;
-static jmethodID pathGetFileNameMID;
-
-static void initRefs(JNIEnv* env)
+static jclass GetFileSystemClass(JNIEnv* env)
 {
-    if (!fileSystemClass) {
-        fileSystemClass = JLClass(env->FindClass(
-                "com/sun/webkit/FileSystem"));
-        ASSERT(fileSystemClass);
-
-        pathGetFileNameMID = env->GetStaticMethodID(
-                fileSystemClass,
-                "fwkPathGetFileName",
-                "(Ljava/lang/String;)Ljava/lang/String;");
-        ASSERT(pathGetFileNameMID);
-    }
+    static JGClass clazz(env->FindClass("com/sun/webkit/FileSystem"));
+    ASSERT(clazz);
+    return clazz;
 }
 
 namespace WebCore {
@@ -45,10 +34,28 @@
     return false;
 }
 
-bool getFileSize(String const&, long long&)
+bool getFileSize(const String& path, long long& result)
 {
-    notImplemented();
-    return false;
+    JNIEnv* env = WebCore_GetJavaEnv();
+
+    static jmethodID mid = env->GetStaticMethodID(
+            GetFileSystemClass(env),
+            "fwkGetFileSize",
+            "(Ljava/lang/String;)J");
+    ASSERT(mid);
+
+    jlong size = env->CallStaticLongMethod(
+            GetFileSystemClass(env),
+            mid,
+            (jstring) path.toJavaString(env));
+    CheckAndClearException(env);
+
+    if (size >= 0) {
+        result = size;
+        return true;
+    } else {
+        return false;
+    }
 }
 
 bool getFileModificationTime(const String&, time_t& result)
@@ -127,15 +134,20 @@
 String pathGetFileName(const String& path)
 {
     JNIEnv* env = WebCore_GetJavaEnv();
-    initRefs(env);
-    
+
+    static jmethodID mid = env->GetStaticMethodID(
+            GetFileSystemClass(env),
+            "fwkPathGetFileName",
+            "(Ljava/lang/String;)Ljava/lang/String;");
+    ASSERT(mid);
+
     JLString result = static_cast<jstring>(env->CallStaticObjectMethod(
-            fileSystemClass,
-            pathGetFileNameMID,
-            (jstring)path.toJavaString(env)));
+            GetFileSystemClass(env),
+            mid,
+            (jstring) path.toJavaString(env)));
     CheckAndClearException(env);
 
-    return String(env, result);    
+    return String(env, result);
 }
 
 } // namespace WebCore
--- a/webview/src/com/sun/webkit/FileSystem.java	Mon May 27 14:38:58 2013 +0400
+++ b/webview/src/com/sun/webkit/FileSystem.java	Mon May 27 13:06:46 2013 +0400
@@ -4,23 +4,34 @@
 package com.sun.webkit;
 
 import java.io.File;
+import static java.lang.String.format;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
-/**
- * The implementation of the file system-related WebKit callbacks.
- */
 final class FileSystem {
-    
-    /**
-     * The private default constructor. Ensures non-instantiability.
-     */
+
+    private final static Logger logger =
+            Logger.getLogger(FileSystem.class.getName());
+
+
     private FileSystem() {
         throw new AssertionError();
     }
-    
 
-    /**
-     * Given a file path, returns the name of the file.
-     */
+
+    private static long fwkGetFileSize(String path) {
+        try {
+            File file = new File(path);
+            if (file.exists()) {
+                return file.length();
+            }
+        } catch (SecurityException ex) {
+            logger.log(Level.FINE, format("Error determining "
+                    + "size of file [%s]", path), ex);
+        }
+        return -1;
+    }
+
     private static String fwkPathGetFileName(String path) {
         return new File(path).getName();
     }