| Index: chrome/browser/ui/app_list/app_list_service_mac.mm
|
| 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 583fc54f704ccccad2464e93d1fb1638fad73009..92d923785a74ea5f8eccbeff8294644e4574e7c3 100644
|
| --- a/chrome/browser/ui/app_list/app_list_service_mac.mm
|
| +++ b/chrome/browser/ui/app_list/app_list_service_mac.mm
|
| @@ -4,18 +4,38 @@
|
|
|
| #include "chrome/browser/ui/app_list/app_list_service_mac.h"
|
|
|
| +#include "apps/app_launcher.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"
|
| #include "base/message_loop.h"
|
| +#include "base/observer_list.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/shell_integration.h"
|
| +#include "chrome/browser/ui/app_list/app_list_dismiss_observer_mac.h"
|
| #include "chrome/browser/ui/app_list/app_list_service_impl.h"
|
| #include "chrome/browser/ui/app_list/app_list_service_mac.h"
|
| #include "chrome/browser/ui/app_list/app_list_controller_delegate.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/common/chrome_switches.h"
|
| +#include "chrome/common/chrome_version_info.h"
|
| +#include "chrome/common/mac/app_mode_common.h"
|
| +#include "chrome/common/url_constants.h"
|
| +#include "chrome/common/web_apps.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"
|
|
|
| namespace gfx {
|
| class ImageSkia;
|
| @@ -37,7 +57,11 @@ class AppListServiceMac : public AppListServiceImpl {
|
| void CreateAppList(Profile* profile);
|
| NSWindow* GetNativeWindow();
|
|
|
| + void AddObserver(chrome::AppListDismissObserverMac* observer);
|
| + void RemoveObserver(chrome::AppListDismissObserverMac* observer);
|
| +
|
| // AppListService overrides:
|
| + virtual void Init(Profile* initial_profile) OVERRIDE;
|
| virtual void ShowAppList(Profile* requested_profile) OVERRIDE;
|
| virtual void DismissAppList() OVERRIDE;
|
| virtual bool IsAppListVisible() const OVERRIDE;
|
| @@ -48,6 +72,7 @@ class AppListServiceMac : public AppListServiceImpl {
|
| AppListServiceMac() {}
|
|
|
| scoped_nsobject<AppListWindowController> window_controller_;
|
| + ObserverList<chrome::AppListDismissObserverMac> observers_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(AppListServiceMac);
|
| };
|
| @@ -73,6 +98,59 @@ 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.url = GURL(chrome::kChromeUIAppsURL);
|
| + 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 sizes when CreateShortcuts for mac will
|
| + // actually make use of them.
|
| + 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 not, make one.
|
| +void CheckAppListShimOnFileThread(const base::FilePath& profile_path) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
|
| + base::FilePath install_path = web_app::internals::GetAppInstallPath(
|
| + GetAppListShortcutInfo(profile_path));
|
| + DLOG(INFO) << install_path.value();
|
| + if (file_util::PathExists(install_path))
|
| + return;
|
| +
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&CreateAppListShim, profile_path));
|
| +}
|
| +
|
| AppListControllerDelegateCocoa::AppListControllerDelegateCocoa() {}
|
|
|
| AppListControllerDelegateCocoa::~AppListControllerDelegateCocoa() {}
|
| @@ -116,6 +194,23 @@ void AppListServiceMac::CreateAppList(Profile* requested_profile) {
|
| [[window_controller_ appListViewController] setDelegate:delegate.Pass()];
|
| }
|
|
|
| +void AppListServiceMac::Init(Profile* initial_profile) {
|
| + static bool checked_shim = false;
|
| + if (checked_shim)
|
| + return;
|
| +
|
| + checked_shim = true;
|
| + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList))
|
| + return;
|
| +
|
| + // Delay, so that startup is not impacted.
|
| + const int kCreateShimDelay = 5;
|
| + content::BrowserThread::PostDelayedTask(
|
| + content::BrowserThread::FILE, FROM_HERE,
|
| + base::Bind(&CheckAppListShimOnFileThread, initial_profile->GetPath()),
|
| + base::TimeDelta::FromSeconds(kCreateShimDelay));
|
| +}
|
| +
|
| void AppListServiceMac::ShowAppList(Profile* requested_profile) {
|
| InvalidatePendingProfileLoads();
|
|
|
| @@ -137,10 +232,14 @@ void AppListServiceMac::ShowAppList(Profile* requested_profile) {
|
| }
|
|
|
| void AppListServiceMac::DismissAppList() {
|
| - if (!window_controller_)
|
| + if (!IsAppListVisible())
|
| return;
|
|
|
| [[window_controller_ window] close];
|
| +
|
| + FOR_EACH_OBSERVER(chrome::AppListDismissObserverMac,
|
| + observers_,
|
| + OnAppListDismissed());
|
| }
|
|
|
| bool AppListServiceMac::IsAppListVisible() const {
|
| @@ -151,6 +250,16 @@ NSWindow* AppListServiceMac::GetNativeWindow() {
|
| return [window_controller_ window];
|
| }
|
|
|
| +void AppListServiceMac::AddObserver(
|
| + chrome::AppListDismissObserverMac* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void AppListServiceMac::RemoveObserver(
|
| + chrome::AppListDismissObserverMac* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace chrome {
|
| @@ -159,4 +268,12 @@ AppListService* GetAppListServiceMac() {
|
| return AppListServiceMac::GetInstance();
|
| }
|
|
|
| +void AddAppListDismissObserver(AppListDismissObserverMac* observer) {
|
| + AppListServiceMac::GetInstance()->AddObserver(observer);
|
| +}
|
| +
|
| +void RemoveAppListDismissObserver(AppListDismissObserverMac* observer) {
|
| + AppListServiceMac::GetInstance()->RemoveObserver(observer);
|
| +}
|
| +
|
| } // namespace chrome
|
|
|