Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell_dialogs/select_file_dialog.h" | 5 #include "ui/shell_dialogs/select_file_dialog.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "ui/shell_dialogs/select_file_dialog_factory.h" | 16 #include "ui/shell_dialogs/select_file_dialog_factory.h" |
| 16 #include "ui/shell_dialogs/select_file_policy.h" | 17 #include "ui/shell_dialogs/select_file_policy.h" |
| 17 #include "ui/shell_dialogs/selected_file_info.h" | 18 #include "ui/shell_dialogs/selected_file_info.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 92 |
| 92 // Inform the listener that no file was selected. | 93 // Inform the listener that no file was selected. |
| 93 // Post a task rather than calling FileSelectionCanceled directly to ensure | 94 // Post a task rather than calling FileSelectionCanceled directly to ensure |
| 94 // that the listener is called asynchronously. | 95 // that the listener is called asynchronously. |
| 95 base::ThreadTaskRunnerHandle::Get()->PostTask( | 96 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 96 FROM_HERE, | 97 FROM_HERE, |
| 97 base::Bind(&SelectFileDialog::CancelFileSelection, this, params)); | 98 base::Bind(&SelectFileDialog::CancelFileSelection, this, params)); |
| 98 return; | 99 return; |
| 99 } | 100 } |
| 100 | 101 |
| 102 // Shorten filename if necessary. | |
| 103 base::FilePath filename = default_path.BaseName(); | |
| 104 base::FilePath path = default_path; | |
| 105 size_t max_name_length = 255; | |
|
Lei Zhang
2017/04/12 19:10:25
const size_t kMaxNameLength ?
rbpotter
2017/04/13 00:25:02
Done.
| |
| 106 if (filename.value().length() > max_name_length) { | |
| 107 base::FilePath::StringType extension = filename.Extension(); | |
|
Lei Zhang
2017/04/12 19:10:25
What if the extension is 256 letters long?
rbpotter
2017/04/13 00:25:02
Have addressed this in new patch.
| |
| 108 path = default_path.DirName().Append( | |
| 109 filename.value().substr(0, max_name_length - extension.length())); | |
| 110 path = path.AddExtension(extension); | |
| 111 } | |
| 112 | |
| 101 // Call the platform specific implementation of the file selection dialog. | 113 // Call the platform specific implementation of the file selection dialog. |
| 102 SelectFileImpl(type, title, default_path, file_types, file_type_index, | 114 SelectFileImpl(type, title, path, file_types, file_type_index, |
| 103 default_extension, owning_window, params); | 115 default_extension, owning_window, params); |
| 104 } | 116 } |
| 105 | 117 |
| 106 bool SelectFileDialog::HasMultipleFileTypeChoices() { | 118 bool SelectFileDialog::HasMultipleFileTypeChoices() { |
| 107 return HasMultipleFileTypeChoicesImpl(); | 119 return HasMultipleFileTypeChoicesImpl(); |
| 108 } | 120 } |
| 109 | 121 |
| 110 SelectFileDialog::SelectFileDialog(Listener* listener, | 122 SelectFileDialog::SelectFileDialog(Listener* listener, |
| 111 ui::SelectFilePolicy* policy) | 123 ui::SelectFilePolicy* policy) |
| 112 : listener_(listener), | 124 : listener_(listener), |
| 113 select_file_policy_(policy) { | 125 select_file_policy_(policy) { |
| 114 DCHECK(listener_); | 126 DCHECK(listener_); |
| 115 } | 127 } |
| 116 | 128 |
| 117 SelectFileDialog::~SelectFileDialog() {} | 129 SelectFileDialog::~SelectFileDialog() {} |
| 118 | 130 |
| 119 void SelectFileDialog::CancelFileSelection(void* params) { | 131 void SelectFileDialog::CancelFileSelection(void* params) { |
| 120 if (listener_) | 132 if (listener_) |
| 121 listener_->FileSelectionCanceled(params); | 133 listener_->FileSelectionCanceled(params); |
| 122 } | 134 } |
| 123 | 135 |
| 124 } // namespace ui | 136 } // namespace ui |
| OLD | NEW |