chrome_launcher_controller.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include <list> 93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include <map> 103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include <set> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include <vector> 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/display/display_controller.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/launcher/launcher_delegate.h" 16424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ash/launcher/launcher_item_delegate.h" 173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/launcher/launcher_model_observer.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/launcher/launcher_types.h" 193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/shelf/shelf_layout_manager_observer.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_types.h" 213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/shell_observer.h" 223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/basictypes.h" 233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/compiler_specific.h" 243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_vector.h" 263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/prefs/pref_change_registrar.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/extensions/app_icon_loader.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_prefs.h" 293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/prefs/pref_service_syncable_observer.h" 303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" 313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 3268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" 333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/public/browser/notification_observer.h" 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/aura/window_observer.h" 363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class AppSyncUIState; 383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class Browser; 393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class BrowserShortcutLauncherItemController; 40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class BrowserStatusMonitor; 413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class ExtensionEnableFlow; 423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class GURL; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LauncherItemController; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class ShellWindowLauncherController; 463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class TabContents; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LauncherModel; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace aura { 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Window; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class NotificationRegistrar; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace ui { 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class BaseWindow; 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A list of the elements which makes up a simple menu description. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// A class which needs to be overwritten dependent on the used OS to moitor 69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// user switching. 70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class ChromeLauncherControllerUserSwitchObserver { 71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public: 72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ChromeLauncherControllerUserSwitchObserver() {} 73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual ~ChromeLauncherControllerUserSwitchObserver() {} 74d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 75d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private: 76d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerUserSwitchObserver); 78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}; 79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ChromeLauncherController manages the launcher items needed for content 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// windows. Launcher items have a type, an optional app id, and a controller. 823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// This incarnation groups running tabs/windows in application specific lists. 833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// * Browser app windows have BrowserLauncherItemController, owned by the 843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// BrowserView instance. 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// * App shell windows have ShellWindowLauncherItemController, owned by 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ShellWindowLauncherController. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// * Shortcuts have no LauncherItemController. 88424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// TODO(simon.hong81): Move LauncherItemDelegate out from 89424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// ChromeLauncherController and makes separate subclass with it. 9068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class ChromeLauncherController : public ash::LauncherDelegate, 9168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public ash::LauncherItemDelegate, 9268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public ash::LauncherModelObserver, 9368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public ash::ShellObserver, 9468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public ash::DisplayController::Observer, 9568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public content::NotificationObserver, 9668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public extensions::AppIconLoader::Delegate, 9768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public PrefServiceSyncableObserver, 9868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public AppSyncUIStateObserver, 9968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public ExtensionEnableFlowDelegate, 10068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public ash::ShelfLayoutManagerObserver { 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates if a launcher item is incognito or not. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum IncognitoState { 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_INCOGNITO, 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_NOT_INCOGNITO, 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Used to update the state of non plaform apps, as web contents change. 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum AppState { 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) APP_STATE_ACTIVE, 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) APP_STATE_WINDOW_ACTIVE, 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) APP_STATE_INACTIVE, 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) APP_STATE_REMOVED 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Mockable interface to get app ids from tabs. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class AppTabHelper { 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~AppTabHelper() {} 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the app id of the specified tab, or an empty string if there is 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no app. 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual std::string GetAppID(content::WebContents* tab) = 0; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if |id| is valid. Used during restore to ignore no longer 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // valid extensions. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsValidID(const std::string& id) = 0; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ChromeLauncherController(Profile* profile, ash::LauncherModel* model); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~ChromeLauncherController(); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes this ChromeLauncherController. 1343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Init(); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates an instance. 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static ChromeLauncherController* CreateInstance(Profile* profile, 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ash::LauncherModel* model); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the single ChromeLauncherController instance. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ChromeLauncherController* instance() { return instance_; } 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a new app item on the launcher for |controller|. 1443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherID CreateAppLauncherItem(LauncherItemController* controller, 1453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& app_id, 1463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherItemStatus status); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Updates the running status of an item. It will also update the status of 1493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // browsers launcher item if needed. 1503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the controller associated with id (which should be a shortcut). 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |controller| remains owned by caller. 1543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetItemController(ash::LauncherID id, 1553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) LauncherItemController* controller); 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Closes or unpins the launcher item. 1583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void CloseLauncherItem(ash::LauncherID id); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Pins the specified id. Currently only supports platform apps. 1613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Pin(ash::LauncherID id); 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Unpins the specified id, closing if not running. 1643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Unpin(ash::LauncherID id); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the item identified by |id| is pinned. 1673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsPinned(ash::LauncherID id); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Pins/unpins the specified id. 1703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void TogglePinned(ash::LauncherID id); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the specified item can be pinned or unpinned. Only apps can 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be pinned. 1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsPinnable(ash::LauncherID id) const; 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If there is no launcher item in the launcher for application |app_id|, one 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // gets created. The (existing or created) launcher items get then locked 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // against a users un-pinning removal. 1793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void LockV1AppWithID(const std::string& app_id); 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A previously locked launcher item of type |app_id| gets unlocked. If the 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // lock count reaches 0 and the item is not pinned it will go away. 1833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void UnlockV1AppWithID(const std::string& app_id); 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Requests that the launcher item controller specified by |id| open a new 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instance of the app. |event_flags| holds the flags of the event which 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // triggered this command. 1883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Launch(ash::LauncherID id, int event_flags); 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Closes the specified item. 1913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Close(ash::LauncherID id); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the specified item is open. 1943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsOpen(ash::LauncherID id); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the specified item is for a platform app. 1973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsPlatformApp(ash::LauncherID id); 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Opens a new instance of the application identified by |app_id|. 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the app-list, and by pinned-app launcher items. 20168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void LaunchApp(const std::string& app_id, 20268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ash::LaunchSource source, 20368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int event_flags); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |app_id| is running, reactivates the app's most recently active window, 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // otherwise launches and activates the app. 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the app-list, and by pinned-app launcher items. 20868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void ActivateApp(const std::string& app_id, 20968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ash::LaunchSource source, 21068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int event_flags); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the launch type of app for the specified id. 2133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extensions::ExtensionPrefs::LaunchType GetLaunchType(ash::LauncherID id); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the id of the app for the specified tab. 2163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::string GetAppID(content::WebContents* tab); 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set the image for a specific launcher item (e.g. when set by the app). 2193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetLauncherItemImage(ash::LauncherID launcher_id, 2203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const gfx::ImageSkia& image); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Find out if the given application |id| is a windowed app item and not a 2233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // pinned item in the launcher. 2243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsWindowedAppInLauncher(const std::string& app_id); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the launche type of the app for the specified id to |launch_type|. 2273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetLaunchType(ash::LauncherID id, 2283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extensions::ExtensionPrefs::LaunchType launch_type); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the user is currently logged in as a guest. 2313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Makes virtual for unittest in LauncherContextMenuTest. 2323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual bool IsLoggedInAsGuest(); 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when user clicks on button in the launcher and there is no last 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // used window (or CTRL is held with the click). 2363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void CreateNewWindow(); 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the user clicks on button in the launcher to create a new 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // incognito window. 2403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void CreateNewIncognitoWindow(); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the pinned pref state. The pinned state consists of a list pref. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Each item of the list is a dictionary. The key |kAppIDPath| gives the 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // id of the app. 2453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void PersistPinnedState(); 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherModel* model(); 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 249d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Accessor to the currently loaded profile. Note that in multi profile use 250d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // cases this might change over time. 2513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Profile* profile(); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets the shelf auto-hide behavior on |root_window|. 2543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( 2553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) aura::RootWindow* root_window) const; 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns |true| if the user is allowed to modify the shelf auto-hide 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // behavior on |root_window|. 2593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool CanUserModifyShelfAutoHideBehavior(aura::RootWindow* root_window) const; 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // user is not allowed to modify the auto-hide behavior. 2633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window); 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The tab no longer represents its previously identified application. 2663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void RemoveTabFromRunningApp(content::WebContents* tab, 2673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& app_id); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notify the controller that the state of an non platform app's tabs 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have changed, 2713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void UpdateAppState(content::WebContents* contents, AppState app_state); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Limits application refocusing to urls that match |url| for |id|. 2743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetRefocusURLPatternForTest(ash::LauncherID id, const GURL& url); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the extension identified by |app_id|. 2773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const extensions::Extension* GetExtensionForAppID( 2783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& app_id) const; 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Activates a |window|. If |allow_minimize| is true and the system allows 281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // it, the the window will get minimized instead. 2823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, 2833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool allow_minimize); 2843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ash::LauncherDelegate overrides: 286424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; 287424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; 288424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE; 289424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ash::LauncherID GetLauncherIDForAppID( 290424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& app_id) OVERRIDE; 291424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual const std::string& GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; 292424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void PinAppWithID(const std::string& app_id) OVERRIDE; 293424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; 29458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual bool CanPin() const OVERRIDE; 295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE; 296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 297424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // ash::LauncherItemDelegate overrides: 298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ItemSelected(const ash::LauncherItem& item, 2993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const ui::Event& event) OVERRIDE; 3003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE; 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ui::MenuModel* CreateContextMenu( 3023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE; 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ash::LauncherMenuModel* CreateApplicationMenu( 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ash::LauncherItem& item, 3053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int event_flags) OVERRIDE; 3063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; 3073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; 3083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // ash::LauncherModelObserver overrides: 3103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void LauncherItemAdded(int index) OVERRIDE; 3113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; 3123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; 3133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void LauncherItemChanged(int index, 3143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const ash::LauncherItem& old_item) OVERRIDE; 3153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void LauncherStatusChanged() OVERRIDE; 3163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // content::NotificationObserver overrides: 3183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void Observe(int type, 3193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const content::NotificationSource& source, 3203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 3213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // ash::ShellObserver overrides: 3233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; 3243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // ash::DisplayController::Observer overrides: 3263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnDisplayConfigurationChanging() OVERRIDE; 3273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnDisplayConfigurationChanged() OVERRIDE; 3283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // PrefServiceSyncableObserver overrides: 3303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnIsSyncingChanged() OVERRIDE; 3313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // AppSyncUIStateObserver overrides: 3333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnAppSyncUIStatusChanged() OVERRIDE; 3343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // ExtensionEnableFlowDelegate overrides: 3363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void ExtensionEnableFlowFinished() OVERRIDE; 3373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // extensions::AppIconLoader overrides: 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetAppImage(const std::string& app_id, 3413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const gfx::ImageSkia& image) OVERRIDE; 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // ash::ShelfLayoutManagerObserver overrides: 3443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnAutoHideBehaviorChanged( 3453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) aura::RootWindow* root_window, 3463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::ShelfAutoHideBehavior new_behavior) OVERRIDE; 3473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 348d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Called when the active user has changed. 349d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void ActiveUserChanged(const std::string& user_email); 350d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 3513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Get the list of all running incarnations of this item. 3523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // |event_flags| specifies the flags which were set by the event which 3533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // triggered this menu generation. It can be used to generate different lists. 3543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ChromeLauncherAppMenuItems GetApplicationList(const ash::LauncherItem& item, 3553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int event_flags); 3563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Get the list of all tabs which belong to a certain application type. 3583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::vector<content::WebContents*> GetV1ApplicationsFromAppId( 3593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::string app_id); 3603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Activates a specified shell application. 3623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void ActivateShellApp(const std::string& app_id, int index); 3633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Checks if a given |web_contents| is known to be associated with an 3653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // application of type |app_id|. 3663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsWebContentHandledByApplication(content::WebContents* web_contents, 3673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& app_id); 3683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Check if the gMail app is loaded and it can handle the given web content. 3703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This special treatment is required to address crbug.com/234268. 3713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Get the favicon for the application list entry for |web_contents|. 3743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Note that for incognito windows the incognito icon will be returned. 3753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // If |web_contents| has not loaded, returns the default favicon. 3763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) gfx::Image GetAppListIcon(content::WebContents* web_contents) const; 3773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Get the title for the applicatoin list entry for |web_contents|. 3793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // If |web_contents| has not loaded, returns "Net Tab". 3803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) string16 GetAppListTitle(content::WebContents* web_contents) const; 3813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Returns the LauncherItemController of BrowserShortcut. 38358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) BrowserShortcutLauncherItemController* 38458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) GetBrowserShortcutLauncherItemController(); 385424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 3863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) protected: 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a new app shortcut item and controller on the launcher at |index|. 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use kInsertItemAtEnd to add a shortcut as the last item. 3893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherID CreateAppShortcutLauncherItem(const std::string& app_id, 3903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int index); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These are intended for testing. 3943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetAppTabHelperForTest(AppTabHelper* helper); 3953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetAppIconLoaderForTest(extensions::AppIconLoader* loader); 3963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& GetAppIdFromLauncherIdForTest(ash::LauncherID id); 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 3993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) friend class ChromeLauncherControllerTest; 4003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) friend class LauncherAppBrowserTest; 4013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) friend class LauncherPlatformAppBrowserTest; 4023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) typedef std::map<ash::LauncherID, LauncherItemController*> 4043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) IDToItemControllerMap; 4053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) typedef std::list<content::WebContents*> WebContentsList; 4063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; 4073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; 4083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Creates a new app shortcut item and controller on the launcher at |index|. 4103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Use kInsertItemAtEnd to add a shortcut as the last item. 4113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherID CreateAppShortcutLauncherItemWithType( 4123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& app_id, 4133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int index, 4143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherItemType launcher_item_type); 4153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Returns the profile used for new windows. 4173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Profile* GetProfileForNewWindows(); 4183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Invoked when the associated browser or app is closed. 4203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void LauncherItemClosed(ash::LauncherID id); 4213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Internal helpers for pinning and unpinning that handle both 4233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // client-triggered and internal pinning operations. 4243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void DoPinAppWithID(const std::string& app_id); 425424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void DoUnpinAppWithID(const std::string& app_id); 4263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 42768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Pin a running app with |launcher_id| internally to |index|. It returns 42868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // the index where the item was pinned. 42968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int PinRunningAppInternal(int index, ash::LauncherID launcher_id); 43068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 43168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Unpin a locked application. This is an internal call which converts the 43268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // model type of the given app index from a shortcut into an unpinned running 43368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // app. 43468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void UnpinRunningAppInternal(int index); 43568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 4363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Re-syncs launcher model with prefs::kPinnedLauncherApps. 4373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void UpdateAppLaunchersFromPref(); 4383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Persists the shelf auto-hide behavior to prefs. 4403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetShelfAutoHideBehaviorPrefs(ash::ShelfAutoHideBehavior behavior, 4413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) aura::RootWindow* root_window); 4423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Sets the shelf auto-hide behavior from prefs. 4443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetShelfAutoHideBehaviorFromPrefs(); 4453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Sets the shelf alignment from prefs. 4473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetShelfAlignmentFromPrefs(); 4483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Sets both of auto-hide behavior and alignment from prefs. 4503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetShelfBehaviorsFromPrefs(); 4513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Returns the most recently active web contents for an app. 4533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) content::WebContents* GetLastActiveWebContents(const std::string& app_id); 4543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Creates an app launcher to insert at |index|. Note that |index| may be 4563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // adjusted by the model to meet ordering constraints. 4573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // The |launcher_item_type| will be set into the LauncherModel. 4583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherID InsertAppLauncherItem( 4593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) LauncherItemController* controller, 4603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& app_id, 4613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherItemStatus status, 4623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int index, 4633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherItemType launcher_item_type); 4643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool HasItemController(ash::LauncherID id) const; 4663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Enumerate all Web contents which match a given shortcut |controller|. 4683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::vector<content::WebContents*> GetV1ApplicationsFromController( 4693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) LauncherItemController* controller); 4703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Create LauncherItem for Browser Shortcut. 4723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherID CreateBrowserShortcutLauncherItem(); 4733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Check if the given |web_contents| is in incognito mode. 47568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bool IsIncognito(const content::WebContents* web_contents) const; 4763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Update browser shortcut's index. 4783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void PersistChromeItemIndex(int index); 4793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Get browser shortcut's index from pref. 4813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int GetChromeIconIndexFromPref() const; 4823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 48368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Depending on the provided flags, move either the chrome icon, the app icon 48468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // or none to the given |target_index|. The provided |chrome_index| and 48568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // |app_list_index| locations will get adjusted within this call to finalize 48668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // the action and to make sure that the other item can still be moved 48768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // afterwards (index adjustments). 48868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void MoveChromeOrApplistToFinalPosition( 48968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bool is_chrome, 49068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bool is_app_list, 49168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int target_index, 49268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int* chrome_index, 49368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int* app_list_index); 49468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 49568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Finds the index of where to insert the next item. 49668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int FindInsertionPoint(bool is_app_list); 49768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 49868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Get the browser shortcut's index in the shelf using the current's systems 49968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // configuration of pinned and known (but not running) apps. 50068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int GetChromeIconIndexForCreation(); 50168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 50268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Get the list of pinned programs from the preferences. 50368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) std::vector<std::string> GetListOfPinnedAppsAndBrowser(); 50468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 5053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Close all windowed V1 applications of a certain extension which was already 5063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // deleted. 5073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void CloseWindowedAppsFromRemovedExtension(const std::string& app_id); 5083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 509424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Register LauncherItemDelegate. 510424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void RegisterLauncherItemDelegate(); 511424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 512d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Attach to a specific profile. 513d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void AttachProfile(Profile* proifile); 514d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 515d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Forget the current profile to allow attaching to a new one. 516d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void ReleaseProfile(); 517d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ChromeLauncherController* instance_; 5193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::LauncherModel* model_; 5213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Profile used for prefs and loading extensions. This is NOT necessarily the 5233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // profile new windows are created with. 5243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Profile* profile_; 5253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) IDToItemControllerMap id_to_item_controller_map_; 5273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Maintains activation order of web contents for each app. 5293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) AppIDToWebContentsListMap app_id_to_web_contents_list_; 5303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Direct access to app_id for a web contents. 5323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) WebContentsToAppIDMap web_contents_to_app_id_; 5333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Used to track shell windows. 5353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<ShellWindowLauncherController> shell_window_controller_; 5363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Used to get app info for tabs. 5383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<AppTabHelper> app_tab_helper_; 5393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Used to load the image for an app item. 5413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<extensions::AppIconLoader> app_icon_loader_; 5423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) content::NotificationRegistrar notification_registrar_; 5443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) PrefChangeRegistrar pref_change_registrar_; 5463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) AppSyncUIState* app_sync_ui_state_; 5483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; 5503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Launchers that are currently being observed. 5523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::set<ash::Launcher*> launchers_; 5533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // The owned browser shortcut item. 5553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<BrowserShortcutLauncherItemController> browser_item_controller_; 5563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 557424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // The owned browser status monitor. 558424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<BrowserStatusMonitor> browser_status_monitor_; 559424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 560d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // A special observer class to detect user switches. 561d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scoped_ptr<ChromeLauncherControllerUserSwitchObserver> user_switch_observer_; 562d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 5633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // If true, incoming pinned state changes should be ignored. 5643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool ignore_persist_pinned_state_change_; 5653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 570