Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: content/shell/shell_download_manager_delegate.cc

Issue 8081008: Always prompt the user for the download location in content_shell, as an indication that a downlo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/shell_download_manager_delegate.cc
===================================================================
--- content/shell/shell_download_manager_delegate.cc (revision 103331)
+++ content/shell/shell_download_manager_delegate.cc (working copy)
@@ -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 @@
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 @@
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 = FilePath(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(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698