diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-18 10:45:28 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-18 10:45:28 +0000 |
commit | e6be47fb2071a5b0e1859eb014cde64f6c78eb5a (patch) | |
tree | 7503e464d6f75f56bbc2b8603bdb4498fd5459c0 /chrome/browser/download | |
parent | 42a8da22b56bb8d365e605fae75b93bd80965c77 (diff) | |
download | chromium_src-e6be47fb2071a5b0e1859eb014cde64f6c78eb5a.zip chromium_src-e6be47fb2071a5b0e1859eb014cde64f6c78eb5a.tar.gz chromium_src-e6be47fb2071a5b0e1859eb014cde64f6c78eb5a.tar.bz2 |
Option-click to download should not display "Save As" UI.
The download manager has a concept of a request originating from the "Save As..." contextual menu v.s. a direct download request from the renderer, however this was't hooked up.
The Download Manager uses boolean variables named "save_as" in various locations to track whether a download originated via a contextual menu selection (in which case the save panel should be displayed) or via a renderer request (in which case no UI should be displayed).
This CL contains 3 distinct changes:
1. DownloadFileManager::OnDownloadURL() is where downloads originating from the contextual menu are dispatched, set save_as to true if the download starts here.
2. ResourceMessageFilter::OnDownloadURL() is where downloads originating from the renderer are dispatched (e.g. option-click), don't display UI for these.
3. The "save_as" variable in the DownloadCreateInfo structure doesn't really reflect the origin of the request but whether the Save panel should be displayed. This can happen for example on a name collision or if the default download location isn't writeable regardless of the action that initiated the download. Renamed the variable and added documentation to this effect.
BUG=36775
TEST=Option-click an image, the image should be saved without prompting the user for a download locate. Save an image via the "Save As..." context menu, you should be prompted for the save location.
Review URL: http://codereview.chromium.org/2927006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52848 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_file_manager.cc | 3 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 23 |
2 files changed, 16 insertions, 10 deletions
diff --git a/chrome/browser/download/download_file_manager.cc b/chrome/browser/download/download_file_manager.cc index 90a95f4..04336cf 100644 --- a/chrome/browser/download/download_file_manager.cc +++ b/chrome/browser/download/download_file_manager.cc @@ -84,9 +84,12 @@ void DownloadFileManager::OnDownloadUrl( 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 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { 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 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { // 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 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { 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 @@ void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { 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 @@ void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { 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 @@ void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { 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 @@ void DownloadManager::ContinueStartDownload(DownloadCreateInfo* info, 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::SaveAutoOpens() { 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); } |