From fe59b91fa123e0d98b57941b4446cceec38f3c26 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Wed, 1 Jun 2011 20:40:38 -0400 Subject: [PATCH] bug 638940 - File Upload: we should not change file names, paths and extensions r=dougt --- embedding/android/GeckoApp.java | 36 ++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index b146a996a49..e97eb7b30b1 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -59,6 +59,8 @@ import android.hardware.*; import android.util.*; import android.net.*; +import android.database.*; +import android.provider.*; abstract public class GeckoApp extends Activity @@ -654,13 +656,33 @@ abstract public class GeckoApp try { ContentResolver cr = getContentResolver(); Uri uri = data.getData(); - String mimeType = cr.getType(uri); - String fileExt = "." + - GeckoAppShell.getExtensionFromMimeType(mimeType); - File file = - File.createTempFile("tmp_" + - (int)Math.floor(1000 * Math.random()), - fileExt, sGREDir); + Cursor cursor = GeckoApp.mAppContext.getContentResolver().query( + uri, + new String[] { OpenableColumns.DISPLAY_NAME }, + null, + null, + null); + String name = null; + if (cursor != null) { + try { + if (cursor.moveToNext()) { + name = cursor.getString(0); + } + } finally { + cursor.close(); + } + } + String fileName = "tmp_"; + String fileExt = null; + int period; + if (name == null || (period = name.lastIndexOf('.')) == -1) { + String mimeType = cr.getType(uri); + fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType); + } else { + fileExt = name.substring(period); + fileName = name.substring(0, period); + } + File file = File.createTempFile(fileName, fileExt, sGREDir); FileOutputStream fos = new FileOutputStream(file); InputStream is = cr.openInputStream(uri);