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 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
40 #import "skia/ext/skia_utils_mac.h" | 45 #import "skia/ext/skia_utils_mac.h" |
41 #include "third_party/skia/include/core/SkBitmap.h" | 46 #include "third_party/skia/include/core/SkBitmap.h" |
42 #include "third_party/skia/include/core/SkColor.h" | 47 #include "third_party/skia/include/core/SkColor.h" |
43 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
44 #import "ui/base/l10n/l10n_util_mac.h" | 49 #import "ui/base/l10n/l10n_util_mac.h" |
45 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // Launch without activating (kLSLaunchDontSwitch). | 234 // Launch without activating (kLSLaunchDontSwitch). |
230 base::mac::OpenApplicationWithPath( | 235 base::mac::OpenApplicationWithPath( |
231 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL); | 236 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL); |
232 } | 237 } |
233 | 238 |
234 base::FilePath GetAppLoaderPath() { | 239 base::FilePath GetAppLoaderPath() { |
235 return base::mac::PathForFrameworkBundleResource( | 240 return base::mac::PathForFrameworkBundleResource( |
236 base::mac::NSToCFCast(@"app_mode_loader.app")); | 241 base::mac::NSToCFCast(@"app_mode_loader.app")); |
237 } | 242 } |
238 | 243 |
| 244 void UpdateAndLaunchShimOnFileThread( |
| 245 const web_app::ShortcutInfo& shortcut_info, |
| 246 const extensions::FileHandlersInfo& file_handlers_info) { |
| 247 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( |
| 248 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); |
| 249 web_app::internals::UpdatePlatformShortcuts( |
| 250 shortcut_data_dir, base::string16(), shortcut_info, file_handlers_info); |
| 251 LaunchShimOnFileThread(shortcut_info); |
| 252 } |
| 253 |
| 254 void UpdateAndLaunchShim( |
| 255 const web_app::ShortcutInfo& shortcut_info, |
| 256 const extensions::FileHandlersInfo& file_handlers_info) { |
| 257 content::BrowserThread::PostTask( |
| 258 content::BrowserThread::FILE, FROM_HERE, |
| 259 base::Bind( |
| 260 &UpdateAndLaunchShimOnFileThread, shortcut_info, file_handlers_info)); |
| 261 } |
| 262 |
| 263 void RebuildAppAndLaunch(const web_app::ShortcutInfo& shortcut_info) { |
| 264 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 265 if (shortcut_info.extension_id == app_mode::kAppListModeId) { |
| 266 AppListService* app_list_service = |
| 267 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 268 app_list_service->CreateShortcut(); |
| 269 app_list_service->Show(); |
| 270 return; |
| 271 } |
| 272 |
| 273 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 274 Profile* profile = profile_manager->GetProfileByPath( |
| 275 shortcut_info.profile_path); |
| 276 if (!profile || !profile_manager->IsValidProfile(profile)) |
| 277 return; |
| 278 |
| 279 extensions::ExtensionRegistry* registry = |
| 280 extensions::ExtensionRegistry::Get(profile); |
| 281 const extensions::Extension* extension = |
| 282 registry->GetExtensionById(shortcut_info.extension_id, |
| 283 extensions::ExtensionRegistry::ENABLED); |
| 284 if (!extension || !extension->is_platform_app()) |
| 285 return; |
| 286 |
| 287 web_app::internals::GetInfoForApp( |
| 288 extension, profile, base::Bind(&UpdateAndLaunchShim)); |
| 289 } |
| 290 |
239 base::FilePath GetLocalizableAppShortcutsSubdirName() { | 291 base::FilePath GetLocalizableAppShortcutsSubdirName() { |
240 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; | 292 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; |
241 static const char kChromeAppDirName[] = "Chrome Apps.localized"; | 293 static const char kChromeAppDirName[] = "Chrome Apps.localized"; |
242 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; | 294 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; |
243 | 295 |
244 switch (chrome::VersionInfo::GetChannel()) { | 296 switch (chrome::VersionInfo::GetChannel()) { |
245 case chrome::VersionInfo::CHANNEL_UNKNOWN: | 297 case chrome::VersionInfo::CHANNEL_UNKNOWN: |
246 return base::FilePath(kChromiumAppDirName); | 298 return base::FilePath(kChromiumAppDirName); |
247 | 299 |
248 case chrome::VersionInfo::CHANNEL_CANARY: | 300 case chrome::VersionInfo::CHANNEL_CANARY: |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 | 890 |
839 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) { | 891 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) { |
840 if (!apps::IsAppShimsEnabled()) | 892 if (!apps::IsAppShimsEnabled()) |
841 return; | 893 return; |
842 | 894 |
843 content::BrowserThread::PostTask( | 895 content::BrowserThread::PostTask( |
844 content::BrowserThread::FILE, FROM_HERE, | 896 content::BrowserThread::FILE, FROM_HERE, |
845 base::Bind(&LaunchShimOnFileThread, shortcut_info)); | 897 base::Bind(&LaunchShimOnFileThread, shortcut_info)); |
846 } | 898 } |
847 | 899 |
| 900 bool MaybeRebuildShortcut(const CommandLine& command_line) { |
| 901 if (!command_line.HasSwitch(app_mode::kAppShimError)) |
| 902 return false; |
| 903 |
| 904 base::PostTaskAndReplyWithResult( |
| 905 content::BrowserThread::GetBlockingPool(), |
| 906 FROM_HERE, |
| 907 base::Bind(&BuildShortcutInfoFromBundle, |
| 908 command_line.GetSwitchValuePath(app_mode::kAppShimError)), |
| 909 base::Bind(&RebuildAppAndLaunch)); |
| 910 return true; |
| 911 } |
| 912 |
848 // Called when the app's ShortcutInfo (with icon) is loaded when creating app | 913 // Called when the app's ShortcutInfo (with icon) is loaded when creating app |
849 // shortcuts. | 914 // shortcuts. |
850 void CreateAppShortcutInfoLoaded( | 915 void CreateAppShortcutInfoLoaded( |
851 Profile* profile, | 916 Profile* profile, |
852 const extensions::Extension* app, | 917 const extensions::Extension* app, |
853 const base::Callback<void(bool)>& close_callback, | 918 const base::Callback<void(bool)>& close_callback, |
854 const web_app::ShortcutInfo& shortcut_info) { | 919 const web_app::ShortcutInfo& shortcut_info) { |
855 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 920 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
856 | 921 |
857 NSButton* continue_button = [alert | 922 NSButton* continue_button = [alert |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 web_app::UpdateShortcutInfoAndIconForApp( | 1028 web_app::UpdateShortcutInfoAndIconForApp( |
964 app, | 1029 app, |
965 profile, | 1030 profile, |
966 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1031 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
967 profile, | 1032 profile, |
968 app, | 1033 app, |
969 close_callback)); | 1034 close_callback)); |
970 } | 1035 } |
971 | 1036 |
972 } // namespace chrome | 1037 } // namespace chrome |
OLD | NEW |