summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjnd@chromium.org <jnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-25 05:58:40 +0000
committerjnd@chromium.org <jnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-25 05:58:40 +0000
commitd3a2f242e60f5102c5ca3022152108941c7f63f8 (patch)
tree2a472983ab27602840af029ca42bf2f1b1cb6b71 /chrome/browser
parent87690d99c17ae5b7dd1c1bd465d661d24aec72d3 (diff)
downloadchromium_src-d3a2f242e60f5102c5ca3022152108941c7f63f8.zip
chromium_src-d3a2f242e60f5102c5ca3022152108941c7f63f8.tar.gz
chromium_src-d3a2f242e60f5102c5ca3022152108941c7f63f8.tar.bz2
Only save pure filename in lpstrFile.
BUG=47213 TEST=manual test? Review URL: http://codereview.chromium.org/2868031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/views/shell_dialogs_win.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/chrome/browser/views/shell_dialogs_win.cc b/chrome/browser/views/shell_dialogs_win.cc
index 199b384..0deab08 100644
--- a/chrome/browser/views/shell_dialogs_win.cc
+++ b/chrome/browser/views/shell_dialogs_win.cc
@@ -843,17 +843,41 @@ bool SelectFileDialogImpl::RunOpenFileDialog(
ofn.hwndOwner = owner;
wchar_t filename[MAX_PATH];
- base::wcslcpy(filename, path->value().c_str(), arraysize(filename));
+ // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12,
+ // The lpstrFile Buffer MUST be NULL Terminated.
+ filename[0] = 0;
+ // Define the dir in here to keep the string buffer pointer pointed to
+ // ofn.lpstrInitialDir available during the period of running the
+ // GetOpenFileName.
+ FilePath dir;
+ // Use lpstrInitialDir to specify the initial directory
+ if (!path->empty()) {
+ bool is_dir;
+ file_util::FileInfo file_info;
+ if (file_util::GetFileInfo(*path, &file_info))
+ is_dir = file_info.is_directory;
+ else
+ is_dir = file_util::EndsWithSeparator(*path);
+ if (is_dir) {
+ ofn.lpstrInitialDir = path->value().c_str();
+ } else {
+ dir = path->DirName();
+ ofn.lpstrInitialDir = dir.value().c_str();
+ // Only pure filename can be put in lpstrFile field.
+ base::wcslcpy(filename, path->BaseName().value().c_str(),
+ arraysize(filename));
+ }
+ }
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
+
// We use OFN_NOCHANGEDIR so that the user can rename or delete the directory
// without having to close Chrome first.
ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
- if (!filter.empty()) {
+ if (!filter.empty())
ofn.lpstrFilter = filter.c_str();
- }
bool success = !!GetOpenFileName(&ofn);
DisableOwner(owner);
if (success)