diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-21 08:27:07 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-21 08:27:07 +0000 |
commit | 5538b3125381def519b5032f6c90506652cb2deb (patch) | |
tree | d7f71e9a1397caace552fc88801e2ea72aab6966 /chrome | |
parent | 9e89596c43138cd0061af8a8b0f0bccaf2c5bdfe (diff) | |
download | chromium_src-5538b3125381def519b5032f6c90506652cb2deb.zip chromium_src-5538b3125381def519b5032f6c90506652cb2deb.tar.gz chromium_src-5538b3125381def519b5032f6c90506652cb2deb.tar.bz2 |
Create an app list shim for the App Launcher on OSX in response to a startup flag.
This allows an app launcher .app shim to be created on OSX with steps:
- Quit Chrome, and
- $ open Chromium.app --args --enable-app-list-shim
Chrome will start, and a finder window will be opened showing the newly
created .app. This can then be launched and pinned to the dock.
The .app can be deleted with --enable-app-list-shim=0 (or it can be
dragged to Trash).
BUG=138633
TEST=Steps as above.
Review URL: https://chromiumcodereview.appspot.com/14760002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201260 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/theme/chrome_unscaled_resources.grd | 7 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/app_list/app_list_service_mac.mm | 85 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.h | 8 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.mm | 17 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac_unittest.mm | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 6 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
8 files changed, 127 insertions, 0 deletions
diff --git a/chrome/app/theme/chrome_unscaled_resources.grd b/chrome/app/theme/chrome_unscaled_resources.grd index bb7f999..affd632 100644 --- a/chrome/app/theme/chrome_unscaled_resources.grd +++ b/chrome/app/theme/chrome_unscaled_resources.grd @@ -79,6 +79,13 @@ <include name="IDR_PROFILE_AVATAR_2X_24" file="default_200_percent/profile_avatar_note.png" type="BINDATA" /> <include name="IDR_PROFILE_AVATAR_2X_25" file="default_200_percent/profile_avatar_sun_cloud.png" type="BINDATA" /> </if> + <if expr="is_macosx and pp_ifdef('enable_app_list')"> + <!-- App Launcher icons for .app shim, dock icon. Unscaled, and chromium + only, until the resource loader is updated to support multiple icon + scales, and shortcut creation properly handles smaller icon sizes. + See http://crbug.com/167408 and http://crbug.com/241304 --> + <include name="IDR_APP_LIST_128" file="chromium/app_list_128.png" type="BINDATA" /> + </if> </includes> </release> </grit> diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 07d50a7..da667f0 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -117,6 +117,7 @@ #if defined(OS_MACOSX) #include "apps/app_shim/app_shim_host_manager_mac.h" +#include "chrome/browser/ui/app_list/app_list_service.h" #endif #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) @@ -901,6 +902,7 @@ void BrowserProcessImpl::PreMainMessageLoopRun() { #if defined(OS_MACOSX) app_shim_host_manager_.reset(new AppShimHostManager); + AppListService::InitAll(NULL); #endif } diff --git a/chrome/browser/ui/app_list/app_list_service_mac.mm b/chrome/browser/ui/app_list/app_list_service_mac.mm index 258058d..3a45759 100644 --- a/chrome/browser/ui/app_list/app_list_service_mac.mm +++ b/chrome/browser/ui/app_list/app_list_service_mac.mm @@ -4,6 +4,8 @@ #include "apps/app_shim/app_shim_handler_mac.h" #include "base/bind.h" +#include "base/command_line.h" +#include "base/file_util.h" #include "base/lazy_instance.h" #include "base/memory/scoped_nsobject.h" #include "base/memory/singleton.h" @@ -14,9 +16,18 @@ #include "chrome/browser/ui/app_list/app_list_service_impl.h" #include "chrome/browser/ui/app_list/app_list_view_delegate.h" #include "chrome/browser/ui/extensions/application_launch.h" +#include "chrome/browser/web_applications/web_app.h" +#include "chrome/browser/web_applications/web_app_mac.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/chrome_version_info.h" #include "chrome/common/mac/app_mode_common.h" +#include "content/public/browser/browser_thread.h" +#include "grit/chrome_unscaled_resources.h" +#include "grit/google_chrome_strings.h" #import "ui/app_list/cocoa/app_list_view_controller.h" #import "ui/app_list/cocoa/app_list_window_controller.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" #include "ui/gfx/display.h" #include "ui/gfx/screen.h" @@ -90,6 +101,64 @@ class AppListControllerDelegateCocoa : public AppListControllerDelegate { DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateCocoa); }; +ShellIntegration::ShortcutInfo GetAppListShortcutInfo( + const base::FilePath& profile_path) { + ShellIntegration::ShortcutInfo shortcut_info; + chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); + if (channel == chrome::VersionInfo::CHANNEL_CANARY) { + shortcut_info.title = + l10n_util::GetStringUTF16(IDS_APP_LIST_SHORTCUT_NAME_CANARY); + } else { + shortcut_info.title = l10n_util::GetStringUTF16(IDS_APP_LIST_SHORTCUT_NAME); + } + + shortcut_info.extension_id = app_mode::kAppListModeId; + shortcut_info.description = shortcut_info.title; + shortcut_info.profile_path = profile_path; + + return shortcut_info; +} + +void CreateAppListShim(const base::FilePath& profile_path) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + WebApplicationInfo web_app_info; + ShellIntegration::ShortcutInfo shortcut_info = + GetAppListShortcutInfo(profile_path); + + ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); + // TODO(tapted): Add more icon scales when the resource bundle will use them + // properly. See http://crbug.com/167408 and http://crbug.com/241304 . + shortcut_info.favicon.Add( + *resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_128)); + + // TODO(tapted): Create a dock icon using chrome/browser/mac/dock.h . + web_app::CreateShortcuts(shortcut_info, + ShellIntegration::ShortcutLocations()); +} + +// Check that there is an app list shim. If enabling and there is not, make one. +// If disabling with --enable-app-list-shim=0, and there is one, delete it. +void CheckAppListShimOnFileThread(const base::FilePath& profile_path) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); + const bool enable = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kEnableAppListShim).c_str()[0] != '0'; + base::FilePath install_path = web_app::GetAppInstallPath( + GetAppListShortcutInfo(profile_path)); + if (enable == file_util::PathExists(install_path)) + return; + + if (enable) { + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&CreateAppListShim, profile_path)); + return; + } + + // Sanity check because deleting things recursively is scary. + CHECK(install_path.MatchesExtension(".app")); + file_util::Delete(install_path, true /* recursive */); +} + AppListControllerDelegateCocoa::AppListControllerDelegateCocoa() {} AppListControllerDelegateCocoa::~AppListControllerDelegateCocoa() {} @@ -139,6 +208,22 @@ void AppListServiceMac::CreateAppList(Profile* requested_profile) { } void AppListServiceMac::Init(Profile* initial_profile) { + // On Mac, Init() is called multiple times for a process: any time there is no + // browser window open and a new window is opened, and during process startup + // to handle the silent launch case (e.g. for app shims). In the startup case, + // a profile has not yet been determined so |initial_profile| will be NULL. + if (initial_profile) { + static bool checked_shim = false; + if (!checked_shim && CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableAppListShim)) { + checked_shim = true; + content::BrowserThread::PostTask( + content::BrowserThread::FILE, FROM_HERE, + base::Bind(&CheckAppListShimOnFileThread, + initial_profile->GetPath())); + } + } + static bool init_called = false; if (init_called) return; diff --git a/chrome/browser/web_applications/web_app_mac.h b/chrome/browser/web_applications/web_app_mac.h index 8f9b90c..236fe95 100644 --- a/chrome/browser/web_applications/web_app_mac.h +++ b/chrome/browser/web_applications/web_app_mac.h @@ -20,6 +20,11 @@ class NSString; namespace web_app { +// Returns the full path of the .app shim that would be created by +// web_app::CreateShortcuts(). +base::FilePath GetAppInstallPath( + const ShellIntegration::ShortcutInfo& shortcut_info); + // Creates a shortcut for a web application. The shortcut is a stub app // that simply loads the browser framework and runs the given app. class WebAppShortcutCreator { @@ -34,6 +39,9 @@ class WebAppShortcutCreator { virtual ~WebAppShortcutCreator(); + // Returns a path to the destination where the app should be written to. + base::FilePath GetShortcutPath() const; + // Copies the app launcher template into place and fills in all relevant // information. bool CreateShortcut(); diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index 6da9795..5c933cd 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -115,6 +115,15 @@ WebAppShortcutCreator::WebAppShortcutCreator( WebAppShortcutCreator::~WebAppShortcutCreator() { } +base::FilePath WebAppShortcutCreator::GetShortcutPath() const { + base::FilePath dst_path = GetDestinationPath(); + if (dst_path.empty()) + return dst_path; + + base::FilePath app_name = internals::GetSanitizedFileName(info_.title); + return dst_path.Append(app_name.ReplaceExtension("app")); +} + bool WebAppShortcutCreator::CreateShortcut() { base::FilePath app_name = internals::GetSanitizedFileName(info_.title); base::FilePath app_file_name = app_name.ReplaceExtension("app"); @@ -283,6 +292,14 @@ void WebAppShortcutCreator::RevealGeneratedBundleInFinder( namespace web_app { +base::FilePath GetAppInstallPath( + const ShellIntegration::ShortcutInfo& shortcut_info) { + WebAppShortcutCreator shortcut_creator(base::FilePath(), + shortcut_info, + string16()); + return shortcut_creator.GetShortcutPath(); +} + namespace internals { base::FilePath GetAppBundleByExtensionId(std::string extension_id) { diff --git a/chrome/browser/web_applications/web_app_mac_unittest.mm b/chrome/browser/web_applications/web_app_mac_unittest.mm index 2579cb36..0c08366 100644 --- a/chrome/browser/web_applications/web_app_mac_unittest.mm +++ b/chrome/browser/web_applications/web_app_mac_unittest.mm @@ -73,6 +73,7 @@ TEST(WebAppShortcutCreatorTest, CreateShortcut) { EXPECT_TRUE(shortcut_creator.CreateShortcut()); EXPECT_TRUE(file_util::PathExists(dst_path)); + EXPECT_EQ(dst_path.value(), shortcut_creator.GetShortcutPath().value()); base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 9774636..1fe2ff4 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1520,6 +1520,12 @@ const char kPasswordStore[] = "password-store"; #endif // OS_POSIX #if defined(OS_MACOSX) +// Enables the app list OSX .app shim, for showing the app list. Takes an +// optional argument: --enable-app-list-shim=0 will delete a previously created +// .app folder for the app list shim. Any other argument, or no argument, will +// create it. +extern const char kEnableAppListShim[] = "enable-app-list-shim"; + // Enables the tabs expose feature ( http://crbug.com/50307 ). const char kEnableExposeForTabs[] = "enable-expose-for-tabs"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index e48121d..ab37a15 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -421,6 +421,7 @@ extern const char kPasswordStore[]; #endif #if defined(OS_MACOSX) +extern const char kEnableAppListShim[]; extern const char kEnableExposeForTabs[]; extern const char kKeychainReauthorize[]; extern const char kRelauncherProcess[]; |