Chromium Code Reviews| 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 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 } | 521 } |
| 522 base::Version full_version(base::SysNSStringToUTF8(version_string)); | 522 base::Version full_version(base::SysNSStringToUTF8(version_string)); |
| 523 uint32_t major_version = 0; | 523 uint32_t major_version = 0; |
| 524 if (full_version.IsValid()) | 524 if (full_version.IsValid()) |
| 525 major_version = full_version.components()[0]; | 525 major_version = full_version.components()[0]; |
| 526 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); | 526 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); |
| 527 | 527 |
| 528 return BuildShortcutInfoFromBundle(bundle_path); | 528 return BuildShortcutInfoFromBundle(bundle_path); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void UpdateFileTypes(NSMutableDictionary* plist, | |
| 532 const extensions::FileHandlersInfo& file_handlers_info) { | |
|
tapted
2017/01/10 22:59:52
Can this entire type `FileHandlersInfo` be deleted
Matt Giuca
2017/01/11 00:58:52
Acknowledged: See previous email.
| |
| 533 NSMutableArray* document_types = | |
| 534 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; | |
| 535 | |
| 536 for (extensions::FileHandlersInfo::const_iterator info_it = | |
| 537 file_handlers_info.begin(); | |
| 538 info_it != file_handlers_info.end(); | |
| 539 ++info_it) { | |
| 540 const extensions::FileHandlerInfo& info = *info_it; | |
| 541 | |
| 542 NSMutableArray* file_extensions = | |
| 543 [NSMutableArray arrayWithCapacity:info.extensions.size()]; | |
| 544 for (std::set<std::string>::iterator it = info.extensions.begin(); | |
| 545 it != info.extensions.end(); | |
| 546 ++it) { | |
| 547 [file_extensions addObject:base::SysUTF8ToNSString(*it)]; | |
| 548 } | |
| 549 | |
| 550 NSMutableArray* mime_types = | |
| 551 [NSMutableArray arrayWithCapacity:info.types.size()]; | |
| 552 for (std::set<std::string>::iterator it = info.types.begin(); | |
| 553 it != info.types.end(); | |
| 554 ++it) { | |
| 555 [mime_types addObject:base::SysUTF8ToNSString(*it)]; | |
| 556 } | |
| 557 | |
| 558 NSDictionary* type_dictionary = @{ | |
| 559 // TODO(jackhou): Add the type name and and icon file once the manifest | |
| 560 // supports these. | |
| 561 // app_mode::kCFBundleTypeNameKey : , | |
| 562 // app_mode::kCFBundleTypeIconFileKey : , | |
| 563 app_mode::kCFBundleTypeExtensionsKey : file_extensions, | |
| 564 app_mode::kCFBundleTypeMIMETypesKey : mime_types, | |
| 565 app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer | |
| 566 }; | |
| 567 [document_types addObject:type_dictionary]; | |
| 568 } | |
| 569 | |
| 570 [plist setObject:document_types | |
| 571 forKey:app_mode::kCFBundleDocumentTypesKey]; | |
| 572 } | |
| 573 | |
| 574 void RevealAppShimInFinderForAppOnFileThread( | 531 void RevealAppShimInFinderForAppOnFileThread( |
| 575 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | 532 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, |
| 576 const base::FilePath& app_path) { | 533 const base::FilePath& app_path) { |
| 577 web_app::WebAppShortcutCreator shortcut_creator( | 534 web_app::WebAppShortcutCreator shortcut_creator( |
| 578 app_path, shortcut_info.get(), extensions::FileHandlersInfo()); | 535 app_path, shortcut_info.get(), extensions::FileHandlersInfo()); |
| 579 shortcut_creator.RevealAppShimInFinder(); | 536 shortcut_creator.RevealAppShimInFinder(); |
| 580 } | 537 } |
| 581 | 538 |
| 582 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch | 539 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch |
| 583 // upgrades to ensure all shortcuts a user may still have are repaired when | 540 // upgrades to ensure all shortcuts a user may still have are repaired when |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 if (info_->extension_id == app_mode::kAppListModeId) { | 842 if (info_->extension_id == app_mode::kAppListModeId) { |
| 886 // Prevent the app list from bouncing in the dock, and getting a run light. | 843 // Prevent the app list from bouncing in the dock, and getting a run light. |
| 887 [plist setObject:[NSNumber numberWithBool:YES] | 844 [plist setObject:[NSNumber numberWithBool:YES] |
| 888 forKey:kLSUIElement]; | 845 forKey:kLSUIElement]; |
| 889 } | 846 } |
| 890 | 847 |
| 891 base::FilePath app_name = app_path.BaseName().RemoveExtension(); | 848 base::FilePath app_name = app_path.BaseName().RemoveExtension(); |
| 892 [plist setObject:base::mac::FilePathToNSString(app_name) | 849 [plist setObject:base::mac::FilePathToNSString(app_name) |
| 893 forKey:base::mac::CFToNSCast(kCFBundleNameKey)]; | 850 forKey:base::mac::CFToNSCast(kCFBundleNameKey)]; |
| 894 | 851 |
| 895 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 896 switches::kEnableAppsFileAssociations)) { | |
| 897 UpdateFileTypes(plist, file_handlers_info_); | |
| 898 } | |
| 899 | |
| 900 return [plist writeToFile:plist_path | 852 return [plist writeToFile:plist_path |
| 901 atomically:YES]; | 853 atomically:YES]; |
| 902 } | 854 } |
| 903 | 855 |
| 904 bool WebAppShortcutCreator::UpdateDisplayName( | 856 bool WebAppShortcutCreator::UpdateDisplayName( |
| 905 const base::FilePath& app_path) const { | 857 const base::FilePath& app_path) const { |
| 906 // Localization is used to display the app name (rather than the bundle | 858 // Localization is used to display the app name (rather than the bundle |
| 907 // filename). OSX searches for the best language in the order of preferred | 859 // filename). OSX searches for the best language in the order of preferred |
| 908 // languages, but one of them must be found otherwise it will default to | 860 // languages, but one of them must be found otherwise it will default to |
| 909 // the filename. | 861 // the filename. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 BuildShortcutInfoFromBundle(*it); | 1081 BuildShortcutInfoFromBundle(*it); |
| 1130 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get(), | 1082 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get(), |
| 1131 extensions::FileHandlersInfo()); | 1083 extensions::FileHandlersInfo()); |
| 1132 shortcut_creator.DeleteShortcuts(); | 1084 shortcut_creator.DeleteShortcuts(); |
| 1133 } | 1085 } |
| 1134 } | 1086 } |
| 1135 | 1087 |
| 1136 } // namespace internals | 1088 } // namespace internals |
| 1137 | 1089 |
| 1138 } // namespace web_app | 1090 } // namespace web_app |
| OLD | NEW |