bug 638523 - Save Image saves htm, not the image r=dougt a=blocking-fennec

This commit is contained in:
Brad Lassey 2011-03-08 00:45:43 -05:00
Родитель 88b81c8eca
Коммит aaf3891e3f
5 изменённых файлов: 44 добавлений и 8 удалений

Просмотреть файл

@ -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()),

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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<jstring>(mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
jGetMimeTypeFromExtensions,
jstrExt));
jstring jstrType = static_cast<jstring>(
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<jstring>(
mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
jGetExtensionFromMimeType,
jstrType));
nsJNIString jniStr(jstrExt);
aFileExt.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
}
void
AndroidBridge::MoveTaskToBack()
{

Просмотреть файл

@ -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;