| 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 29 matching lines...) Expand all Loading... |
| 40 #include "grit/chromium_strings.h" | 40 #include "grit/chromium_strings.h" |
| 41 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| 42 #import "skia/ext/skia_utils_mac.h" | 42 #import "skia/ext/skia_utils_mac.h" |
| 43 #include "third_party/skia/include/core/SkBitmap.h" | 43 #include "third_party/skia/include/core/SkBitmap.h" |
| 44 #include "third_party/skia/include/core/SkColor.h" | 44 #include "third_party/skia/include/core/SkColor.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 46 #import "ui/base/l10n/l10n_util_mac.h" | 46 #import "ui/base/l10n/l10n_util_mac.h" |
| 47 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
| 48 #include "ui/gfx/image/image_family.h" | 48 #include "ui/gfx/image/image_family.h" |
| 49 | 49 |
| 50 bool g_app_shims_allow_update_and_launch_in_tests = false; |
| 51 |
| 50 namespace { | 52 namespace { |
| 51 | 53 |
| 52 // Launch Services Key to run as an agent app, which doesn't launch in the dock. | 54 // Launch Services Key to run as an agent app, which doesn't launch in the dock. |
| 53 NSString* const kLSUIElement = @"LSUIElement"; | 55 NSString* const kLSUIElement = @"LSUIElement"; |
| 54 | 56 |
| 55 class ScopedCarbonHandle { | 57 class ScopedCarbonHandle { |
| 56 public: | 58 public: |
| 57 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { | 59 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { |
| 58 DCHECK(handle_); | 60 DCHECK(handle_); |
| 59 DCHECK_EQ(noErr, MemError()); | 61 DCHECK_EQ(noErr, MemError()); |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; | 559 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; |
| 558 return succeeded; | 560 return succeeded; |
| 559 } | 561 } |
| 560 | 562 |
| 561 if (!base::CopyDirectory(staging_path, dst_path, true)) { | 563 if (!base::CopyDirectory(staging_path, dst_path, true)) { |
| 562 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() | 564 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() |
| 563 << " failed"; | 565 << " failed"; |
| 564 return succeeded; | 566 return succeeded; |
| 565 } | 567 } |
| 566 | 568 |
| 569 // Remove the quarantine attribute from both the bundle and the executable. |
| 567 base::mac::RemoveQuarantineAttribute(dst_path.Append(app_name)); | 570 base::mac::RemoveQuarantineAttribute(dst_path.Append(app_name)); |
| 571 base::mac::RemoveQuarantineAttribute( |
| 572 dst_path.Append(app_name) |
| 573 .Append("Contents").Append("MacOS").Append("app_mode_loader")); |
| 568 ++succeeded; | 574 ++succeeded; |
| 569 } | 575 } |
| 570 | 576 |
| 571 return succeeded; | 577 return succeeded; |
| 572 } | 578 } |
| 573 | 579 |
| 574 bool WebAppShortcutCreator::CreateShortcuts( | 580 bool WebAppShortcutCreator::CreateShortcuts( |
| 575 ShortcutCreationReason creation_reason, | 581 ShortcutCreationReason creation_reason, |
| 576 ShortcutLocations creation_locations) { | 582 ShortcutLocations creation_locations) { |
| 577 const base::FilePath applications_dir = GetApplicationsDirname(); | 583 const base::FilePath applications_dir = GetApplicationsDirname(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 inFileViewerRootedAtPath:nil]; | 862 inFileViewerRootedAtPath:nil]; |
| 857 } | 863 } |
| 858 | 864 |
| 859 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) { | 865 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) { |
| 860 WebAppShortcutCreator shortcut_creator( | 866 WebAppShortcutCreator shortcut_creator( |
| 861 base::FilePath(), shortcut_info, extensions::FileHandlersInfo()); | 867 base::FilePath(), shortcut_info, extensions::FileHandlersInfo()); |
| 862 return shortcut_creator.GetApplicationsShortcutPath(); | 868 return shortcut_creator.GetApplicationsShortcutPath(); |
| 863 } | 869 } |
| 864 | 870 |
| 865 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) { | 871 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) { |
| 866 if (AppShimsDisabledForTest()) | 872 if (AppShimsDisabledForTest() && |
| 873 !g_app_shims_allow_update_and_launch_in_tests) { |
| 867 return; | 874 return; |
| 875 } |
| 868 | 876 |
| 869 content::BrowserThread::PostTask( | 877 content::BrowserThread::PostTask( |
| 870 content::BrowserThread::FILE, FROM_HERE, | 878 content::BrowserThread::FILE, FROM_HERE, |
| 871 base::Bind(&LaunchShimOnFileThread, shortcut_info)); | 879 base::Bind(&LaunchShimOnFileThread, shortcut_info)); |
| 872 } | 880 } |
| 873 | 881 |
| 874 // Called when the app's ShortcutInfo (with icon) is loaded when creating app | 882 // Called when the app's ShortcutInfo (with icon) is loaded when creating app |
| 875 // shortcuts. | 883 // shortcuts. |
| 876 void CreateAppShortcutInfoLoaded( | 884 void CreateAppShortcutInfoLoaded( |
| 877 Profile* profile, | 885 Profile* profile, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 app_data_path, shortcut_info, extensions::FileHandlersInfo()); | 977 app_data_path, shortcut_info, extensions::FileHandlersInfo()); |
| 970 shortcut_creator.DeleteShortcuts(); | 978 shortcut_creator.DeleteShortcuts(); |
| 971 } | 979 } |
| 972 | 980 |
| 973 void UpdatePlatformShortcuts( | 981 void UpdatePlatformShortcuts( |
| 974 const base::FilePath& app_data_path, | 982 const base::FilePath& app_data_path, |
| 975 const base::string16& old_app_title, | 983 const base::string16& old_app_title, |
| 976 const ShortcutInfo& shortcut_info, | 984 const ShortcutInfo& shortcut_info, |
| 977 const extensions::FileHandlersInfo& file_handlers_info) { | 985 const extensions::FileHandlersInfo& file_handlers_info) { |
| 978 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 986 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 979 if (AppShimsDisabledForTest()) | 987 if (AppShimsDisabledForTest() && |
| 988 !g_app_shims_allow_update_and_launch_in_tests) { |
| 980 return; | 989 return; |
| 990 } |
| 981 | 991 |
| 982 WebAppShortcutCreator shortcut_creator( | 992 WebAppShortcutCreator shortcut_creator( |
| 983 app_data_path, shortcut_info, file_handlers_info); | 993 app_data_path, shortcut_info, file_handlers_info); |
| 984 shortcut_creator.UpdateShortcuts(); | 994 shortcut_creator.UpdateShortcuts(); |
| 985 } | 995 } |
| 986 | 996 |
| 987 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { | 997 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { |
| 988 const std::string profile_base_name = profile_path.BaseName().value(); | 998 const std::string profile_base_name = profile_path.BaseName().value(); |
| 989 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( | 999 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( |
| 990 profile_path.Append(chrome::kWebAppDirname), profile_base_name); | 1000 profile_path.Append(chrome::kWebAppDirname), profile_base_name); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1013 web_app::UpdateShortcutInfoAndIconForApp( | 1023 web_app::UpdateShortcutInfoAndIconForApp( |
| 1014 app, | 1024 app, |
| 1015 profile, | 1025 profile, |
| 1016 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1026 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
| 1017 profile, | 1027 profile, |
| 1018 app, | 1028 app, |
| 1019 close_callback)); | 1029 close_callback)); |
| 1020 } | 1030 } |
| 1021 | 1031 |
| 1022 } // namespace chrome | 1032 } // namespace chrome |
| OLD | NEW |