| 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 4d0b01787575a9c56665b44ea6d5b33c091593c9..f260c148eb305b3b4f2ed7cf0c0fe557b82d71f4 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
|
| @@ -19,12 +19,10 @@ import android.text.TextUtils;
|
| import android.util.Pair;
|
| import android.view.View;
|
| import android.webkit.MimeTypeMap;
|
| -import android.webkit.URLUtil;
|
| import android.widget.TextView;
|
|
|
| import org.chromium.base.Log;
|
| import org.chromium.base.ThreadUtils;
|
| -import org.chromium.base.VisibleForTesting;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
|
| @@ -177,64 +175,18 @@ public class ChromeDownloadDelegate implements ContentViewDownloadDelegate {
|
| }
|
|
|
| /**
|
| - * Decide the file name of the final download. The file extension is derived
|
| - * from the MIME type.
|
| - * @param url The full URL to the content that should be downloaded.
|
| - * @param mimeType The MIME type of the content reported by the server.
|
| - * @param contentDisposition Content-Disposition HTTP header, if present.
|
| - * @return The best guess of the file name for the downloaded object.
|
| - */
|
| - @VisibleForTesting
|
| - public static String fileName(String url, String mimeType, String contentDisposition) {
|
| - // URLUtil#guessFileName will prefer the MIME type extension over
|
| - // the file extension only if the latter is of a known MIME type.
|
| - // Therefore for things like "file.php" with Content-Type PDF, it will
|
| - // still generate file names like "file.php" instead of "file.pdf".
|
| - // If that's the case, rebuild the file extension from the MIME type.
|
| - String fileName = URLUtil.guessFileName(url, contentDisposition, mimeType);
|
| - int dotIndex = fileName.lastIndexOf('.');
|
| - if (mimeType != null
|
| - && !mimeType.isEmpty()
|
| - && dotIndex > 1 // at least one char before the '.'
|
| - && dotIndex < fileName.length()) { // '.' should not be the last char
|
| - MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
| -
|
| - String fileRoot = fileName.substring(0, dotIndex);
|
| - String fileExtension = fileName.substring(dotIndex + 1);
|
| - String fileExtensionMimeType =
|
| - mimeTypeMap.getMimeTypeFromExtension(fileExtension);
|
| -
|
| - // If the file extension's official MIME type and {@code mimeType}
|
| - // are the same, simply use the file extension.
|
| - // If not, extension derived from {@code mimeType} is preferred.
|
| - if (mimeType.equals(fileExtensionMimeType)) {
|
| - fileName = fileRoot + "." + fileExtension;
|
| - } else {
|
| - String mimeExtension =
|
| - mimeTypeMap.getExtensionFromMimeType(mimeType);
|
| -
|
| - if (mimeExtension != null && !mimeExtension.equals(fileExtension)) {
|
| - fileName = fileRoot + "." + mimeExtension;
|
| - }
|
| - }
|
| - }
|
| - return fileName;
|
| - }
|
| -
|
| - /**
|
| * Notify the host application a download should be done, even if there is a
|
| * streaming viewer available for this type.
|
| *
|
| * @param downloadInfo Information about the download.
|
| */
|
| protected void onDownloadStartNoStream(final DownloadInfo downloadInfo) {
|
| + final String fileName = downloadInfo.getFileName();
|
| + assert !TextUtils.isEmpty(fileName);
|
| final String newMimeType = remapGenericMimeType(
|
| downloadInfo.getMimeType(),
|
| downloadInfo.getUrl(),
|
| - downloadInfo.getFileName());
|
| - final String fileName = TextUtils.isEmpty(downloadInfo.getFileName())
|
| - ? fileName(downloadInfo.getUrl(), newMimeType, downloadInfo.getContentDisposition())
|
| - : downloadInfo.getFileName();
|
| + fileName);
|
| new AsyncTask<Void, Void, Object[]>() {
|
| @Override
|
| protected Object[] doInBackground(Void... params) {
|
|
|