Index: ui/base/dialogs/select_file_dialog_mac.mm |
diff --git a/ui/base/dialogs/select_file_dialog_mac.mm b/ui/base/dialogs/select_file_dialog_mac.mm |
index 1f2efc80ee8670c3de030c86452d0eeb7ac07668..731889c9bffa4949262934a20909dcec4ce82295 100644 |
--- a/ui/base/dialogs/select_file_dialog_mac.mm |
+++ b/ui/base/dialogs/select_file_dialog_mac.mm |
@@ -35,6 +35,13 @@ CFStringRef CreateUTIFromExtension(const FilePath::StringType& ext) { |
kUTTagClassFilenameExtension, ext_cf.get(), NULL); |
} |
+FilePath::StringType LastExtension(const FilePath::StringType& ext) { |
+ size_t last_dot = ext.rfind('.'); |
+ if (last_dot == std::string::npos) |
+ return ext; |
+ return ext.substr(last_dot + 1); |
Avi (use Gerrit)
2012/11/13 20:41:00
Isn't there something on FilePath that would do th
davidben
2012/11/13 20:53:28
There is FilePath::Extension() and friends, but it
|
+} |
+ |
} // namespace |
class SelectFileDialogImpl; |
@@ -224,8 +231,11 @@ void SelectFileDialogImpl::SelectFileImpl( |
const std::vector<FilePath::StringType>& ext_list = |
file_types->extensions[i]; |
for (size_t j = 0; j < ext_list.size(); ++j) { |
+ // NSSavePanel cannot handle extensions like tar.gz, so we |
Avi (use Gerrit)
2012/11/13 20:41:00
It's not an NSSavePanel issue, but a UTI issue; a
|
+ // remove all but the last component. |
+ std::string ext = LastExtension(ext_list[j]); |
base::mac::ScopedCFTypeRef<CFStringRef> uti( |
- CreateUTIFromExtension(ext_list[j])); |
+ CreateUTIFromExtension(ext)); |
[file_type_set addObject:base::mac::CFToNSCast(uti.get())]; |
// Always allow the extension itself, in case the UTI doesn't map |
@@ -233,7 +243,7 @@ void SelectFileDialogImpl::SelectFileImpl( |
// UTIs on 10.7 and 10.8. |
// See http://crbug.com/148840, http://openradar.me/12316273 |
base::mac::ScopedCFTypeRef<CFStringRef> ext_cf( |
- base::SysUTF8ToCFStringRef(ext_list[j])); |
+ base::SysUTF8ToCFStringRef(ext)); |
[file_type_set addObject:base::mac::CFToNSCast(ext_cf.get())]; |
} |
} |
@@ -258,7 +268,8 @@ void SelectFileDialogImpl::SelectFileImpl( |
file_types ? file_types->extensions.size() > 1 : true; |
if (!default_extension.empty()) |
- [dialog setAllowedFileTypes:@[base::SysUTF8ToNSString(default_extension)]]; |
+ [dialog setAllowedFileTypes:@[base::SysUTF8ToNSString( |
+ LastExtension(default_extension))]]; |
params_map_[dialog] = params; |
type_map_[dialog] = type; |