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 <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" | 10 #include "apps/app_shim/app_shim_mac.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/mac/foundation_util.h" | 15 #include "base/mac/foundation_util.h" |
| 16 #include "base/mac/launch_services_util.h" | 16 #include "base/mac/launch_services_util.h" |
| 17 #include "base/mac/mac_util.h" | 17 #include "base/mac/mac_util.h" |
| 18 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
| 19 #include "base/mac/scoped_nsobject.h" | 19 #include "base/mac/scoped_nsobject.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/process/process_handle.h" | 21 #include "base/process/process_handle.h" |
| 22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_split.h" | |
| 24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 26 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 28 #include "chrome/browser/browser_process.h" | |
| 27 #import "chrome/browser/mac/dock.h" | 29 #import "chrome/browser/mac/dock.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/profiles/profile_manager.h" | |
| 29 #include "chrome/browser/shell_integration.h" | 32 #include "chrome/browser/shell_integration.h" |
| 33 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 30 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
| 34 #import "chrome/common/mac/app_mode_common.h" | 38 #import "chrome/common/mac/app_mode_common.h" |
| 35 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 40 #include "extensions/browser/extension_registry.h" | |
| 36 #include "extensions/common/extension.h" | 41 #include "extensions/common/extension.h" |
| 37 #include "grit/chrome_unscaled_resources.h" | 42 #include "grit/chrome_unscaled_resources.h" |
| 38 #include "grit/chromium_strings.h" | 43 #include "grit/chromium_strings.h" |
| 39 #import "skia/ext/skia_utils_mac.h" | 44 #import "skia/ext/skia_utils_mac.h" |
| 40 #include "third_party/skia/include/core/SkBitmap.h" | 45 #include "third_party/skia/include/core/SkBitmap.h" |
| 41 #include "third_party/skia/include/core/SkColor.h" | 46 #include "third_party/skia/include/core/SkColor.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 43 #import "ui/base/l10n/l10n_util_mac.h" | 48 #import "ui/base/l10n/l10n_util_mac.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "ui/gfx/image/image_family.h" | 50 #include "ui/gfx/image/image_family.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 // Launch without activating (kLSLaunchDontSwitch). | 233 // Launch without activating (kLSLaunchDontSwitch). |
| 229 base::mac::OpenApplicationWithPath( | 234 base::mac::OpenApplicationWithPath( |
| 230 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL); | 235 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL); |
| 231 } | 236 } |
| 232 | 237 |
| 233 base::FilePath GetAppLoaderPath() { | 238 base::FilePath GetAppLoaderPath() { |
| 234 return base::mac::PathForFrameworkBundleResource( | 239 return base::mac::PathForFrameworkBundleResource( |
| 235 base::mac::NSToCFCast(@"app_mode_loader.app")); | 240 base::mac::NSToCFCast(@"app_mode_loader.app")); |
| 236 } | 241 } |
| 237 | 242 |
| 243 void UpdateAndLaunchShimOnFileThread( | |
| 244 const web_app::ShortcutInfo& shortcut_info, | |
| 245 const extensions::FileHandlersInfo& file_handlers_info) { | |
| 246 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | |
| 247 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | |
| 248 web_app::internals::UpdatePlatformShortcuts( | |
| 249 shortcut_data_dir, base::string16(), shortcut_info, file_handlers_info); | |
| 250 LaunchShimOnFileThread(shortcut_info); | |
| 251 } | |
| 252 | |
| 253 void UpdateAndLaunchShim( | |
| 254 const web_app::ShortcutInfo& shortcut_info, | |
| 255 const extensions::FileHandlersInfo& file_handlers_info) { | |
| 256 content::BrowserThread::PostTask( | |
| 257 content::BrowserThread::FILE, FROM_HERE, | |
| 258 base::Bind( | |
| 259 &UpdateAndLaunchShimOnFileThread, shortcut_info, file_handlers_info)); | |
| 260 } | |
| 261 | |
| 238 base::FilePath GetLocalizableAppShortcutsSubdirName() { | 262 base::FilePath GetLocalizableAppShortcutsSubdirName() { |
| 239 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; | 263 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; |
| 240 static const char kChromeAppDirName[] = "Chrome Apps.localized"; | 264 static const char kChromeAppDirName[] = "Chrome Apps.localized"; |
| 241 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; | 265 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; |
| 242 | 266 |
| 243 switch (chrome::VersionInfo::GetChannel()) { | 267 switch (chrome::VersionInfo::GetChannel()) { |
| 244 case chrome::VersionInfo::CHANNEL_UNKNOWN: | 268 case chrome::VersionInfo::CHANNEL_UNKNOWN: |
| 245 return base::FilePath(kChromiumAppDirName); | 269 return base::FilePath(kChromiumAppDirName); |
| 246 | 270 |
| 247 case chrome::VersionInfo::CHANNEL_CANARY: | 271 case chrome::VersionInfo::CHANNEL_CANARY: |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 | 879 |
| 856 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) { | 880 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) { |
| 857 if (!apps::IsAppShimsEnabled()) | 881 if (!apps::IsAppShimsEnabled()) |
| 858 return; | 882 return; |
| 859 | 883 |
| 860 content::BrowserThread::PostTask( | 884 content::BrowserThread::PostTask( |
| 861 content::BrowserThread::FILE, FROM_HERE, | 885 content::BrowserThread::FILE, FROM_HERE, |
| 862 base::Bind(&LaunchShimOnFileThread, shortcut_info)); | 886 base::Bind(&LaunchShimOnFileThread, shortcut_info)); |
| 863 } | 887 } |
| 864 | 888 |
| 889 bool MaybeRebuildShortcut(const CommandLine& command_line) { | |
| 890 if (!command_line.HasSwitch(app_mode::kAppShimError)) | |
| 891 return false; | |
| 892 | |
| 893 std::string bundle_base_name = | |
| 894 command_line.GetSwitchValuePath(app_mode::kAppShimError) | |
| 895 .BaseName().RemoveExtension().value(); | |
| 896 if (bundle_base_name.length() < 40) { | |
|
tapted
2014/05/05 07:02:01
40 -> constant?
But all the returns below here `r
jackhou1
2014/05/06 04:47:58
Done.
Good idea. It still needs to get the Profil
| |
| 897 if (bundle_base_name == app_mode::kAppListModeId) { | |
| 898 AppListService* app_list_service = | |
| 899 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 900 app_list_service->CreateShortcut(); | |
| 901 app_list_service->Show(); | |
| 902 } | |
| 903 return true; | |
| 904 } | |
| 905 | |
| 906 std::vector<std::string> parts; | |
| 907 base::SplitString(bundle_base_name, ' ', &parts); | |
| 908 std::string app_id = parts.back(); | |
|
tapted
2014/05/05 07:02:01
hypothetically.... will this crash if bundle_base_
jackhou1
2014/05/06 04:47:58
Removed.
| |
| 909 parts.pop_back(); | |
| 910 base::FilePath profile_path(JoinString(parts, ' ')); | |
| 911 | |
| 912 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 913 Profile* profile = profile_manager->GetProfileByPath( | |
| 914 profile_manager->user_data_dir().Append(profile_path)); | |
| 915 if (!profile || !profile_manager->IsValidProfile(profile)) | |
| 916 return true; | |
| 917 | |
| 918 extensions::ExtensionRegistry* registry = | |
| 919 extensions::ExtensionRegistry::Get(profile); | |
| 920 const extensions::Extension* extension = | |
| 921 registry->GetExtensionById(app_id, | |
| 922 extensions::ExtensionRegistry::ENABLED); | |
| 923 if (!extension || !extension->is_platform_app()) | |
| 924 return true; | |
| 925 | |
| 926 web_app::internals::GetInfoForApp( | |
| 927 extension, profile, base::Bind(&UpdateAndLaunchShim)); | |
| 928 return true; | |
| 929 } | |
| 930 | |
| 865 namespace internals { | 931 namespace internals { |
| 866 | 932 |
| 867 bool CreatePlatformShortcuts( | 933 bool CreatePlatformShortcuts( |
| 868 const base::FilePath& app_data_path, | 934 const base::FilePath& app_data_path, |
| 869 const web_app::ShortcutInfo& shortcut_info, | 935 const web_app::ShortcutInfo& shortcut_info, |
| 870 const extensions::FileHandlersInfo& file_handlers_info, | 936 const extensions::FileHandlersInfo& file_handlers_info, |
| 871 const web_app::ShortcutLocations& creation_locations, | 937 const web_app::ShortcutLocations& creation_locations, |
| 872 ShortcutCreationReason creation_reason) { | 938 ShortcutCreationReason creation_reason) { |
| 873 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 939 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 874 WebAppShortcutCreator shortcut_creator( | 940 WebAppShortcutCreator shortcut_creator( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 BuildShortcutInfoFromBundle(*it); | 973 BuildShortcutInfoFromBundle(*it); |
| 908 WebAppShortcutCreator shortcut_creator( | 974 WebAppShortcutCreator shortcut_creator( |
| 909 it->DirName(), shortcut_info, extensions::FileHandlersInfo()); | 975 it->DirName(), shortcut_info, extensions::FileHandlersInfo()); |
| 910 shortcut_creator.DeleteShortcuts(); | 976 shortcut_creator.DeleteShortcuts(); |
| 911 } | 977 } |
| 912 } | 978 } |
| 913 | 979 |
| 914 } // namespace internals | 980 } // namespace internals |
| 915 | 981 |
| 916 } // namespace web_app | 982 } // namespace web_app |
| OLD | NEW |