diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-30 21:59:04 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-30 21:59:04 +0000 |
commit | 5c12f4a7d56afa3a3cd2d2a83dbfd65e321c71d8 (patch) | |
tree | 0a2de3573fca0d7617c5514773a87a63e404a5fc /content/shell/shell_download_manager_delegate.cc | |
parent | 83ca5d6f9b403134e1f7ebeb1253328e14cfc1db (diff) | |
download | chromium_src-5c12f4a7d56afa3a3cd2d2a83dbfd65e321c71d8.zip chromium_src-5c12f4a7d56afa3a3cd2d2a83dbfd65e321c71d8.tar.gz chromium_src-5c12f4a7d56afa3a3cd2d2a83dbfd65e321c71d8.tar.bz2 |
Always prompt the user for the download location in content_shell, as an indication that a download is happening since we don't have a downloads UI.
BUG=90445
Review URL: http://codereview.chromium.org/8081008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103554 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell/shell_download_manager_delegate.cc')
-rw-r--r-- | content/shell/shell_download_manager_delegate.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/content/shell/shell_download_manager_delegate.cc b/content/shell/shell_download_manager_delegate.cc index 47b3c80..a023d78 100644 --- a/content/shell/shell_download_manager_delegate.cc +++ b/content/shell/shell_download_manager_delegate.cc @@ -4,11 +4,19 @@ #include "content/shell/shell_download_manager_delegate.h" +#if defined(OS_WIN) +#include <windows.h> +#include <commdlg.h> +#endif + #include "base/bind.h" #include "base/file_util.h" +#include "base/logging.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "content/browser/browser_context.h" #include "content/browser/browser_thread.h" +#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/download/download_manager.h" #include "content/browser/download/download_state_info.h" #include "net/base/net_util.h" @@ -47,6 +55,9 @@ bool ShellDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { download->mime_type(), string16(UTF8ToUTF16("download"))); + // Since we have no download UI, show the user a dialog always. + state.prompt_user_for_save_location = true; + BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, @@ -92,6 +103,37 @@ void ShellDownloadManagerDelegate::ChooseDownloadPath( TabContents* tab_contents, const FilePath& suggested_path, void* data) { + FilePath result; +#if defined(OS_WIN) + std::wstring file_part = FilePath(suggested_path).BaseName().value(); + wchar_t file_name[MAX_PATH]; + base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); + OPENFILENAME save_as; + ZeroMemory(&save_as, sizeof(save_as)); + save_as.lStructSize = sizeof(OPENFILENAME); + save_as.hwndOwner = tab_contents->GetNativeView(); + save_as.lpstrFile = file_name; + save_as.nMaxFile = arraysize(file_name); + + std::wstring directory; + if (!suggested_path.empty()) + directory = suggested_path.DirName().value(); + + save_as.lpstrInitialDir = directory.c_str(); + save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | + OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; + + if (GetSaveFileName(&save_as)) + result = FilePath(std::wstring(save_as.lpstrFile)); +#else + NOTIMPLEMENTED(); +#endif + + if (result.empty()) { + download_manager_->FileSelectionCanceled(data); + } else { + download_manager_->FileSelected(result, data); + } } bool ShellDownloadManagerDelegate::OverrideIntermediatePath( |