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 "apps/app_shim/app_shim_mac.h" | |
11 #include "base/command_line.h" | 10 #include "base/command_line.h" |
12 #include "base/file_util.h" | 11 #include "base/file_util.h" |
13 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
14 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
15 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
16 #include "base/mac/launch_services_util.h" | 15 #include "base/mac/launch_services_util.h" |
17 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
18 #include "base/mac/scoped_cftyperef.h" | 17 #include "base/mac/scoped_cftyperef.h" |
19 #include "base/mac/scoped_nsobject.h" | 18 #include "base/mac/scoped_nsobject.h" |
20 #include "base/path_service.h" | 19 #include "base/path_service.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return false; | 129 return false; |
131 } | 130 } |
132 | 131 |
133 ScopedCarbonHandle raw_data(bitmap.getSize()); | 132 ScopedCarbonHandle raw_data(bitmap.getSize()); |
134 ConvertSkiaToARGB(bitmap, &raw_data); | 133 ConvertSkiaToARGB(bitmap, &raw_data); |
135 OSErr result = SetIconFamilyData(icon_family, icon_type, raw_data.Get()); | 134 OSErr result = SetIconFamilyData(icon_family, icon_type, raw_data.Get()); |
136 DCHECK_EQ(noErr, result); | 135 DCHECK_EQ(noErr, result); |
137 return result == noErr; | 136 return result == noErr; |
138 } | 137 } |
139 | 138 |
| 139 bool AppShimsDisabledForTest() { |
| 140 // Disable app shims in tests because shims created in ~/Applications will not |
| 141 // be cleaned up. |
| 142 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType); |
| 143 } |
| 144 |
140 base::FilePath GetWritableApplicationsDirectory() { | 145 base::FilePath GetWritableApplicationsDirectory() { |
141 base::FilePath path; | 146 base::FilePath path; |
142 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) { | 147 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) { |
143 if (!base::DirectoryExists(path)) { | 148 if (!base::DirectoryExists(path)) { |
144 if (!base::CreateDirectory(path)) | 149 if (!base::CreateDirectory(path)) |
145 return base::FilePath(); | 150 return base::FilePath(); |
146 | 151 |
147 // Create a zero-byte ".localized" file to inherit localizations from OSX | 152 // Create a zero-byte ".localized" file to inherit localizations from OSX |
148 // for folders that have special meaning. | 153 // for folders that have special meaning. |
149 base::WriteFile(path.Append(".localized"), NULL, 0); | 154 base::WriteFile(path.Append(".localized"), NULL, 0); |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 inFileViewerRootedAtPath:nil]; | 847 inFileViewerRootedAtPath:nil]; |
843 } | 848 } |
844 | 849 |
845 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) { | 850 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) { |
846 WebAppShortcutCreator shortcut_creator( | 851 WebAppShortcutCreator shortcut_creator( |
847 base::FilePath(), shortcut_info, extensions::FileHandlersInfo()); | 852 base::FilePath(), shortcut_info, extensions::FileHandlersInfo()); |
848 return shortcut_creator.GetApplicationsShortcutPath(); | 853 return shortcut_creator.GetApplicationsShortcutPath(); |
849 } | 854 } |
850 | 855 |
851 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) { | 856 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) { |
852 if (!apps::IsAppShimsEnabled()) | 857 if (AppShimsDisabledForTest()) |
853 return; | 858 return; |
854 | 859 |
855 content::BrowserThread::PostTask( | 860 content::BrowserThread::PostTask( |
856 content::BrowserThread::FILE, FROM_HERE, | 861 content::BrowserThread::FILE, FROM_HERE, |
857 base::Bind(&LaunchShimOnFileThread, shortcut_info)); | 862 base::Bind(&LaunchShimOnFileThread, shortcut_info)); |
858 } | 863 } |
859 | 864 |
860 // Called when the app's ShortcutInfo (with icon) is loaded when creating app | 865 // Called when the app's ShortcutInfo (with icon) is loaded when creating app |
861 // shortcuts. | 866 // shortcuts. |
862 void CreateAppShortcutInfoLoaded( | 867 void CreateAppShortcutInfoLoaded( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 | 917 |
913 namespace internals { | 918 namespace internals { |
914 | 919 |
915 bool CreatePlatformShortcuts( | 920 bool CreatePlatformShortcuts( |
916 const base::FilePath& app_data_path, | 921 const base::FilePath& app_data_path, |
917 const ShortcutInfo& shortcut_info, | 922 const ShortcutInfo& shortcut_info, |
918 const extensions::FileHandlersInfo& file_handlers_info, | 923 const extensions::FileHandlersInfo& file_handlers_info, |
919 const ShortcutLocations& creation_locations, | 924 const ShortcutLocations& creation_locations, |
920 ShortcutCreationReason creation_reason) { | 925 ShortcutCreationReason creation_reason) { |
921 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 926 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 927 if (AppShimsDisabledForTest()) |
| 928 return true; |
| 929 |
922 WebAppShortcutCreator shortcut_creator( | 930 WebAppShortcutCreator shortcut_creator( |
923 app_data_path, shortcut_info, file_handlers_info); | 931 app_data_path, shortcut_info, file_handlers_info); |
924 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); | 932 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); |
925 } | 933 } |
926 | 934 |
927 void DeletePlatformShortcuts(const base::FilePath& app_data_path, | 935 void DeletePlatformShortcuts(const base::FilePath& app_data_path, |
928 const ShortcutInfo& shortcut_info) { | 936 const ShortcutInfo& shortcut_info) { |
929 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 937 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
930 WebAppShortcutCreator shortcut_creator( | 938 WebAppShortcutCreator shortcut_creator( |
931 app_data_path, shortcut_info, extensions::FileHandlersInfo()); | 939 app_data_path, shortcut_info, extensions::FileHandlersInfo()); |
932 shortcut_creator.DeleteShortcuts(); | 940 shortcut_creator.DeleteShortcuts(); |
933 } | 941 } |
934 | 942 |
935 void UpdatePlatformShortcuts( | 943 void UpdatePlatformShortcuts( |
936 const base::FilePath& app_data_path, | 944 const base::FilePath& app_data_path, |
937 const base::string16& old_app_title, | 945 const base::string16& old_app_title, |
938 const ShortcutInfo& shortcut_info, | 946 const ShortcutInfo& shortcut_info, |
939 const extensions::FileHandlersInfo& file_handlers_info) { | 947 const extensions::FileHandlersInfo& file_handlers_info) { |
940 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 948 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 949 if (AppShimsDisabledForTest()) |
| 950 return; |
| 951 |
941 WebAppShortcutCreator shortcut_creator( | 952 WebAppShortcutCreator shortcut_creator( |
942 app_data_path, shortcut_info, file_handlers_info); | 953 app_data_path, shortcut_info, file_handlers_info); |
943 shortcut_creator.UpdateShortcuts(); | 954 shortcut_creator.UpdateShortcuts(); |
944 } | 955 } |
945 | 956 |
946 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { | 957 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { |
947 const std::string profile_base_name = profile_path.BaseName().value(); | 958 const std::string profile_base_name = profile_path.BaseName().value(); |
948 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( | 959 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( |
949 profile_path.Append(chrome::kWebAppDirname), profile_base_name); | 960 profile_path.Append(chrome::kWebAppDirname), profile_base_name); |
950 | 961 |
(...skipping 21 matching lines...) Expand all Loading... |
972 web_app::UpdateShortcutInfoAndIconForApp( | 983 web_app::UpdateShortcutInfoAndIconForApp( |
973 app, | 984 app, |
974 profile, | 985 profile, |
975 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 986 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
976 profile, | 987 profile, |
977 app, | 988 app, |
978 close_callback)); | 989 close_callback)); |
979 } | 990 } |
980 | 991 |
981 } // namespace chrome | 992 } // namespace chrome |
OLD | NEW |