Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/win/open_file_name_win.h" | 5 #include "ui/base/win/open_file_name_win.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 131 |
| 132 void OpenFileName::MaybeInstallWindowPositionHookForSaveAsOnXP() { | 132 void OpenFileName::MaybeInstallWindowPositionHookForSaveAsOnXP() { |
| 133 if (base::win::GetVersion() >= base::win::VERSION_VISTA) | 133 if (base::win::GetVersion() >= base::win::VERSION_VISTA) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 openfilename_.Flags |= OFN_ENABLEHOOK; | 136 openfilename_.Flags |= OFN_ENABLEHOOK; |
| 137 DCHECK(!openfilename_.lpfnHook); | 137 DCHECK(!openfilename_.lpfnHook); |
| 138 openfilename_.lpfnHook = &SaveAsDialogHook; | 138 openfilename_.lpfnHook = &SaveAsDialogHook; |
| 139 } | 139 } |
| 140 | 140 |
| 141 base::FilePath OpenFileName::GetSingleResult() { | 141 base::FilePath OpenFileName::GetSingleResult() { |
|
sky
2014/09/29 23:53:03
I would rather we always do the right thing here,
luken
2014/09/30 17:25:07
Agreed, your idea is better. I've refactored to ju
| |
| 142 base::FilePath directory; | 142 // The return value of |openfilename_.lpstrFile| is dependent on the |
| 143 std::vector<base::FilePath> filenames; | 143 // value of the Multi-Select flag within |openfilename_|. If the flag is |
| 144 GetResult(&directory, &filenames); | 144 // not set the return value will be a single null-terminated wide string. |
| 145 if (filenames.size() != 1) | 145 // If it is set it will be more than one null-terminated wide string, itself |
| 146 return base::FilePath(); | 146 // terminated by an empty null-terminated wide string. We assert that |
| 147 return directory.Append(filenames[0]); | 147 // GetSingleResult() is assuming there is only a single result to return. |
| 148 DCHECK_EQ(0U, openfilename_.Flags & OFN_ALLOWMULTISELECT); | |
| 149 return base::FilePath(openfilename_.lpstrFile); | |
| 148 } | 150 } |
| 149 | 151 |
| 150 void OpenFileName::GetResult(base::FilePath* directory, | 152 void OpenFileName::GetResult(base::FilePath* directory, |
| 151 std::vector<base::FilePath>* filenames) { | 153 std::vector<base::FilePath>* filenames) { |
| 152 DCHECK(filenames->empty()); | 154 DCHECK(filenames->empty()); |
| 155 // The return value of |openfilename_.lpstrFile| is dependent on the | |
|
sky
2014/09/29 23:53:03
nit: don't duplicate almost the whole comment. Do
luken
2014/09/30 17:25:07
Done.
| |
| 156 // value of the Multi-Select flag within |openfilename_|. If the flag is | |
| 157 // not set the return value will be a single null-terminated wide string. | |
| 158 // If it is set it will be more than one null-terminated wide string, itself | |
| 159 // terminated by an empty null-terminated wide string. We assert that | |
| 160 // GetResult() is assuming there is more than one result to return. | |
| 161 DCHECK_NE(0U, openfilename_.Flags & OFN_ALLOWMULTISELECT); | |
| 153 const wchar_t* selection = openfilename_.lpstrFile; | 162 const wchar_t* selection = openfilename_.lpstrFile; |
| 154 while (*selection) { // Empty string indicates end of list. | 163 while (*selection) { // Empty string indicates end of list. |
| 155 filenames->push_back(base::FilePath(selection)); | 164 filenames->push_back(base::FilePath(selection)); |
| 156 // Skip over filename and null-terminator. | 165 // Skip over filename and null-terminator. |
| 157 selection += filenames->back().value().length() + 1; | 166 selection += filenames->back().value().length() + 1; |
| 158 } | 167 } |
| 159 if (filenames->size() == 1) { | 168 if (filenames->size() == 1) { |
| 160 // When there is one file, it contains the path and filename. | 169 // When there is one file, it contains the path and filename. |
| 161 *directory = (*filenames)[0].DirName(); | 170 *directory = (*filenames)[0].DirName(); |
| 162 (*filenames)[0] = (*filenames)[0].BaseName(); | 171 (*filenames)[0] = (*filenames)[0].BaseName(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 MakeTuple(base::string16(display_string, display_string_end), | 225 MakeTuple(base::string16(display_string, display_string_end), |
| 217 base::string16(pattern, pattern_end))); | 226 base::string16(pattern, pattern_end))); |
| 218 display_string = pattern_end + 1; | 227 display_string = pattern_end + 1; |
| 219 } | 228 } |
| 220 | 229 |
| 221 return filters; | 230 return filters; |
| 222 } | 231 } |
| 223 | 232 |
| 224 } // namespace win | 233 } // namespace win |
| 225 } // namespace ui | 234 } // namespace ui |
| OLD | NEW |