Recommit r52848 - Option-click to download should not display "Save As" UI.
Review URL: http://codereview.chromium.org/2825056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52850 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/download/download_file_manager.cc b/chrome/browser/download/download_file_manager.cc
index 90a95f45..04336cf 100644
--- a/chrome/browser/download/download_file_manager.cc
+++ b/chrome/browser/download/download_file_manager.cc
@@ -84,9 +84,12 @@
URLRequestContext* context = request_context_getter->GetURLRequestContext();
context->set_referrer_charset(referrer_charset);
+ // Show "Save As" UI.
+ bool prompt_for_save_location = true;
resource_dispatcher_host_->BeginDownload(url,
referrer,
save_info,
+ prompt_for_save_location,
render_process_host_id,
render_view_id,
context);
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 26d1d54..622d108 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -404,7 +404,8 @@
DCHECK(info);
// Check whether this download is for an extension install or not.
- if (!info->save_as) { // Allow extensions to be explicitly saved.
+ // Allow extensions to be explicitly saved.
+ if (!info->prompt_user_for_save_location) {
if (UserScript::HasUserScriptFileExtension(info->url) ||
info->mime_type == Extension::kMimeType)
info->is_extension_install = true;
@@ -426,13 +427,13 @@
// opened, don't bother asking where to keep it.
if (!info->is_extension_install &&
!ShouldOpenFileBasedOnExtension(generated_name))
- info->save_as = true;
+ info->prompt_user_for_save_location = true;
}
// Determine the proper path for a download, by either one of the following:
// 1) using the default download directory.
// 2) prompting the user.
- if (info->save_as && !last_download_path_.empty())
+ if (info->prompt_user_for_save_location && !last_download_path_.empty())
info->suggested_path = last_download_path_;
else
info->suggested_path = download_path();
@@ -441,7 +442,8 @@
info->suggested_path = info->save_info.file_path;
}
- if (!info->save_as && info->save_info.file_path.empty()) {
+ if (!info->prompt_user_for_save_location &&
+ info->save_info.file_path.empty()) {
// Downloads can be marked as dangerous for two reasons:
// a) They have a dangerous-looking filename
// b) They are an extension that is not from the gallery
@@ -470,7 +472,7 @@
FilePath dir = info->suggested_path.DirName();
FilePath filename = info->suggested_path.BaseName();
if (!file_util::PathIsWritable(dir)) {
- info->save_as = true;
+ info->prompt_user_for_save_location = true;
PathService::Get(chrome::DIR_USER_DOCUMENTS, &info->suggested_path);
info->suggested_path = info->suggested_path.Append(filename);
}
@@ -507,11 +509,12 @@
info->path_uniquifier = 0;
} else if (info->path_uniquifier == -1) {
// We failed to find a unique path. We have to prompt the user.
- info->save_as = true;
+ info->prompt_user_for_save_location = true;
}
}
- if (!info->save_as && info->save_info.file_path.empty()) {
+ if (!info->prompt_user_for_save_location &&
+ info->save_info.file_path.empty()) {
// Create an empty file at the suggested path so that we don't allocate the
// same "non-existant" path to multiple downloads.
// See: http://code.google.com/p/chromium/issues/detail?id=3662
@@ -530,7 +533,7 @@
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
DCHECK(info);
- if (info->save_as) {
+ if (info->prompt_user_for_save_location) {
// We must ask the user for the place to put the download.
if (!select_file_dialog_.get())
select_file_dialog_ = SelectFileDialog::Create(this);
@@ -577,7 +580,7 @@
info->child_id,
info->request_id,
info->is_dangerous,
- info->save_as,
+ info->prompt_user_for_save_location,
profile_->IsOffTheRecord(),
info->is_extension_install,
!info->save_info.file_path.empty());
@@ -1410,7 +1413,7 @@
void DownloadManager::FileSelected(const FilePath& path,
int index, void* params) {
DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params);
- if (info->save_as)
+ if (info->prompt_user_for_save_location)
last_download_path_ = path.DirName();
ContinueStartDownload(info, path);
}
diff --git a/chrome/browser/download/download_manager_unittest.cc b/chrome/browser/download/download_manager_unittest.cc
index c971115..70878632 100644
--- a/chrome/browser/download/download_manager_unittest.cc
+++ b/chrome/browser/download/download_manager_unittest.cc
@@ -685,12 +685,13 @@
kStartDownloadCases[i].prompt_for_download);
DownloadCreateInfo info;
- info.save_as = kStartDownloadCases[i].save_as;
+ info.prompt_user_for_save_location = kStartDownloadCases[i].save_as;
info.url = GURL(kStartDownloadCases[i].url);
info.mime_type = kStartDownloadCases[i].mime_type;
download_manager_->StartDownload(&info);
- EXPECT_EQ(kStartDownloadCases[i].expected_save_as, info.save_as);
+ EXPECT_EQ(kStartDownloadCases[i].expected_save_as,
+ info.prompt_user_for_save_location);
}
}
diff --git a/chrome/browser/history/download_types.h b/chrome/browser/history/download_types.h
index 4db21e41..642ac5b 100644
--- a/chrome/browser/history/download_types.h
+++ b/chrome/browser/history/download_types.h
@@ -39,7 +39,7 @@
render_view_id(-1),
request_id(-1),
db_handle(0),
- save_as(false),
+ prompt_user_for_save_location(false),
is_dangerous(false),
is_extension_install(false) {
}
@@ -54,7 +54,7 @@
render_view_id(-1),
request_id(-1),
db_handle(0),
- save_as(false),
+ prompt_user_for_save_location(false),
is_dangerous(false),
is_extension_install(false) {
}
@@ -82,7 +82,12 @@
// may be different from |mime_type|, which may be set based on heuristics
// which may look at the file extension and first few bytes of the file.
std::string original_mime_type;
- bool save_as;
+
+ // True if we should display the 'save as...' UI and prompt the user
+ // for the download location.
+ // False if the UI should be supressed and the download performed to the
+ // default location.
+ bool prompt_user_for_save_location;
// Whether this download is potentially dangerous (ex: exe, dll, ...).
bool is_dangerous;
// The original name for a dangerous download.
diff --git a/chrome/browser/renderer_host/download_resource_handler.cc b/chrome/browser/renderer_host/download_resource_handler.cc
index 0b45695ac..735a1689 100644
--- a/chrome/browser/renderer_host/download_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_resource_handler.cc
@@ -85,7 +85,8 @@
content_type_header = "";
info->original_mime_type = content_type_header;
- info->save_as = save_as_ && save_info_.file_path.empty();
+ info->prompt_user_for_save_location =
+ save_as_ && save_info_.file_path.empty();
info->is_dangerous = false;
info->referrer_charset = request_->context()->referrer_charset();
info->save_info = save_info_;
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index cca59a1..d3e80c8 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -599,6 +599,7 @@
const GURL& url,
const GURL& referrer,
const DownloadSaveInfo& save_info,
+ bool prompt_for_save_location,
int child_id,
int route_id,
URLRequestContext* request_context) {
@@ -628,7 +629,7 @@
url,
download_file_manager_.get(),
request,
- true,
+ prompt_for_save_location,
save_info);
if (safe_browsing_->enabled()) {
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h
index 00d19e0..46dd9c4 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.h
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.h
@@ -109,6 +109,7 @@
void BeginDownload(const GURL& url,
const GURL& referrer,
const DownloadSaveInfo& save_info,
+ bool prompt_for_save_location,
int process_unique_id,
int route_id,
URLRequestContext* request_context);
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 0418487..698e385f 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -871,9 +871,13 @@
const GURL& url,
const GURL& referrer) {
URLRequestContext* context = request_context_->GetURLRequestContext();
+
+ // Don't show "Save As" UI.
+ bool prompt_for_save_location = false;
resource_dispatcher_host_->BeginDownload(url,
referrer,
DownloadSaveInfo(),
+ prompt_for_save_location,
id(),
message.routing_id(),
context);