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

Unified Diff: ui/shell_dialogs/select_file_dialog.cc

Issue 2804793002: Print Preview: Fix failure to save with long page title (Closed)
Patch Set: Move length check to select file dialog Created 3 years, 8 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: ui/shell_dialogs/select_file_dialog.cc
diff --git a/ui/shell_dialogs/select_file_dialog.cc b/ui/shell_dialogs/select_file_dialog.cc
index 1aa7a0e26164079e0563943180353d03cdb6c861..05d9df1cc6092b491184e5f5eec1683510f403ad 100644
--- a/ui/shell_dialogs/select_file_dialog.cc
+++ b/ui/shell_dialogs/select_file_dialog.cc
@@ -5,6 +5,7 @@
#include "ui/shell_dialogs/select_file_dialog.h"
#include <stddef.h>
+#include <algorithm>
#include "base/bind.h"
#include "base/location.h"
@@ -85,6 +86,25 @@ void SelectFileDialog::SelectFile(
void* params) {
DCHECK(listener_);
+ // Shorten filename if necessary.
Lei Zhang 2017/04/06 00:47:05 Do this right before the SelectFileImpl() call. Ot
rbpotter 2017/04/12 17:25:19 Done.
+ base::FilePath filename = default_path.BaseName();
+ base::FilePath path = default_path.DirName();
+ int max_name_length = 255;
Lei Zhang 2017/04/06 00:47:05 Can this be size_t to avoid all the casts below.
rbpotter 2017/04/12 17:25:19 Done.
+ if (filename.value().length() > max_name_length ||
+ default_path.value().length() > MAX_PATH - 1) {
Lei Zhang 2017/04/06 00:47:05 Does MAX_PATH work on POSIX?
rbpotter 2017/04/12 17:25:19 Removed path length check so not an issue any more
+ base::FilePath::StringType extension = filename.Extension();
+ // Path name no longer than MAX_PATH - 2 - length of rest of path (remove
+ // 1 for separator and 1 for null character).
+ int max_path_length =
+ MAX_PATH - 2 - static_cast<int>(path.value().length());
+ int new_length = std::max(1, std::min(max_name_length, max_path_length) -
+ static_cast<int>(extension.length()));
+ path = path.Append(filename.value().substr(0, new_length));
+ path = path.AddExtension(extension);
+ } else {
+ path = path.Append(filename);
Lei Zhang 2017/04/06 00:47:05 Isn't this the same as: path = default_path; ?
rbpotter 2017/04/12 17:25:19 Done.
+ }
+
if (select_file_policy_.get() &&
!select_file_policy_->CanOpenSelectFileDialog()) {
select_file_policy_->SelectFileDenied();
@@ -99,7 +119,7 @@ void SelectFileDialog::SelectFile(
}
// Call the platform specific implementation of the file selection dialog.
- SelectFileImpl(type, title, default_path, file_types, file_type_index,
+ SelectFileImpl(type, title, path, file_types, file_type_index,
default_extension, owning_window, params);
}
« 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