Chromium Code Reviews| Index: chrome/browser/web_applications/web_app_mac.mm |
| diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm |
| index d2c7d4928242b2660f64acdceb2ea78ed50dee2d..020b9ef875546d52e21c718e541f7e507112a894 100644 |
| --- a/chrome/browser/web_applications/web_app_mac.mm |
| +++ b/chrome/browser/web_applications/web_app_mac.mm |
| @@ -21,18 +21,23 @@ |
| #include "base/process/process_handle.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/browser_process.h" |
| #import "chrome/browser/mac/dock.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/shell_integration.h" |
| +#include "chrome/browser/ui/app_list/app_list_service.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/chrome_version_info.h" |
| #import "chrome/common/mac/app_mode_common.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "extensions/browser/extension_registry.h" |
| #include "extensions/common/extension.h" |
| #include "grit/chrome_unscaled_resources.h" |
| #include "grit/chromium_strings.h" |
| @@ -235,6 +240,25 @@ base::FilePath GetAppLoaderPath() { |
| base::mac::NSToCFCast(@"app_mode_loader.app")); |
| } |
| +void UpdateAndLaunchShimOnFileThread( |
| + const web_app::ShortcutInfo& shortcut_info, |
| + const extensions::FileHandlersInfo& file_handlers_info) { |
| + base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( |
| + shortcut_info.profile_path, shortcut_info.extension_id, GURL()); |
| + web_app::internals::UpdatePlatformShortcuts( |
| + shortcut_data_dir, base::string16(), shortcut_info, file_handlers_info); |
| + LaunchShimOnFileThread(shortcut_info); |
| +} |
| + |
| +void UpdateAndLaunchShim( |
| + const web_app::ShortcutInfo& shortcut_info, |
| + const extensions::FileHandlersInfo& file_handlers_info) { |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::FILE, FROM_HERE, |
| + base::Bind( |
| + &UpdateAndLaunchShimOnFileThread, shortcut_info, file_handlers_info)); |
| +} |
| + |
| base::FilePath GetLocalizableAppShortcutsSubdirName() { |
| static const char kChromiumAppDirName[] = "Chromium Apps.localized"; |
| static const char kChromeAppDirName[] = "Chrome Apps.localized"; |
| @@ -862,6 +886,48 @@ void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) { |
| base::Bind(&LaunchShimOnFileThread, shortcut_info)); |
| } |
| +bool MaybeRebuildShortcut(const CommandLine& command_line) { |
| + if (!command_line.HasSwitch(app_mode::kAppShimError)) |
| + return false; |
| + |
| + std::string bundle_base_name = |
| + command_line.GetSwitchValuePath(app_mode::kAppShimError) |
| + .BaseName().RemoveExtension().value(); |
| + 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
|
| + if (bundle_base_name == app_mode::kAppListModeId) { |
| + AppListService* app_list_service = |
| + AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); |
| + app_list_service->CreateShortcut(); |
| + app_list_service->Show(); |
| + } |
| + return true; |
| + } |
| + |
| + std::vector<std::string> parts; |
| + base::SplitString(bundle_base_name, ' ', &parts); |
| + 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.
|
| + parts.pop_back(); |
| + base::FilePath profile_path(JoinString(parts, ' ')); |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + Profile* profile = profile_manager->GetProfileByPath( |
| + profile_manager->user_data_dir().Append(profile_path)); |
| + if (!profile || !profile_manager->IsValidProfile(profile)) |
| + return true; |
| + |
| + extensions::ExtensionRegistry* registry = |
| + extensions::ExtensionRegistry::Get(profile); |
| + const extensions::Extension* extension = |
| + registry->GetExtensionById(app_id, |
| + extensions::ExtensionRegistry::ENABLED); |
| + if (!extension || !extension->is_platform_app()) |
| + return true; |
| + |
| + web_app::internals::GetInfoForApp( |
| + extension, profile, base::Bind(&UpdateAndLaunchShim)); |
| + return true; |
| +} |
| + |
| namespace internals { |
| bool CreatePlatformShortcuts( |