зеркало из https://github.com/mozilla/pjs.git
bug 638523 - Save Image saves htm, not the image r=dougt a=blocking-fennec
This commit is contained in:
Родитель
88b81c8eca
Коммит
aaf3891e3f
|
@ -636,7 +636,7 @@ abstract public class GeckoApp
|
||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String mimeType = cr.getType(uri);
|
String mimeType = cr.getType(uri);
|
||||||
String fileExt = "." +
|
String fileExt = "." +
|
||||||
mimeType.substring(mimeType.lastIndexOf('/') + 1);
|
GeckoAppShell.getExtensionFromMimeType(mimeType);
|
||||||
File file =
|
File file =
|
||||||
File.createTempFile("tmp_" +
|
File.createTempFile("tmp_" +
|
||||||
(int)Math.floor(1000 * Math.random()),
|
(int)Math.floor(1000 * Math.random()),
|
||||||
|
|
|
@ -58,6 +58,7 @@ import android.graphics.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import android.hardware.*;
|
import android.hardware.*;
|
||||||
import android.location.*;
|
import android.location.*;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -649,9 +650,12 @@ public class GeckoAppShell
|
||||||
return new Intent(Intent.ACTION_VIEW);
|
return new Intent(Intent.ACTION_VIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String getExtensionFromMimeType(String aMimeType) {
|
||||||
|
return MimeTypeMap.getSingleton().getExtensionFromMimeType(aMimeType);
|
||||||
|
}
|
||||||
|
|
||||||
static String getMimeTypeFromExtensions(String aFileExt) {
|
static String getMimeTypeFromExtensions(String aFileExt) {
|
||||||
android.webkit.MimeTypeMap mtm =
|
MimeTypeMap mtm = MimeTypeMap.getSingleton();
|
||||||
android.webkit.MimeTypeMap.getSingleton();
|
|
||||||
StringTokenizer st = new StringTokenizer(aFileExt, "., ");
|
StringTokenizer st = new StringTokenizer(aFileExt, "., ");
|
||||||
String type = null;
|
String type = null;
|
||||||
String subType = null;
|
String subType = null;
|
||||||
|
|
|
@ -88,6 +88,10 @@ nsMIMEInfoAndroid::GetMimeInfoForMimeType(const nsACString& aMimeType,
|
||||||
if (systemDefault)
|
if (systemDefault)
|
||||||
info->mPrefApp = systemDefault;
|
info->mPrefApp = systemDefault;
|
||||||
|
|
||||||
|
nsCAutoString fileExt;
|
||||||
|
bridge->GetExtensionFromMimeType(nsDependentCString(aMimeType), fileExt);
|
||||||
|
info->SetPrimaryExtension(fileExt);
|
||||||
|
|
||||||
PRUint32 len;
|
PRUint32 len;
|
||||||
info->mHandlerApps->GetLength(&len);
|
info->mHandlerApps->GetLength(&len);
|
||||||
if (len == 1) {
|
if (len == 1) {
|
||||||
|
@ -108,7 +112,9 @@ nsMIMEInfoAndroid::GetMimeInfoForFileExt(const nsACString& aFileExt,
|
||||||
mozilla::AndroidBridge::Bridge()->
|
mozilla::AndroidBridge::Bridge()->
|
||||||
GetMimeTypeFromExtensions(aFileExt, mimeType);
|
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;
|
mimeinfo->mPrefApp = systemDefault;
|
||||||
|
|
||||||
|
|
||||||
|
nsCAutoString fileExt;
|
||||||
|
nsCAutoString mimeType;
|
||||||
|
mimeinfo->GetType(mimeType);
|
||||||
|
bridge->GetExtensionFromMimeType(mimeType, fileExt);
|
||||||
|
mimeinfo->SetPrimaryExtension(fileExt);
|
||||||
|
|
||||||
PRUint32 len;
|
PRUint32 len;
|
||||||
mimeinfo->mHandlerApps->GetLength(&len);
|
mimeinfo->mHandlerApps->GetLength(&len);
|
||||||
if (len == 1) {
|
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;");
|
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");
|
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;");
|
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");
|
jMoveTaskToBack = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "moveTaskToBack", "()V");
|
||||||
jGetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getClipboardText", "()Ljava/lang/String;");
|
jGetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getClipboardText", "()Ljava/lang/String;");
|
||||||
jSetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setClipboardText", "(Ljava/lang/String;)V");
|
jSetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setClipboardText", "(Ljava/lang/String;)V");
|
||||||
|
@ -454,13 +455,30 @@ AndroidBridge::GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString&
|
||||||
AutoLocalJNIFrame jniFrame;
|
AutoLocalJNIFrame jniFrame;
|
||||||
NS_ConvertUTF8toUTF16 wFileExt(aFileExt);
|
NS_ConvertUTF8toUTF16 wFileExt(aFileExt);
|
||||||
jstring jstrExt = mJNIEnv->NewString(wFileExt.get(), wFileExt.Length());
|
jstring jstrExt = mJNIEnv->NewString(wFileExt.get(), wFileExt.Length());
|
||||||
jstring jstrType = static_cast<jstring>(mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
|
jstring jstrType = static_cast<jstring>(
|
||||||
|
mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
|
||||||
jGetMimeTypeFromExtensions,
|
jGetMimeTypeFromExtensions,
|
||||||
jstrExt));
|
jstrExt));
|
||||||
nsJNIString jniStr(jstrType);
|
nsJNIString jniStr(jstrType);
|
||||||
aMimeType.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
|
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
|
void
|
||||||
AndroidBridge::MoveTaskToBack()
|
AndroidBridge::MoveTaskToBack()
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,6 +145,7 @@ public:
|
||||||
const nsAString& aTitle = EmptyString());
|
const nsAString& aTitle = EmptyString());
|
||||||
|
|
||||||
void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
|
void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
|
||||||
|
void GetExtensionFromMimeType(const nsCString& aMimeType, nsACString& aFileExt);
|
||||||
|
|
||||||
void MoveTaskToBack();
|
void MoveTaskToBack();
|
||||||
|
|
||||||
|
@ -260,6 +261,7 @@ protected:
|
||||||
jmethodID jGetHandlersForURL;
|
jmethodID jGetHandlersForURL;
|
||||||
jmethodID jOpenUriExternal;
|
jmethodID jOpenUriExternal;
|
||||||
jmethodID jGetMimeTypeFromExtensions;
|
jmethodID jGetMimeTypeFromExtensions;
|
||||||
|
jmethodID jGetExtensionFromMimeType;
|
||||||
jmethodID jMoveTaskToBack;
|
jmethodID jMoveTaskToBack;
|
||||||
jmethodID jGetClipboardText;
|
jmethodID jGetClipboardText;
|
||||||
jmethodID jSetClipboardText;
|
jmethodID jSetClipboardText;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче