From aaf3891e3fa267d7f6c606016315f1d6d28badfb Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Tue, 8 Mar 2011 00:45:43 -0500 Subject: [PATCH] bug 638523 - Save Image saves htm, not the image r=dougt a=blocking-fennec --- embedding/android/GeckoApp.java | 2 +- embedding/android/GeckoAppShell.java | 8 +++++-- .../exthandler/android/nsMIMEInfoAndroid.cpp | 16 +++++++++++-- widget/src/android/AndroidBridge.cpp | 24 ++++++++++++++++--- widget/src/android/AndroidBridge.h | 2 ++ 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 9c6274c4b0c..64247aa9a13 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -636,7 +636,7 @@ abstract public class GeckoApp Uri uri = data.getData(); String mimeType = cr.getType(uri); String fileExt = "." + - mimeType.substring(mimeType.lastIndexOf('/') + 1); + GeckoAppShell.getExtensionFromMimeType(mimeType); File file = File.createTempFile("tmp_" + (int)Math.floor(1000 * Math.random()), diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index d0b85c8c964..06a0953f845 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -58,6 +58,7 @@ import android.graphics.*; import android.widget.*; import android.hardware.*; import android.location.*; +import android.webkit.MimeTypeMap; import android.util.*; import android.net.Uri; @@ -649,9 +650,12 @@ public class GeckoAppShell return new Intent(Intent.ACTION_VIEW); } + static String getExtensionFromMimeType(String aMimeType) { + return MimeTypeMap.getSingleton().getExtensionFromMimeType(aMimeType); + } + static String getMimeTypeFromExtensions(String aFileExt) { - android.webkit.MimeTypeMap mtm = - android.webkit.MimeTypeMap.getSingleton(); + MimeTypeMap mtm = MimeTypeMap.getSingleton(); StringTokenizer st = new StringTokenizer(aFileExt, "., "); String type = null; String subType = null; diff --git a/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp b/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp index bc52fb9f3b0..57c97708a47 100644 --- a/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp +++ b/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp @@ -88,6 +88,10 @@ nsMIMEInfoAndroid::GetMimeInfoForMimeType(const nsACString& aMimeType, if (systemDefault) info->mPrefApp = systemDefault; + nsCAutoString fileExt; + bridge->GetExtensionFromMimeType(nsDependentCString(aMimeType), fileExt); + info->SetPrimaryExtension(fileExt); + PRUint32 len; info->mHandlerApps->GetLength(&len); if (len == 1) { @@ -107,8 +111,10 @@ nsMIMEInfoAndroid::GetMimeInfoForFileExt(const nsACString& aFileExt, if (mozilla::AndroidBridge::Bridge()) mozilla::AndroidBridge::Bridge()-> GetMimeTypeFromExtensions(aFileExt, mimeType); - - return GetMimeInfoForMimeType(mimeType, aMimeInfo); + + nsresult rv = GetMimeInfoForMimeType(mimeType, aMimeInfo); + NS_ENSURE_SUCCESS(rv, rv); + return (*aMimeInfo)->SetPrimaryExtension(aFileExt); } /** @@ -138,6 +144,12 @@ nsMIMEInfoAndroid::GetMimeInfoForURL(const nsACString &aURL, mimeinfo->mPrefApp = systemDefault; + nsCAutoString fileExt; + nsCAutoString mimeType; + mimeinfo->GetType(mimeType); + bridge->GetExtensionFromMimeType(mimeType, fileExt); + mimeinfo->SetPrimaryExtension(fileExt); + PRUint32 len; mimeinfo->mHandlerApps->GetLength(&len); if (len == 1) { diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index fef60429331..9bd576fc657 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -119,6 +119,7 @@ AndroidBridge::Init(JNIEnv *jEnv, jGetHandlersForURL = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getHandlersForURL", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"); jOpenUriExternal = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "openUriExternal", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z"); jGetMimeTypeFromExtensions = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getMimeTypeFromExtensions", "(Ljava/lang/String;)Ljava/lang/String;"); + jGetExtensionFromMimeType = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getExtensionFromMimeType", "(Ljava/lang/String;)Ljava/lang/String;"); jMoveTaskToBack = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "moveTaskToBack", "()V"); jGetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getClipboardText", "()Ljava/lang/String;"); jSetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setClipboardText", "(Ljava/lang/String;)V"); @@ -454,13 +455,30 @@ AndroidBridge::GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& AutoLocalJNIFrame jniFrame; NS_ConvertUTF8toUTF16 wFileExt(aFileExt); jstring jstrExt = mJNIEnv->NewString(wFileExt.get(), wFileExt.Length()); - jstring jstrType = static_cast(mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass, - jGetMimeTypeFromExtensions, - jstrExt)); + jstring jstrType = static_cast( + mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass, + jGetMimeTypeFromExtensions, + jstrExt)); nsJNIString jniStr(jstrType); aMimeType.Assign(NS_ConvertUTF16toUTF8(jniStr.get())); } +void +AndroidBridge::GetExtensionFromMimeType(const nsCString& aMimeType, nsACString& aFileExt) +{ + ALOG_BRIDGE("AndroidBridge::GetExtensionFromMimeType"); + + AutoLocalJNIFrame jniFrame; + NS_ConvertUTF8toUTF16 wMimeType(aMimeType); + jstring jstrType = mJNIEnv->NewString(wMimeType.get(), wMimeType.Length()); + jstring jstrExt = static_cast( + mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass, + jGetExtensionFromMimeType, + jstrType)); + nsJNIString jniStr(jstrExt); + aFileExt.Assign(NS_ConvertUTF16toUTF8(jniStr.get())); +} + void AndroidBridge::MoveTaskToBack() { diff --git a/widget/src/android/AndroidBridge.h b/widget/src/android/AndroidBridge.h index 1af266363ce..592645c3e5d 100644 --- a/widget/src/android/AndroidBridge.h +++ b/widget/src/android/AndroidBridge.h @@ -145,6 +145,7 @@ public: const nsAString& aTitle = EmptyString()); void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType); + void GetExtensionFromMimeType(const nsCString& aMimeType, nsACString& aFileExt); void MoveTaskToBack(); @@ -260,6 +261,7 @@ protected: jmethodID jGetHandlersForURL; jmethodID jOpenUriExternal; jmethodID jGetMimeTypeFromExtensions; + jmethodID jGetExtensionFromMimeType; jmethodID jMoveTaskToBack; jmethodID jGetClipboardText; jmethodID jSetClipboardText;