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

Unified Diff: ui/shell_dialogs/select_file_dialog.cc

Issue 2804793002: Print Preview: Fix failure to save with long page title (Closed)
Patch Set: Remove unused line 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 | « ui/shell_dialogs/select_file_dialog.h ('k') | ui/shell_dialogs/select_file_dialog_unittest.cc » ('j') | 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..e10afac1b6b476c5297851196f59c6aa4d9eda79 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"
@@ -74,6 +75,30 @@ scoped_refptr<SelectFileDialog> SelectFileDialog::Create(
return CreateSelectFileDialog(listener, policy);
}
+base::FilePath SelectFileDialog::GetShortenedFilePath(
+ const base::FilePath& path) {
+ const size_t kMaxNameLength = 255;
+ if (path.BaseName().value().length() <= kMaxNameLength)
+ return path;
+ base::FilePath filename = path.BaseName();
+ base::FilePath::StringType extension = filename.FinalExtension();
+ filename = filename.RemoveFinalExtension();
+ base::FilePath::StringType file_string = filename.value();
+ // 1 for . plus 12 for longest known extension.
+ size_t max_extension_length = 13;
+ if (file_string.length() < kMaxNameLength) {
+ max_extension_length =
+ std::max(max_extension_length, kMaxNameLength - file_string.length());
+ }
+ if (extension.length() > max_extension_length) {
+ // Take the first max_extension_length characters (this will be the
+ // leading '.' plus the next max_extension_length - 1).
+ extension.resize(max_extension_length);
+ }
+ file_string.resize(kMaxNameLength - extension.length());
+ return path.DirName().Append(file_string).AddExtension(extension);
+}
+
void SelectFileDialog::SelectFile(
Type type,
const base::string16& title,
@@ -98,8 +123,10 @@ void SelectFileDialog::SelectFile(
return;
}
+ base::FilePath path = GetShortenedFilePath(default_path);
+
// 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 | « ui/shell_dialogs/select_file_dialog.h ('k') | ui/shell_dialogs/select_file_dialog_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698