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.h" | 5 #include "ui/shell_dialogs/select_file_dialog.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
23 #include "grit/ui_strings.h" | 23 #include "grit/ui_strings.h" |
24 #import "ui/base/cocoa/nib_loading.h" | 24 #import "ui/base/cocoa/nib_loading.h" |
25 #include "ui/base/l10n/l10n_util_mac.h" | 25 #include "ui/base/l10n/l10n_util_mac.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const int kFileTypePopupTag = 1234; | 29 const int kFileTypePopupTag = 1234; |
30 | 30 |
31 CFStringRef CreateUTIFromExtension(const base::FilePath::StringType& ext) { | 31 CFStringRef CreateUTIFromExtension(const base::FilePath::StringType& ext) { |
32 base::mac::ScopedCFTypeRef<CFStringRef> ext_cf( | 32 base::ScopedCFTypeRef<CFStringRef> ext_cf(base::SysUTF8ToCFStringRef(ext)); |
33 base::SysUTF8ToCFStringRef(ext)); | |
34 return UTTypeCreatePreferredIdentifierForTag( | 33 return UTTypeCreatePreferredIdentifierForTag( |
35 kUTTagClassFilenameExtension, ext_cf.get(), NULL); | 34 kUTTagClassFilenameExtension, ext_cf.get(), NULL); |
36 } | 35 } |
37 | 36 |
38 } // namespace | 37 } // namespace |
39 | 38 |
40 class SelectFileDialogImpl; | 39 class SelectFileDialogImpl; |
41 | 40 |
42 // A bridge class to act as the modal delegate to the save/open sheet and send | 41 // A bridge class to act as the modal delegate to the save/open sheet and send |
43 // the results to the C++ class. | 42 // the results to the C++ class. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // it is not always the case that the given extensions in one of the sub- | 218 // it is not always the case that the given extensions in one of the sub- |
220 // lists are all synonyms. In fact, in the case of a <select> element with | 219 // lists are all synonyms. In fact, in the case of a <select> element with |
221 // multiple "accept" types, all the extensions allowed for all the types | 220 // multiple "accept" types, all the extensions allowed for all the types |
222 // will be part of one list. To be safe, allow the types of all the | 221 // will be part of one list. To be safe, allow the types of all the |
223 // specified extensions. | 222 // specified extensions. |
224 NSMutableSet* file_type_set = [NSMutableSet set]; | 223 NSMutableSet* file_type_set = [NSMutableSet set]; |
225 for (size_t i = 0; i < file_types->extensions.size(); ++i) { | 224 for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
226 const std::vector<base::FilePath::StringType>& ext_list = | 225 const std::vector<base::FilePath::StringType>& ext_list = |
227 file_types->extensions[i]; | 226 file_types->extensions[i]; |
228 for (size_t j = 0; j < ext_list.size(); ++j) { | 227 for (size_t j = 0; j < ext_list.size(); ++j) { |
229 base::mac::ScopedCFTypeRef<CFStringRef> uti( | 228 base::ScopedCFTypeRef<CFStringRef> uti( |
230 CreateUTIFromExtension(ext_list[j])); | 229 CreateUTIFromExtension(ext_list[j])); |
231 [file_type_set addObject:base::mac::CFToNSCast(uti.get())]; | 230 [file_type_set addObject:base::mac::CFToNSCast(uti.get())]; |
232 | 231 |
233 // Always allow the extension itself, in case the UTI doesn't map | 232 // Always allow the extension itself, in case the UTI doesn't map |
234 // back to the original extension correctly. This occurs with dynamic | 233 // back to the original extension correctly. This occurs with dynamic |
235 // UTIs on 10.7 and 10.8. | 234 // UTIs on 10.7 and 10.8. |
236 // See http://crbug.com/148840, http://openradar.me/12316273 | 235 // See http://crbug.com/148840, http://openradar.me/12316273 |
237 base::mac::ScopedCFTypeRef<CFStringRef> ext_cf( | 236 base::ScopedCFTypeRef<CFStringRef> ext_cf( |
238 base::SysUTF8ToCFStringRef(ext_list[j])); | 237 base::SysUTF8ToCFStringRef(ext_list[j])); |
239 [file_type_set addObject:base::mac::CFToNSCast(ext_cf.get())]; | 238 [file_type_set addObject:base::mac::CFToNSCast(ext_cf.get())]; |
240 } | 239 } |
241 } | 240 } |
242 allowed_file_types = [file_type_set allObjects]; | 241 allowed_file_types = [file_type_set allObjects]; |
243 } | 242 } |
244 if (type == SELECT_SAVEAS_FILE) | 243 if (type == SELECT_SAVEAS_FILE) |
245 [dialog setAllowedFileTypes:allowed_file_types]; | 244 [dialog setAllowedFileTypes:allowed_file_types]; |
246 // else we'll pass it in when we run the open panel | 245 // else we'll pass it in when we run the open panel |
247 | 246 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 NSString* type_description; | 332 NSString* type_description; |
334 if (type < file_types->extension_description_overrides.size()) { | 333 if (type < file_types->extension_description_overrides.size()) { |
335 type_description = base::SysUTF16ToNSString( | 334 type_description = base::SysUTF16ToNSString( |
336 file_types->extension_description_overrides[type]); | 335 file_types->extension_description_overrides[type]); |
337 } else { | 336 } else { |
338 // No description given for a list of extensions; pick the first one from | 337 // No description given for a list of extensions; pick the first one from |
339 // the list (arbitrarily) and use its description. | 338 // the list (arbitrarily) and use its description. |
340 const std::vector<base::FilePath::StringType>& ext_list = | 339 const std::vector<base::FilePath::StringType>& ext_list = |
341 file_types->extensions[type]; | 340 file_types->extensions[type]; |
342 DCHECK(!ext_list.empty()); | 341 DCHECK(!ext_list.empty()); |
343 base::mac::ScopedCFTypeRef<CFStringRef> uti( | 342 base::ScopedCFTypeRef<CFStringRef> uti( |
344 CreateUTIFromExtension(ext_list[0])); | 343 CreateUTIFromExtension(ext_list[0])); |
345 base::mac::ScopedCFTypeRef<CFStringRef> description( | 344 base::ScopedCFTypeRef<CFStringRef> description( |
346 UTTypeCopyDescription(uti.get())); | 345 UTTypeCopyDescription(uti.get())); |
347 | 346 |
348 type_description = | 347 type_description = |
349 [[base::mac::CFToNSCast(description.get()) retain] autorelease]; | 348 [[base::mac::CFToNSCast(description.get()) retain] autorelease]; |
350 } | 349 } |
351 [popup addItemWithTitle:type_description]; | 350 [popup addItemWithTitle:type_description]; |
352 } | 351 } |
353 | 352 |
354 [popup selectItemAtIndex:file_type_index - 1]; // 1-based | 353 [popup selectItemAtIndex:file_type_index - 1]; // 1-based |
355 return accessory_view; | 354 return accessory_view; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 417 |
419 namespace ui { | 418 namespace ui { |
420 | 419 |
421 SelectFileDialog* CreateMacSelectFileDialog( | 420 SelectFileDialog* CreateMacSelectFileDialog( |
422 SelectFileDialog::Listener* listener, | 421 SelectFileDialog::Listener* listener, |
423 SelectFilePolicy* policy) { | 422 SelectFilePolicy* policy) { |
424 return new SelectFileDialogImpl(listener, policy); | 423 return new SelectFileDialogImpl(listener, policy); |
425 } | 424 } |
426 | 425 |
427 } // namespace ui | 426 } // namespace ui |
OLD | NEW |