Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3303)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java

Issue 2371773003: Clean up Android DownloadManager code as most download now go through Chrome Network stack (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/android/download/chrome_download_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5a786ace914a3d7d623a1a2805d4f2e4a561963f..0ef10538498fe7fb6a1a58f56601e42b101111a6 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
@@ -9,7 +9,6 @@ import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
@@ -60,62 +59,18 @@ public class ChromeDownloadDelegate {
if (confirm) {
DownloadUtils.showDownloadStartToast(mContext);
}
- mPendingRequest = null;
- return closeBlankTab();
- } else if (confirm) {
- // User confirmed the download.
- if (mPendingRequest.isGETRequest()) {
- final DownloadInfo info = mPendingRequest;
- new AsyncTask<Void, Void, Pair<String, String>>() {
- @Override
- protected Pair<String, String> doInBackground(Void... params) {
- Pair<String, String> result = getDownloadDirectoryNameAndFullPath();
- String fullDirPath = result.second;
- return doesFileAlreadyExists(fullDirPath, info.getFileName())
- ? result : null;
- }
-
- @Override
- protected void onPostExecute(Pair<String, String> result) {
- if (result != null) {
- // File already exists.
- String dirName = result.first;
- String fullDirPath = result.second;
- launchDownloadInfoBar(info, dirName, fullDirPath);
- } else {
- enqueueDownloadManagerRequest(info);
- }
- }
- }.execute();
- } else {
- DownloadInfo newDownloadInfo =
- DownloadInfo.Builder.fromDownloadInfo(mPendingRequest).build();
- DownloadManagerService.getDownloadManagerService(mContext).onDownloadCompleted(
- newDownloadInfo);
- }
- mPendingRequest = null;
- return false;
- } else {
- // User did not accept the download, discard the file if it is a POST download.
- if (!mPendingRequest.isGETRequest()) {
- discardFile(mPendingRequest.getFilePath());
- }
- mPendingRequest = null;
- return closeBlankTab();
}
+ mPendingRequest = null;
+ return closeBlankTab();
}
@Override
public void onInfoBarDismissed() {
- if (mPendingRequest != null) {
- if (mPendingRequest.getDownloadGuid() != null) {
- assert mTab != null;
- nativeDangerousDownloadValidated(
- mTab, mPendingRequest.getDownloadGuid(), false);
- } else if (!mPendingRequest.isGETRequest()) {
- // Infobar was dismissed, discard the file if a POST download is pending.
- discardFile(mPendingRequest.getFilePath());
- }
+ if (mPendingRequest == null) return;
+ if (mPendingRequest.getDownloadGuid() != null) {
+ assert mTab != null;
+ nativeDangerousDownloadValidated(
+ mTab, mPendingRequest.getDownloadGuid(), false);
}
// Forget the pending request.
mPendingRequest = null;
@@ -151,38 +106,6 @@ public class ChromeDownloadDelegate {
nativeInit(tab.getWebContents());
}
- @CalledByNative
- private void requestHttpGetDownload(String url, String userAgent, String contentDisposition,
- String mimeType, String cookie, String referer, boolean hasUserGesture,
- String filename, long contentLength, boolean mustDownload) {
- // If we're dealing with A/V content that's not explicitly marked for download, check if it
- // is streamable.
- if (!mustDownload) {
- // Query the package manager to see if there's a registered handler that matches.
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(url), mimeType);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- // If the intent is resolved to ourselves, we don't want to attempt to load the url
- // only to try and download it again.
- if (DownloadManagerService.openIntent(mContext, intent, false)) {
- return;
- }
- }
- DownloadInfo downloadInfo = new DownloadInfo.Builder()
- .setUrl(url)
- .setUserAgent(userAgent)
- .setContentDisposition(contentDisposition)
- .setMimeType(mimeType)
- .setCookie(cookie)
- .setReferer(referer)
- .setHasUserGesture(hasUserGesture)
- .setFileName(filename)
- .setContentLength(contentLength)
- .setIsGETRequest(true)
- .build();
- onDownloadStartNoStream(downloadInfo);
- }
-
/**
* Notify the host application a download should be done, even if there is a
* streaming viewer available for this type.
@@ -232,7 +155,7 @@ public class ChromeDownloadDelegate {
// The proper fix would be to let chrome knows which frame originated the request.
if ("application/x-shockwave-flash".equals(newInfo.getMimeType())) return;
- if (isDangerousFile(fileName, newMimeType)) {
+ if (isDangerousFile(fileName)) {
confirmDangerousDownload(newInfo);
} else {
// Not a dangerous file, proceed.
@@ -480,8 +403,8 @@ public class ChromeDownloadDelegate {
* @param mimeType MIME type of the content.
*/
@CalledByNative
- private void onDownloadStarted(String filename, String mimeType) {
- if (!isDangerousFile(filename, mimeType)) {
+ private void onDownloadStarted(String filename) {
+ if (!isDangerousFile(filename)) {
DownloadUtils.showDownloadStartToast(mContext);
closeBlankTab();
}
@@ -543,22 +466,10 @@ public class ChromeDownloadDelegate {
* Check whether a file is dangerous.
*
* @param filename Name of the file.
- * @param mimeType MIME type of the content.
- * @return true if the file is dangerous, or false otherwise.
- */
- protected boolean isDangerousFile(String filename, String mimeType) {
- return nativeIsDownloadDangerous(filename) || isDangerousExtension(
- MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType));
- }
-
- /**
- * Check whether a file extension is dangerous.
- *
- * @param ext Extension of the file.
* @return true if the file is dangerous, or false otherwise.
*/
- private static boolean isDangerousExtension(String ext) {
Ted C 2016/09/27 17:45:22 do we need to add this logic to native now?
qinmin 2016/09/27 19:26:50 There is a warning when openning an apk file on an
- return "apk".equals(ext);
+ protected boolean isDangerousFile(String filename) {
+ return nativeIsDownloadDangerous(filename);
}
/**
@@ -617,32 +528,30 @@ public class ChromeDownloadDelegate {
String path = uri.getPath();
// OMA downloads have extension "dm" or "dd". For the latter, it
// can be handled when native download completes.
- if (path != null && (path.endsWith(".dm"))) {
- if (mTab == null) return true;
- String fileName = URLUtil.guessFileName(
- url, null, OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
- final DownloadInfo downloadInfo =
- new DownloadInfo.Builder().setUrl(url).setFileName(fileName).build();
- WindowAndroid window = mTab.getWindowAndroid();
- if (window.hasPermission(permission.WRITE_EXTERNAL_STORAGE)) {
- onDownloadStartNoStream(downloadInfo);
- } else if (window.canRequestPermission(permission.WRITE_EXTERNAL_STORAGE)) {
- PermissionCallback permissionCallback = new PermissionCallback() {
- @Override
- public void onRequestPermissionsResult(
- String[] permissions, int[] grantResults) {
- if (grantResults.length > 0
- && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- onDownloadStartNoStream(downloadInfo);
- }
+ if (path == null || !path.endsWith(".dm")) return false;
+ if (mTab == null) return true;
+ String fileName = URLUtil.guessFileName(
+ url, null, OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
+ final DownloadInfo downloadInfo =
+ new DownloadInfo.Builder().setUrl(url).setFileName(fileName).build();
+ WindowAndroid window = mTab.getWindowAndroid();
+ if (window.hasPermission(permission.WRITE_EXTERNAL_STORAGE)) {
+ onDownloadStartNoStream(downloadInfo);
+ } else if (window.canRequestPermission(permission.WRITE_EXTERNAL_STORAGE)) {
+ PermissionCallback permissionCallback = new PermissionCallback() {
+ @Override
+ public void onRequestPermissionsResult(
+ String[] permissions, int[] grantResults) {
+ if (grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ onDownloadStartNoStream(downloadInfo);
}
- };
- window.requestPermissions(
- new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
- }
- return true;
+ }
+ };
+ window.requestPermissions(
+ new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
}
- return false;
+ return true;
}
protected Context getContext() {
« no previous file with comments | « no previous file | chrome/browser/android/download/chrome_download_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698