| 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 <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 return 0; | 693 return 0; |
| 694 | 694 |
| 695 for (std::vector<base::FilePath>::const_iterator it = folders.begin(); | 695 for (std::vector<base::FilePath>::const_iterator it = folders.begin(); |
| 696 it != folders.end(); ++it) { | 696 it != folders.end(); ++it) { |
| 697 const base::FilePath& dst_path = *it; | 697 const base::FilePath& dst_path = *it; |
| 698 if (!base::CreateDirectory(dst_path)) { | 698 if (!base::CreateDirectory(dst_path)) { |
| 699 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; | 699 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; |
| 700 return succeeded; | 700 return succeeded; |
| 701 } | 701 } |
| 702 | 702 |
| 703 // Ensure the copy does not merge with stale info. |
| 704 base::DeleteFile(dst_path.Append(app_name), true); |
| 705 |
| 703 if (!base::CopyDirectory(staging_path, dst_path, true)) { | 706 if (!base::CopyDirectory(staging_path, dst_path, true)) { |
| 704 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() | 707 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() |
| 705 << " failed"; | 708 << " failed"; |
| 706 return succeeded; | 709 return succeeded; |
| 707 } | 710 } |
| 708 | 711 |
| 709 // Remove the quarantine attribute from both the bundle and the executable. | 712 // Remove the quarantine attribute from both the bundle and the executable. |
| 710 base::mac::RemoveQuarantineAttribute(dst_path.Append(app_name)); | 713 base::mac::RemoveQuarantineAttribute(dst_path.Append(app_name)); |
| 711 base::mac::RemoveQuarantineAttribute( | 714 base::mac::RemoveQuarantineAttribute( |
| 712 dst_path.Append(app_name) | 715 dst_path.Append(app_name) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 base::FilePath bundle_path = GetAppBundleById(GetBundleIdentifier()); | 794 base::FilePath bundle_path = GetAppBundleById(GetBundleIdentifier()); |
| 792 if (!bundle_path.empty() && HasSameUserDataDir(bundle_path)) | 795 if (!bundle_path.empty() && HasSameUserDataDir(bundle_path)) |
| 793 base::DeleteFile(bundle_path, true); | 796 base::DeleteFile(bundle_path, true); |
| 794 | 797 |
| 795 // Delete the internal one. | 798 // Delete the internal one. |
| 796 DeletePathAndParentIfEmpty(GetInternalShortcutPath()); | 799 DeletePathAndParentIfEmpty(GetInternalShortcutPath()); |
| 797 } | 800 } |
| 798 | 801 |
| 799 bool WebAppShortcutCreator::UpdateShortcuts() { | 802 bool WebAppShortcutCreator::UpdateShortcuts() { |
| 800 std::vector<base::FilePath> paths; | 803 std::vector<base::FilePath> paths; |
| 801 base::DeleteFile(GetInternalShortcutPath(), true); | |
| 802 paths.push_back(app_data_dir_); | 804 paths.push_back(app_data_dir_); |
| 803 | 805 |
| 804 // Try to update the copy under /Applications. If that does not exist, check | 806 // Try to update the copy under /Applications. If that does not exist, check |
| 805 // if a matching bundle can be found elsewhere. | 807 // if a matching bundle can be found elsewhere. |
| 806 base::FilePath app_path = GetApplicationsShortcutPath(); | 808 base::FilePath app_path = GetApplicationsShortcutPath(); |
| 807 if (app_path.empty() || !base::PathExists(app_path)) | 809 if (app_path.empty() || !base::PathExists(app_path)) |
| 808 app_path = GetAppBundleById(GetBundleIdentifier()); | 810 app_path = GetAppBundleById(GetBundleIdentifier()); |
| 809 | 811 |
| 810 if (!app_path.empty()) { | 812 if (!app_path.empty()) |
| 811 base::DeleteFile(app_path, true); | |
| 812 paths.push_back(app_path.DirName()); | 813 paths.push_back(app_path.DirName()); |
| 813 } | |
| 814 | 814 |
| 815 size_t success_count = CreateShortcutsIn(paths); | 815 size_t success_count = CreateShortcutsIn(paths); |
| 816 if (success_count == 0) | 816 if (success_count == 0) |
| 817 return false; | 817 return false; |
| 818 | 818 |
| 819 UpdateInternalBundleIdentifier(); | 819 UpdateInternalBundleIdentifier(); |
| 820 return success_count == paths.size() && !app_path.empty(); | 820 return success_count == paths.size() && !app_path.empty(); |
| 821 } | 821 } |
| 822 | 822 |
| 823 base::FilePath WebAppShortcutCreator::GetApplicationsDirname() const { | 823 base::FilePath WebAppShortcutCreator::GetApplicationsDirname() const { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 switches::kEnableAppsFileAssociations)) { | 890 switches::kEnableAppsFileAssociations)) { |
| 891 UpdateFileTypes(plist, file_handlers_info_); | 891 UpdateFileTypes(plist, file_handlers_info_); |
| 892 } | 892 } |
| 893 | 893 |
| 894 return [plist writeToFile:plist_path | 894 return [plist writeToFile:plist_path |
| 895 atomically:YES]; | 895 atomically:YES]; |
| 896 } | 896 } |
| 897 | 897 |
| 898 bool WebAppShortcutCreator::UpdateDisplayName( | 898 bool WebAppShortcutCreator::UpdateDisplayName( |
| 899 const base::FilePath& app_path) const { | 899 const base::FilePath& app_path) const { |
| 900 // OSX searches for the best language in the order of preferred languages. | 900 // Localization is used to display the app name (rather than the bundle |
| 901 // Since we only have one localization directory, it will choose this one. | 901 // filename). OSX searches for the best language in the order of preferred |
| 902 base::FilePath localized_dir = GetResourcesPath(app_path).Append("en.lproj"); | 902 // languages, but one of them must be found otherwise it will default to |
| 903 // the filename. |
| 904 NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0]; |
| 905 base::FilePath localized_dir = GetResourcesPath(app_path).Append( |
| 906 base::SysNSStringToUTF8(language) + ".lproj"); |
| 903 if (!base::CreateDirectory(localized_dir)) | 907 if (!base::CreateDirectory(localized_dir)) |
| 904 return false; | 908 return false; |
| 905 | 909 |
| 906 NSString* bundle_name = base::SysUTF16ToNSString(info_->title); | 910 NSString* bundle_name = base::SysUTF16ToNSString(info_->title); |
| 907 NSString* display_name = base::SysUTF16ToNSString(info_->title); | 911 NSString* display_name = base::SysUTF16ToNSString(info_->title); |
| 908 if (HasExistingExtensionShim(GetApplicationsDirname(), info_->extension_id, | 912 if (HasExistingExtensionShim(GetApplicationsDirname(), info_->extension_id, |
| 909 app_path.BaseName())) { | 913 app_path.BaseName())) { |
| 910 display_name = [bundle_name | 914 display_name = [bundle_name |
| 911 stringByAppendingString:base::SysUTF8ToNSString( | 915 stringByAppendingString:base::SysUTF8ToNSString( |
| 912 " (" + info_->profile_name + ")")]; | 916 " (" + info_->profile_name + ")")]; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 web_app::GetShortcutInfoForApp( | 1212 web_app::GetShortcutInfoForApp( |
| 1209 app, | 1213 app, |
| 1210 profile, | 1214 profile, |
| 1211 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1215 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
| 1212 profile, | 1216 profile, |
| 1213 app, | 1217 app, |
| 1214 close_callback)); | 1218 close_callback)); |
| 1215 } | 1219 } |
| 1216 | 1220 |
| 1217 } // namespace chrome | 1221 } // namespace chrome |
| OLD | NEW |