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