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

Unified Diff: chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.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
Index: chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc
diff --git a/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc b/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc
index a48d45056ce336626b47a20a8773f40e6aee1ed2..6b5f6420d437c45332e19e6372cf9d2af170ff9b 100644
--- a/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc
+++ b/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc
@@ -49,6 +49,18 @@ void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent);
}
+// Makes sure that .jpg also shows .JPG. |data| is a std::string* in disguise.
+gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
+ gpointer data) {
+ 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);
+}
+
} // namespace
namespace libgtk2ui {
@@ -272,9 +284,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);
+ gtk_file_filter_add_custom(filter,
+ GTK_FILE_FILTER_FILENAME,
+ &FileFilterCaseInsensitive,
+ reinterpret_cast<gpointer>(file_extension),
+ &OnFileFilterDataDestroyed);
+ fallback_labels.insert(std::string("*").append(*file_extension));
}
}
// We didn't find any non-empty extensions to filter on.
« no previous file with comments | « no previous file | ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc » ('j') | ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698