Commit a7fac6f2 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download location: Add the file size to location dialog title.

The file size is very useful for the user and it's in the UI design.

This CL adds the pipeline to show the file size in download location
dialog.

Bug: 846222
Change-Id: I972955571a6dd8b781c784167a4aee697b98d486
Reviewed-on: https://chromium-review.googlesource.com/1097713
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567102}
parent a4347263
...@@ -40,12 +40,13 @@ public class DownloadLocationDialog extends ModalDialogView implements OnChecked ...@@ -40,12 +40,13 @@ public class DownloadLocationDialog extends ModalDialogView implements OnChecked
* *
* @param controller Controller that listens to the events from the dialog. * @param controller Controller that listens to the events from the dialog.
* @param context Context from which the dialog emerged. * @param context Context from which the dialog emerged.
* @param totalBytes The total bytes of the file. Can be 0 if size is unknown.
* @param dialogType Type of dialog that should be displayed, dictates title/subtitle. * @param dialogType Type of dialog that should be displayed, dictates title/subtitle.
* @param suggestedPath The path that was automatically generated, used as a starting point. * @param suggestedPath The path that was automatically generated, used as a starting point.
* @return A {@link DownloadLocationDialog} with the given properties. * @return A {@link DownloadLocationDialog} with the given properties.
*/ */
public static DownloadLocationDialog create(Controller controller, Context context, public static DownloadLocationDialog create(Controller controller, Context context,
@DownloadLocationDialogType int dialogType, File suggestedPath) { long totalBytes, @DownloadLocationDialogType int dialogType, File suggestedPath) {
Params params = new Params(); Params params = new Params();
params.positiveButtonTextId = R.string.duplicate_download_infobar_download_button; params.positiveButtonTextId = R.string.duplicate_download_infobar_download_button;
params.negativeButtonTextId = R.string.cancel; params.negativeButtonTextId = R.string.cancel;
...@@ -79,7 +80,12 @@ public class DownloadLocationDialog extends ModalDialogView implements OnChecked ...@@ -79,7 +80,12 @@ public class DownloadLocationDialog extends ModalDialogView implements OnChecked
break; break;
case DownloadLocationDialogType.DEFAULT: case DownloadLocationDialogType.DEFAULT:
default: if (totalBytes > 0) {
StringBuilder title = new StringBuilder(params.title);
title.append(" ");
title.append(DownloadUtils.getStringForBytes(context, totalBytes));
params.title = title.toString();
}
break; break;
} }
......
...@@ -37,8 +37,8 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller ...@@ -37,8 +37,8 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller
} }
@CalledByNative @CalledByNative
public void showDialog(WindowAndroid windowAndroid, @DownloadLocationDialogType int dialogType, public void showDialog(WindowAndroid windowAndroid, long totalBytes,
String suggestedPath) { @DownloadLocationDialogType int dialogType, String suggestedPath) {
ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get(); ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get();
// If the activity has gone away, just clean up the native pointer. // If the activity has gone away, just clean up the native pointer.
if (activity == null) { if (activity == null) {
...@@ -49,8 +49,8 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller ...@@ -49,8 +49,8 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller
mModalDialogManager = activity.getModalDialogManager(); mModalDialogManager = activity.getModalDialogManager();
if (mLocationDialog != null) return; if (mLocationDialog != null) return;
mLocationDialog = mLocationDialog = DownloadLocationDialog.create(
DownloadLocationDialog.create(this, activity, dialogType, new File(suggestedPath)); this, activity, totalBytes, dialogType, new File(suggestedPath));
mModalDialogManager.showDialog(mLocationDialog, ModalDialogManager.APP_MODAL); mModalDialogManager.showDialog(mLocationDialog, ModalDialogManager.APP_MODAL);
} }
......
...@@ -25,6 +25,7 @@ class DownloadLocationDialogBridge { ...@@ -25,6 +25,7 @@ class DownloadLocationDialogBridge {
// Show a download location picker dialog to determine the download path. // Show a download location picker dialog to determine the download path.
// The path selected by the user will be returned in |location_callback|. // The path selected by the user will be returned in |location_callback|.
virtual void ShowDialog(gfx::NativeWindow native_window, virtual void ShowDialog(gfx::NativeWindow native_window,
int64_t total_bytes,
DownloadLocationDialogType dialog_type, DownloadLocationDialogType dialog_type,
const base::FilePath& suggested_path, const base::FilePath& suggested_path,
LocationCallback location_callback) = 0; LocationCallback location_callback) = 0;
......
...@@ -27,6 +27,7 @@ DownloadLocationDialogBridgeImpl::~DownloadLocationDialogBridgeImpl() { ...@@ -27,6 +27,7 @@ DownloadLocationDialogBridgeImpl::~DownloadLocationDialogBridgeImpl() {
void DownloadLocationDialogBridgeImpl::ShowDialog( void DownloadLocationDialogBridgeImpl::ShowDialog(
gfx::NativeWindow native_window, gfx::NativeWindow native_window,
int64_t total_bytes,
DownloadLocationDialogType dialog_type, DownloadLocationDialogType dialog_type,
const base::FilePath& suggested_path, const base::FilePath& suggested_path,
LocationCallback location_callback) { LocationCallback location_callback) {
...@@ -57,7 +58,7 @@ void DownloadLocationDialogBridgeImpl::ShowDialog( ...@@ -57,7 +58,7 @@ void DownloadLocationDialogBridgeImpl::ShowDialog(
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
Java_DownloadLocationDialogBridge_showDialog( Java_DownloadLocationDialogBridge_showDialog(
env, java_obj_, native_window->GetJavaObject(), env, java_obj_, native_window->GetJavaObject(),
static_cast<int>(dialog_type), static_cast<long>(total_bytes), static_cast<int>(dialog_type),
base::android::ConvertUTF8ToJavaString(env, base::android::ConvertUTF8ToJavaString(env,
suggested_path.AsUTF8Unsafe())); suggested_path.AsUTF8Unsafe()));
} }
......
...@@ -19,6 +19,7 @@ class DownloadLocationDialogBridgeImpl : public DownloadLocationDialogBridge { ...@@ -19,6 +19,7 @@ class DownloadLocationDialogBridgeImpl : public DownloadLocationDialogBridge {
// DownloadLocationDialogBridge implementation. // DownloadLocationDialogBridge implementation.
void ShowDialog(gfx::NativeWindow native_window, void ShowDialog(gfx::NativeWindow native_window,
int64_t total_bytes,
DownloadLocationDialogType dialog_type, DownloadLocationDialogType dialog_type,
const base::FilePath& suggested_path, const base::FilePath& suggested_path,
LocationCallback location_callback) override; LocationCallback location_callback) override;
......
...@@ -325,11 +325,12 @@ void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { ...@@ -325,11 +325,12 @@ void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void ChromeDownloadManagerDelegate::ChooseDownloadLocation( void ChromeDownloadManagerDelegate::ChooseDownloadLocation(
gfx::NativeWindow native_window, gfx::NativeWindow native_window,
int64_t total_bytes,
DownloadLocationDialogType dialog_type, DownloadLocationDialogType dialog_type,
const base::FilePath& suggested_path, const base::FilePath& suggested_path,
DownloadLocationDialogBridge::LocationCallback callback) { DownloadLocationDialogBridge::LocationCallback callback) {
DCHECK(location_dialog_bridge_); DCHECK(location_dialog_bridge_);
location_dialog_bridge_->ShowDialog(native_window, dialog_type, location_dialog_bridge_->ShowDialog(native_window, total_bytes, dialog_type,
suggested_path, std::move(callback)); suggested_path, std::move(callback));
} }
...@@ -895,7 +896,7 @@ void ChromeDownloadManagerDelegate::RequestConfirmation( ...@@ -895,7 +896,7 @@ void ChromeDownloadManagerDelegate::RequestConfirmation(
gfx::NativeWindow native_window = web_contents->GetTopLevelNativeWindow(); gfx::NativeWindow native_window = web_contents->GetTopLevelNativeWindow();
ChooseDownloadLocation( ChooseDownloadLocation(
native_window, dialog_type, suggested_path, native_window, download->GetTotalBytes(), dialog_type, suggested_path,
base::BindOnce(&OnDownloadLocationDetermined, callback)); base::BindOnce(&OnDownloadLocationDetermined, callback));
} }
} else { } else {
...@@ -967,7 +968,8 @@ void ChromeDownloadManagerDelegate::GenerateUniqueFileNameDone( ...@@ -967,7 +968,8 @@ void ChromeDownloadManagerDelegate::GenerateUniqueFileNameDone(
if (result == PathValidationResult::SUCCESS) { if (result == PathValidationResult::SUCCESS) {
if (download_prefs_->PromptForDownload()) { if (download_prefs_->PromptForDownload()) {
ChooseDownloadLocation( ChooseDownloadLocation(
native_window, DownloadLocationDialogType::NAME_CONFLICT, target_path, native_window, 0 /* total_bytes */,
DownloadLocationDialogType::NAME_CONFLICT, target_path,
base::BindOnce(&OnDownloadLocationDetermined, callback)); base::BindOnce(&OnDownloadLocationDetermined, callback));
return; return;
} }
......
...@@ -65,6 +65,7 @@ class ChromeDownloadManagerDelegate ...@@ -65,6 +65,7 @@ class ChromeDownloadManagerDelegate
void ChooseDownloadLocation( void ChooseDownloadLocation(
gfx::NativeWindow native_window, gfx::NativeWindow native_window,
int64_t total_bytes,
DownloadLocationDialogType dialog_type, DownloadLocationDialogType dialog_type,
const base::FilePath& suggested_path, const base::FilePath& suggested_path,
DownloadLocationDialogBridge::LocationCallback callback); DownloadLocationDialogBridge::LocationCallback callback);
......
...@@ -1057,6 +1057,7 @@ class TestDownloadLocationDialogBridge : public DownloadLocationDialogBridge { ...@@ -1057,6 +1057,7 @@ class TestDownloadLocationDialogBridge : public DownloadLocationDialogBridge {
// DownloadLocationDialogBridge implementation. // DownloadLocationDialogBridge implementation.
void ShowDialog( void ShowDialog(
gfx::NativeWindow native_window, gfx::NativeWindow native_window,
int64_t total_bytes,
DownloadLocationDialogType dialog_type, DownloadLocationDialogType dialog_type,
const base::FilePath& suggested_path, const base::FilePath& suggested_path,
DownloadLocationDialogBridge::LocationCallback callback) override { DownloadLocationDialogBridge::LocationCallback callback) override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment