Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / app_list / app_list_controller_ash.cc
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 #include "chrome/browser/ui/browser_navigator.h"
10 #include "extensions/common/extension.h"
11 #include "ui/app_list/views/app_list_view.h"
12
13 AppListControllerDelegateAsh::AppListControllerDelegateAsh() {}
14
15 AppListControllerDelegateAsh::~AppListControllerDelegateAsh() {}
16
17 void AppListControllerDelegateAsh::DismissView() {
18   DCHECK(ash::Shell::HasInstance());
19   ash::Shell::GetInstance()->DismissAppList();
20 }
21
22 gfx::NativeWindow AppListControllerDelegateAsh::GetAppListWindow() {
23   DCHECK(ash::Shell::HasInstance());
24   return ash::Shell::GetInstance()->GetAppListWindow();
25 }
26
27 gfx::Rect AppListControllerDelegateAsh::GetAppListBounds() {
28   app_list::AppListView* app_list_view =
29       ash::Shell::GetInstance()->GetAppListView();
30   if (app_list_view)
31     return app_list_view->GetBoundsInScreen();
32   return gfx::Rect();
33 }
34
35 gfx::ImageSkia AppListControllerDelegateAsh::GetWindowIcon() {
36   return gfx::ImageSkia();
37 }
38
39 bool AppListControllerDelegateAsh::IsAppPinned(
40     const std::string& extension_id) {
41   return ChromeLauncherController::instance()->IsAppPinned(extension_id);
42 }
43
44 void AppListControllerDelegateAsh::PinApp(const std::string& extension_id) {
45   ChromeLauncherController::instance()->PinAppWithID(extension_id);
46 }
47
48 void AppListControllerDelegateAsh::UnpinApp(const std::string& extension_id) {
49   ChromeLauncherController::instance()->UnpinAppWithID(extension_id);
50 }
51
52 AppListControllerDelegate::Pinnable
53     AppListControllerDelegateAsh::GetPinnable() {
54   return ChromeLauncherController::instance()->CanPin() ? PIN_EDITABLE :
55       PIN_FIXED;
56 }
57
58 void AppListControllerDelegateAsh::OnShowChildDialog() {
59   app_list::AppListView* app_list_view =
60       ash::Shell::GetInstance()->GetAppListView();
61   if (app_list_view)
62     app_list_view->SetAppListOverlayVisible(true);
63 }
64
65 void AppListControllerDelegateAsh::OnCloseChildDialog() {
66   app_list::AppListView* app_list_view =
67       ash::Shell::GetInstance()->GetAppListView();
68   if (app_list_view)
69     app_list_view->SetAppListOverlayVisible(false);
70 }
71
72 bool AppListControllerDelegateAsh::CanDoCreateShortcutsFlow() {
73   return false;
74 }
75
76 void AppListControllerDelegateAsh::DoCreateShortcutsFlow(
77     Profile* profile,
78     const std::string& extension_id) {
79   NOTREACHED();
80 }
81
82 void AppListControllerDelegateAsh::CreateNewWindow(Profile* profile,
83                                                    bool incognito) {
84   if (incognito)
85     ChromeLauncherController::instance()->CreateNewIncognitoWindow();
86   else
87     ChromeLauncherController::instance()->CreateNewWindow();
88 }
89
90 void AppListControllerDelegateAsh::OpenURL(Profile* profile,
91                                            const GURL& url,
92                                            ui::PageTransition transition,
93                                            WindowOpenDisposition disposition) {
94   chrome::NavigateParams params(profile, url, transition);
95   params.disposition = disposition;
96   chrome::Navigate(&params);
97 }
98
99 void AppListControllerDelegateAsh::ActivateApp(
100     Profile* profile,
101     const extensions::Extension* extension,
102     AppListSource source,
103     int event_flags) {
104   ChromeLauncherController::instance()->ActivateApp(
105       extension->id(),
106       AppListSourceToLaunchSource(source),
107       event_flags);
108
109   DismissView();
110 }
111
112 void AppListControllerDelegateAsh::LaunchApp(
113     Profile* profile,
114     const extensions::Extension* extension,
115     AppListSource source,
116     int event_flags) {
117   ChromeLauncherController::instance()->LaunchApp(
118       extension->id(),
119       AppListSourceToLaunchSource(source),
120       event_flags);
121   DismissView();
122 }
123
124 void AppListControllerDelegateAsh::ShowForProfileByPath(
125     const base::FilePath& profile_path) {
126   // Ash doesn't have profile switching.
127   NOTREACHED();
128 }
129
130 bool AppListControllerDelegateAsh::ShouldShowUserIcon() {
131   return false;
132 }
133
134 ash::LaunchSource AppListControllerDelegateAsh::AppListSourceToLaunchSource(
135     AppListSource source) {
136   switch (source) {
137     case LAUNCH_FROM_APP_LIST:
138       return ash::LAUNCH_FROM_APP_LIST;
139     case LAUNCH_FROM_APP_LIST_SEARCH:
140       return ash::LAUNCH_FROM_APP_LIST_SEARCH;
141     default:
142       return ash::LAUNCH_FROM_UNKNOWN;
143   }
144 }