| Index: chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| index 083f5148cad2ef85c81ced66463ffc1574544cf4..5a786ace914a3d7d623a1a2805d4f2e4a561963f 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| @@ -510,10 +510,7 @@ public class ChromeDownloadDelegate {
|
| || "application/force-download".equals(mimeType)
|
| || "application/unknown".equals(mimeType)) {
|
|
|
| - if (!TextUtils.isEmpty(filename)) {
|
| - url = filename;
|
| - }
|
| - String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
| + String extension = getFileExtension(url, filename);
|
| String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
| if (newMimeType != null) {
|
| mimeType = newMimeType;
|
| @@ -527,6 +524,22 @@ public class ChromeDownloadDelegate {
|
| }
|
|
|
| /**
|
| + * Retrieve the file extension from a given file name or url.
|
| + *
|
| + * @param url URL to extract the extension.
|
| + * @param filename File name to extract the extension.
|
| + * @return If extension can be extracted from file name, use that. Or otherwise, use the
|
| + * extension extracted from the url.
|
| + */
|
| + static String getFileExtension(String url, String filename) {
|
| + if (!TextUtils.isEmpty(filename)) {
|
| + int index = filename.lastIndexOf(".");
|
| + if (index > 0) return filename.substring(index + 1);
|
| + }
|
| + return MimeTypeMap.getFileExtensionFromUrl(url);
|
| + }
|
| +
|
| + /**
|
| * Check whether a file is dangerous.
|
| *
|
| * @param filename Name of the file.
|
|
|