app_list_controller_ash.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
6
7#include "ash/shell.h"
8#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
9
10AppListControllerDelegateAsh::AppListControllerDelegateAsh() {}
11
12AppListControllerDelegateAsh::~AppListControllerDelegateAsh() {}
13
14void AppListControllerDelegateAsh::DismissView() {
15  DCHECK(ash::Shell::HasInstance());
16  if (ash::Shell::GetInstance()->GetAppListTargetVisibility())
17    ash::Shell::GetInstance()->ToggleAppList(NULL);
18}
19
20gfx::NativeWindow AppListControllerDelegateAsh::GetAppListWindow() {
21  DCHECK(ash::Shell::HasInstance());
22  return ash::Shell::GetInstance()->GetAppListWindow();
23}
24
25bool AppListControllerDelegateAsh::IsAppPinned(
26    const std::string& extension_id) {
27  return ChromeLauncherController::instance()->IsAppPinned(extension_id);
28}
29
30void AppListControllerDelegateAsh::PinApp(const std::string& extension_id) {
31  ChromeLauncherController::instance()->PinAppWithID(extension_id);
32}
33
34void AppListControllerDelegateAsh::UnpinApp(const std::string& extension_id) {
35  ChromeLauncherController::instance()->UnpinAppWithID(extension_id);
36}
37
38AppListControllerDelegate::Pinnable
39    AppListControllerDelegateAsh::GetPinnable() {
40  return ChromeLauncherController::instance()->CanPin() ? PIN_EDITABLE :
41      PIN_FIXED;
42}
43
44bool AppListControllerDelegateAsh::CanDoCreateShortcutsFlow(
45    bool is_platform_app) {
46  return false;
47}
48
49void AppListControllerDelegateAsh::CreateNewWindow(Profile* profile,
50                                                   bool incognito) {
51  if (incognito)
52    ChromeLauncherController::instance()->CreateNewIncognitoWindow();
53  else
54    ChromeLauncherController::instance()->CreateNewWindow();
55}
56
57void AppListControllerDelegateAsh::ActivateApp(
58    Profile* profile,
59    const extensions::Extension* extension,
60    AppListSource source,
61    int event_flags) {
62  ChromeLauncherController::instance()->ActivateApp(
63      extension->id(),
64      AppListSourceToLaunchSource(source),
65      event_flags);
66
67  DismissView();
68}
69
70void AppListControllerDelegateAsh::LaunchApp(
71    Profile* profile,
72    const extensions::Extension* extension,
73    AppListSource source,
74    int event_flags) {
75  ChromeLauncherController::instance()->LaunchApp(
76      extension->id(),
77      AppListSourceToLaunchSource(source),
78      event_flags);
79  DismissView();
80}
81
82void AppListControllerDelegateAsh::ShowForProfileByPath(
83    const base::FilePath& profile_path) {
84  // Ash doesn't have profile switching.
85  NOTREACHED();
86}
87
88bool AppListControllerDelegateAsh::ShouldShowUserIcon() {
89  return false;
90}
91
92ash::LaunchSource AppListControllerDelegateAsh::AppListSourceToLaunchSource(
93    AppListSource source) {
94  switch (source) {
95    case LAUNCH_FROM_APP_LIST:
96      return ash::LAUNCH_FROM_APP_LIST;
97    case LAUNCH_FROM_APP_LIST_SEARCH:
98      return ash::LAUNCH_FROM_APP_LIST_SEARCH;
99    default:
100      return ash::LAUNCH_FROM_UNKNOWN;
101  }
102}
103