OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/shell_dialogs/select_file_dialog_mac.h" | 5 #include "ui/shell_dialogs/select_file_dialog_mac.h" |
6 | 6 |
7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "ui/base/l10n/l10n_util_mac.h" | 22 #include "ui/base/l10n/l10n_util_mac.h" |
23 #include "ui/strings/grit/ui_strings.h" | 23 #include "ui/strings/grit/ui_strings.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 const int kFileTypePopupTag = 1234; | 27 const int kFileTypePopupTag = 1234; |
28 | 28 |
29 CFStringRef CreateUTIFromExtension(const base::FilePath::StringType& ext) { | 29 CFStringRef CreateUTIFromExtension(const base::FilePath::StringType& ext) { |
30 base::ScopedCFTypeRef<CFStringRef> ext_cf(base::SysUTF8ToCFStringRef(ext)); | 30 base::ScopedCFTypeRef<CFStringRef> ext_cf(base::SysUTF8ToCFStringRef(ext)); |
31 return UTTypeCreatePreferredIdentifierForTag( | 31 return UTTypeCreatePreferredIdentifierForTag( |
32 kUTTagClassFilenameExtension, ext_cf.get(), NULL); | 32 kUTTagClassFilenameExtension, ext_cf.get(), NULL); |
Avi (use Gerrit)
2016/07/21 14:25:20
The documentation (https://developer.apple.com/lib
karandeepb
2016/07/22 09:17:16
Filed rdar://27490414. Although can't reproduce t
| |
33 } | 33 } |
34 | 34 |
35 NSString* GetDescriptionFromExtension(const base::FilePath::StringType& ext) { | 35 NSString* GetDescriptionFromExtension(const base::FilePath::StringType& ext) { |
36 base::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext)); | 36 base::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext)); |
37 base::ScopedCFTypeRef<CFStringRef> description( | 37 base::ScopedCFTypeRef<CFStringRef> description( |
38 UTTypeCopyDescription(uti.get())); | 38 UTTypeCopyDescription(uti.get())); |
39 | 39 |
40 if (description && CFStringGetLength(description)) | 40 if (description && CFStringGetLength(description)) |
41 return [[base::mac::CFToNSCast(description.get()) retain] autorelease]; | 41 return [[base::mac::CFToNSCast(description.get()) retain] autorelease]; |
42 | 42 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 DCHECK_NE(0u, [type_description length]); | 303 DCHECK_NE(0u, [type_description length]); |
304 [popup addItemWithTitle:type_description]; | 304 [popup addItemWithTitle:type_description]; |
305 | 305 |
306 // Populate file_type_lists. | 306 // Populate file_type_lists. |
307 // Set to store different extensions in the current extension group. | 307 // Set to store different extensions in the current extension group. |
308 NSMutableSet* file_type_set = [NSMutableSet set]; | 308 NSMutableSet* file_type_set = [NSMutableSet set]; |
309 for (const base::FilePath::StringType& ext : ext_list) { | 309 for (const base::FilePath::StringType& ext : ext_list) { |
310 if (ext == default_extension) | 310 if (ext == default_extension) |
311 default_extension_index = i; | 311 default_extension_index = i; |
312 | 312 |
313 // Crash reports suggest that CreateUTIFromExtension may return nil. Hence | |
314 // we nil check before adding to |file_type_set|. See crbug.com/630101. | |
313 base::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext)); | 315 base::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext)); |
314 [file_type_set addObject:base::mac::CFToNSCast(uti.get())]; | 316 if (uti) |
317 [file_type_set addObject:base::mac::CFToNSCast(uti.get())]; | |
315 | 318 |
316 // Always allow the extension itself, in case the UTI doesn't map | 319 // Always allow the extension itself, in case the UTI doesn't map |
317 // back to the original extension correctly. This occurs with dynamic | 320 // back to the original extension correctly. This occurs with dynamic |
318 // UTIs on 10.7 and 10.8. | 321 // UTIs on 10.7 and 10.8. |
319 // See http://crbug.com/148840, http://openradar.me/12316273 | 322 // See http://crbug.com/148840, http://openradar.me/12316273 |
320 base::ScopedCFTypeRef<CFStringRef> ext_cf( | 323 base::ScopedCFTypeRef<CFStringRef> ext_cf( |
321 base::SysUTF8ToCFStringRef(ext)); | 324 base::SysUTF8ToCFStringRef(ext)); |
322 [file_type_set addObject:base::mac::CFToNSCast(ext_cf.get())]; | 325 [file_type_set addObject:base::mac::CFToNSCast(ext_cf.get())]; |
323 } | 326 } |
324 [file_type_lists addObject:[file_type_set allObjects]]; | 327 [file_type_lists addObject:[file_type_set allObjects]]; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 // For save dialogs, this causes the first item in the allowedFileTypes | 445 // For save dialogs, this causes the first item in the allowedFileTypes |
443 // array to be used as the extension for the save panel. | 446 // array to be used as the extension for the save panel. |
444 [dialog_ setAllowedFileTypes:[fileTypeLists_ objectAtIndex:index]]; | 447 [dialog_ setAllowedFileTypes:[fileTypeLists_ objectAtIndex:index]]; |
445 } else { | 448 } else { |
446 // The user selected "All files" option. | 449 // The user selected "All files" option. |
447 [dialog_ setAllowedFileTypes:nil]; | 450 [dialog_ setAllowedFileTypes:nil]; |
448 } | 451 } |
449 } | 452 } |
450 | 453 |
451 @end | 454 @end |
OLD | NEW |