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

Unified Diff: ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc

Issue 11784036: [gtk] Fix file filter bug for <input type=file accept=mime/type>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: erg@ review Created 7 years, 11 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 | « chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc
diff --git a/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc b/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc
index b66afc280eded3d8436c0aa60e333475fd135ac9..77839eade8867ff354cc9385bf5c240f426d4a5f 100644
--- a/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc
+++ b/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc
@@ -23,6 +23,18 @@
namespace {
+// Makes sure that .jpg also shows .JPG. |data| is a std::string* in disguise.
+gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
+ gpointer data) {
Evan Stade 2013/01/10 01:50:06 just make data a std::string*
Dan Beam 2013/01/10 05:37:08 Done.
+ std::string* file_extension = reinterpret_cast<std::string*>(data);
+ return EndsWith(file_info->filename, *file_extension, false);
+}
+
+// Deletes |data| when gtk_file_filter_add_custom() is done with it.
+void OnFileFilterDataDestroyed(gpointer data) {
+ delete reinterpret_cast<std::string*>(data);
+}
+
// Implementation of SelectFileDialog that shows a Gtk common dialog for
// choosing a file or folder. This acts as a modal dialog.
class SelectFileDialogImplGTK : public ui::SelectFileDialogImpl {
@@ -227,9 +239,14 @@ void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
if (!current_extension.empty()) {
if (!filter)
filter = gtk_file_filter_new();
- std::string pattern = "*." + current_extension;
- gtk_file_filter_add_pattern(filter, pattern.c_str());
- fallback_labels.insert(pattern);
+ // |file_extension| is freed in |OnFileFilterDataDestroyed()|.
+ std::string* file_extension = new std::string("." + current_extension);
Evan Stade 2013/01/10 01:50:06 scoped_ptr for clarity (and .release() it to the f
Dan Beam 2013/01/10 05:37:08 Done.
+ gtk_file_filter_add_custom(filter,
+ GTK_FILE_FILTER_FILENAME,
+ &FileFilterCaseInsensitive,
+ reinterpret_cast<gpointer>(file_extension),
Evan Stade 2013/01/10 01:50:06 sure this cast is necessary?
Dan Beam 2013/01/10 05:37:08 Nope, it's not.
+ &OnFileFilterDataDestroyed);
+ fallback_labels.insert(std::string("*").append(*file_extension));
Evan Stade 2013/01/10 01:50:06 you should not use file_extension after you've han
Dan Beam 2013/01/10 05:37:08 Done.
}
}
// We didn't find any non-empty extensions to filter on.
« no previous file with comments | « chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698