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

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

Issue 2496983003: Use native implementation of dangerous download infobar (Closed)
Patch Set: Created 4 years, 1 month 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/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java » ('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 ce46b4bf98d3a6353ebfcacba15978796240f246..e1854b61ca34699c7519b5cce3ce78a761d6c616 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
@@ -26,8 +26,6 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
-import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
-import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
@@ -49,43 +47,10 @@ import java.io.File;
public class ChromeDownloadDelegate {
private static final String TAG = "Download";
- private class DangerousDownloadListener implements SimpleConfirmInfoBarBuilder.Listener {
- @Override
- public boolean onInfoBarButtonClicked(boolean confirm) {
- assert mTab != null;
- if (mPendingRequest == null) return false;
- if (mPendingRequest.getDownloadGuid() != null) {
- nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadGuid(), confirm);
- if (confirm) {
- DownloadUtils.showDownloadStartToast(mContext);
- }
- }
- mPendingRequest = null;
- return closeBlankTab();
- }
-
- @Override
- public void onInfoBarDismissed() {
- if (mPendingRequest == null) return;
- if (mPendingRequest.getDownloadGuid() != null) {
- assert mTab != null;
- nativeDangerousDownloadValidated(
- mTab, mPendingRequest.getDownloadGuid(), false);
- }
- // Forget the pending request.
- mPendingRequest = null;
- }
- }
-
- private final DangerousDownloadListener mDangerousDownloadListener;
-
// The application context.
private final Context mContext;
private Tab mTab;
- // Pending download request for a dangerous file.
- private DownloadInfo mPendingRequest;
-
/**
* Creates ChromeDownloadDelegate.
* @param context The application context.
@@ -101,8 +66,6 @@ public class ChromeDownloadDelegate {
}
});
- mPendingRequest = null;
- mDangerousDownloadListener = new DangerousDownloadListener();
nativeInit(tab.getWebContents());
}
@@ -155,15 +118,11 @@ 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)) {
- confirmDangerousDownload(newInfo);
+ // Not a dangerous file, proceed.
+ if (fileExists) {
+ launchDownloadInfoBar(newInfo, dirName, fullDirPath);
} else {
- // Not a dangerous file, proceed.
- if (fileExists) {
- launchDownloadInfoBar(newInfo, dirName, fullDirPath);
- } else {
- enqueueDownloadManagerRequest(newInfo);
- }
+ enqueueDownloadManagerRequest(newInfo);
}
}
}.execute();
@@ -178,43 +137,6 @@ public class ChromeDownloadDelegate {
return downloadInfo.getUrl();
}
- /**
- * Request user confirmation on a dangerous download.
- *
- * @param downloadInfo Information about the download.
- */
- private void confirmDangerousDownload(DownloadInfo downloadInfo) {
- // A Dangerous file is already pending user confirmation, ignore the new download.
- if (mPendingRequest != null) return;
- // Tab is already destroyed, no need to add an infobar.
- if (mTab == null) return;
-
- mPendingRequest = downloadInfo;
-
- int drawableId = R.drawable.infobar_warning;
- final String titleText = nativeGetDownloadWarningText(mPendingRequest.getFileName());
- final String okButtonText = mContext.getResources().getString(R.string.ok);
- final String cancelButtonText = mContext.getResources().getString(R.string.cancel);
- SimpleConfirmInfoBarBuilder.create(mTab, mDangerousDownloadListener,
- InfoBarIdentifier.CONFIRM_DANGEROUS_DOWNLOAD, drawableId, titleText, okButtonText,
- cancelButtonText, true);
- }
-
- /**
- * Called when a danagerous download is about to start.
- *
- * @param filename File name of the download item.
- * @param downloadGuid GUID of the download.
- */
- @CalledByNative
- private void onDangerousDownload(String filename, String downloadGuid) {
- DownloadInfo downloadInfo = new DownloadInfo.Builder()
- .setFileName(filename)
- .setDescription(filename)
- .setDownloadGuid(downloadGuid).build();
- confirmDangerousDownload(downloadInfo);
- }
-
@CalledByNative
private void requestFileAccess(final long callbackId) {
if (mTab == null) {
@@ -562,8 +484,6 @@ public class ChromeDownloadDelegate {
private native void nativeInit(WebContents webContents);
private static native String nativeGetDownloadWarningText(String filename);
private static native boolean nativeIsDownloadDangerous(String filename);
- private static native void nativeDangerousDownloadValidated(
- Object tab, String downloadGuid, boolean accept);
private static native void nativeLaunchDownloadOverwriteInfoBar(ChromeDownloadDelegate delegate,
Tab tab, DownloadInfo downloadInfo, String fileName, String dirName,
String dirFullPath);
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698