| 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 ceeebd30fae4aaa8c9ad6a7cd2a49095f715df48..3718e7605768c13dfea749d8666fd3cacce5cee7 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
|
| @@ -27,9 +27,8 @@ 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.ConfirmInfoBar;
|
| -import org.chromium.chrome.browser.infobar.InfoBar;
|
| -import org.chromium.chrome.browser.infobar.InfoBarListeners;
|
| +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;
|
| @@ -52,83 +51,85 @@ import java.io.File;
|
| *
|
| * Prompts the user when a dangerous file is downloaded. Auto-opens PDFs after downloading.
|
| */
|
| -public class ChromeDownloadDelegate
|
| - implements ContentViewDownloadDelegate, InfoBarListeners.Confirm {
|
| +public class ChromeDownloadDelegate implements ContentViewDownloadDelegate {
|
| private static final String TAG = "Download";
|
|
|
| - // The application context.
|
| - private final Context mContext;
|
| - private Tab mTab;
|
| - private final TabModelSelector mTabModelSelector;
|
| -
|
| - // Pending download request for a dangerous file.
|
| - private DownloadInfo mPendingRequest;
|
| -
|
| - @Override
|
| - public void onConfirmInfoBarButtonClicked(ConfirmInfoBar infoBar, boolean confirm) {
|
| - assert mTab != null;
|
| - if (mPendingRequest.hasDownloadId()) {
|
| - nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadId(), confirm);
|
| - if (confirm) {
|
| - showDownloadStartNotification();
|
| - }
|
| - 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;
|
| + private class DangerousDownloadListener implements SimpleConfirmInfoBarBuilder.Listener {
|
| + @Override
|
| + public void onInfoBarButtonClicked(boolean confirm) {
|
| + assert mTab != null;
|
| + if (mPendingRequest.hasDownloadId()) {
|
| + nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadId(), confirm);
|
| + if (confirm) {
|
| + showDownloadStartNotification();
|
| + }
|
| + 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;
|
| - launchDownloadInfoBar(info, dirName, fullDirPath);
|
| - } else {
|
| - enqueueDownloadManagerRequest(info);
|
| + return doesFileAlreadyExists(fullDirPath, info.getFileName())
|
| + ? result : null;
|
| }
|
| - }
|
| - }.execute();
|
| +
|
| + @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).setIsSuccessful(true).build();
|
| + DownloadManagerService.getDownloadManagerService(mContext).onDownloadCompleted(
|
| + newDownloadInfo);
|
| + }
|
| } else {
|
| - DownloadInfo newDownloadInfo = DownloadInfo.Builder.fromDownloadInfo(
|
| - mPendingRequest).setIsSuccessful(true).build();
|
| - DownloadManagerService.getDownloadManagerService(mContext).onDownloadCompleted(
|
| - newDownloadInfo);
|
| - }
|
| - } else {
|
| - // User did not accept the download, discard the file if it is a POST download.
|
| - if (!mPendingRequest.isGETRequest()) {
|
| - discardFile(mPendingRequest.getFilePath());
|
| + // User did not accept the download, discard the file if it is a POST download.
|
| + if (!mPendingRequest.isGETRequest()) {
|
| + discardFile(mPendingRequest.getFilePath());
|
| + }
|
| }
|
| + mPendingRequest = null;
|
| }
|
| - mPendingRequest = null;
|
| - infoBar.dismissJavaOnlyInfoBar();
|
| - }
|
|
|
| - @Override
|
| - public void onInfoBarDismissed(InfoBar infoBar) {
|
| - if (mPendingRequest != null) {
|
| - if (mPendingRequest.hasDownloadId()) {
|
| - assert mTab != null;
|
| - nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadId(), false);
|
| - } else if (!mPendingRequest.isGETRequest()) {
|
| - // Infobar was dismissed, discard the file if a POST download is pending.
|
| - discardFile(mPendingRequest.getFilePath());
|
| + @Override
|
| + public void onInfoBarDismissed() {
|
| + if (mPendingRequest != null) {
|
| + if (mPendingRequest.hasDownloadId()) {
|
| + assert mTab != null;
|
| + nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadId(), false);
|
| + } else if (!mPendingRequest.isGETRequest()) {
|
| + // Infobar was dismissed, discard the file if a POST download is pending.
|
| + discardFile(mPendingRequest.getFilePath());
|
| + }
|
| }
|
| + // Forget the pending request.
|
| + mPendingRequest = null;
|
| }
|
| - // Forget the pending request.
|
| - mPendingRequest = null;
|
| }
|
|
|
| + private final DangerousDownloadListener mDangerousDownloadListener;
|
| +
|
| + // The application context.
|
| + private final Context mContext;
|
| + private Tab mTab;
|
| + private final TabModelSelector mTabModelSelector;
|
| +
|
| + // Pending download request for a dangerous file.
|
| + private DownloadInfo mPendingRequest;
|
| +
|
| /**
|
| * Creates ChromeDownloadDelegate.
|
| * @param context The application context.
|
| @@ -148,6 +149,7 @@ public class ChromeDownloadDelegate
|
|
|
| mTabModelSelector = tabModelSelector;
|
| mPendingRequest = null;
|
| + mDangerousDownloadListener = new DangerousDownloadListener();
|
| }
|
|
|
| /**
|
| @@ -306,17 +308,17 @@ public class ChromeDownloadDelegate
|
|
|
| mPendingRequest = downloadInfo;
|
|
|
| - // TODO(dfalcantara): Ask ainslie@ for an icon to use for this InfoBar.
|
| - int drawableId = 0;
|
| + 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);
|
| - mTab.getInfoBarContainer().addInfoBar(new ConfirmInfoBar(
|
| - this, drawableId, null, titleText, null, okButtonText, cancelButtonText));
|
| + SimpleConfirmInfoBarBuilder.create(mTab, mDangerousDownloadListener,
|
| + InfoBarIdentifier.CONFIRM_DANGEROUS_DOWNLOAD, drawableId, titleText, okButtonText,
|
| + cancelButtonText, true);
|
| }
|
|
|
| /**
|
| - * Called when a danagers download is about to start.
|
| + * Called when a danagerous download is about to start.
|
| *
|
| * @param filename File name of the download item.
|
| * @param downloadId ID of the download.
|
|
|