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