| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 11 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| 12 #include "ash/common/shelf/shelf_model_observer.h" | 12 #include "ash/common/shelf/shelf_model_observer.h" |
| 13 #include "ash/common/shelf/shelf_types.h" | 13 #include "ash/common/shelf/shelf_types.h" |
| 14 #include "ash/display/window_tree_host_manager.h" | 14 #include "ash/display/window_tree_host_manager.h" |
| 15 #include "ash/shelf/shelf_delegate.h" | 15 #include "ash/shelf/shelf_delegate.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/ui/app_icon_loader.h" | 19 #include "chrome/browser/ui/app_icon_loader.h" |
| 20 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 20 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | 21 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| 21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 22 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 22 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" | 23 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" |
| 23 #include "components/prefs/pref_change_registrar.h" | 24 #include "components/prefs/pref_change_registrar.h" |
| 24 #include "ui/aura/window_observer.h" | 25 #include "ui/aura/window_observer.h" |
| 25 | 26 |
| 26 class AppSyncUIState; | 27 class AppSyncUIState; |
| 27 class BrowserStatusMonitor; | 28 class BrowserStatusMonitor; |
| 28 class LauncherControllerHelper; | 29 class LauncherControllerHelper; |
| 29 class Profile; | 30 class Profile; |
| 30 class AppWindowLauncherController; | 31 class AppWindowLauncherController; |
| 31 class TabContents; | 32 class TabContents; |
| 32 | 33 |
| 33 namespace ash { | 34 namespace ash { |
| 34 class ChromeLauncherPrefsObserver; | |
| 35 class ShelfItemDelegateManager; | 35 class ShelfItemDelegateManager; |
| 36 class ShelfModel; | 36 class ShelfModel; |
| 37 namespace launcher { |
| 38 class ChromeLauncherPrefsObserver; |
| 39 } |
| 37 } | 40 } |
| 38 | 41 |
| 39 namespace aura { | 42 namespace aura { |
| 40 class Window; | 43 class Window; |
| 41 } | 44 } |
| 42 | 45 |
| 43 namespace content { | 46 namespace content { |
| 44 class BrowserContext; | 47 class BrowserContext; |
| 45 } | 48 } |
| 46 | 49 |
| 47 namespace extensions { | 50 namespace extensions { |
| 48 class Extension; | 51 class Extension; |
| 49 } | 52 } |
| 50 | 53 |
| 51 class ChromeLauncherControllerUserSwitchObserver; | 54 class ChromeLauncherControllerUserSwitchObserver; |
| 52 | 55 |
| 53 // Implementation of ChromeLauncherController, used for classic Ash. | 56 // Implementation of ChromeLauncherController, used for classic Ash. |
| 54 // In addition to implementing ChromeLauncherController, this class performs | 57 // In addition to implementing ChromeLauncherController, this class performs |
| 55 // a lot of other responsibilities, such as implementing ash::ShelfDelegate, | 58 // a lot of other responsibilities, such as implementing ash::ShelfDelegate, |
| 56 // updating the UI state and the shelf model when apps are uninstalled, etc. | 59 // updating the UI state and the shelf model when apps are uninstalled, etc. |
| 57 class ChromeLauncherControllerImpl | 60 class ChromeLauncherControllerImpl |
| 58 : public ChromeLauncherController, | 61 : public ChromeLauncherController, |
| 59 public ash::ShelfDelegate, | 62 public ash::ShelfDelegate, |
| 60 public LauncherAppUpdater::Delegate, | 63 public LauncherAppUpdater::Delegate, |
| 61 private ash::ShelfModelObserver, | 64 private ash::ShelfModelObserver, |
| 62 private ash::WindowTreeHostManager::Observer, | 65 private ash::WindowTreeHostManager::Observer, |
| 63 private AppIconLoaderDelegate, | 66 private AppIconLoaderDelegate, |
| 64 private AppSyncUIStateObserver, | 67 private AppSyncUIStateObserver, |
| 65 private ash::ShelfItemDelegateManagerObserver { | 68 private ash::ShelfItemDelegateManagerObserver, |
| 69 private app_list::AppListSyncableService::Observer { |
| 66 public: | 70 public: |
| 67 ChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model); | 71 ChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model); |
| 68 ~ChromeLauncherControllerImpl() override; | 72 ~ChromeLauncherControllerImpl() override; |
| 69 | 73 |
| 70 // Create ChromeLauncherControllerImpl instance and set is as the | 74 // Create ChromeLauncherControllerImpl instance and set is as the |
| 71 // ChromeLauncherController singleton. | 75 // ChromeLauncherController singleton. |
| 72 static ChromeLauncherControllerImpl* CreateInstance(Profile* profile, | 76 static ChromeLauncherControllerImpl* CreateInstance(Profile* profile, |
| 73 ash::ShelfModel* model); | 77 ash::ShelfModel* model); |
| 74 | 78 |
| 75 // ChromeLauncherController: | 79 // ChromeLauncherController: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 97 int event_flags) override; | 101 int event_flags) override; |
| 98 void ActivateApp(const std::string& app_id, | 102 void ActivateApp(const std::string& app_id, |
| 99 ash::LaunchSource source, | 103 ash::LaunchSource source, |
| 100 int event_flags) override; | 104 int event_flags) override; |
| 101 extensions::LaunchType GetLaunchType(ash::ShelfID id) override; | 105 extensions::LaunchType GetLaunchType(ash::ShelfID id) override; |
| 102 void SetLauncherItemImage(ash::ShelfID shelf_id, | 106 void SetLauncherItemImage(ash::ShelfID shelf_id, |
| 103 const gfx::ImageSkia& image) override; | 107 const gfx::ImageSkia& image) override; |
| 104 bool IsWindowedAppInLauncher(const std::string& app_id) override; | 108 bool IsWindowedAppInLauncher(const std::string& app_id) override; |
| 105 void SetLaunchType(ash::ShelfID id, | 109 void SetLaunchType(ash::ShelfID id, |
| 106 extensions::LaunchType launch_type) override; | 110 extensions::LaunchType launch_type) override; |
| 107 void PersistPinnedState() override; | |
| 108 Profile* GetProfile() override; | 111 Profile* GetProfile() override; |
| 109 void UpdateAppState(content::WebContents* contents, | 112 void UpdateAppState(content::WebContents* contents, |
| 110 AppState app_state) override; | 113 AppState app_state) override; |
| 111 ash::ShelfID GetShelfIDForWebContents( | 114 ash::ShelfID GetShelfIDForWebContents( |
| 112 content::WebContents* contents) override; | 115 content::WebContents* contents) override; |
| 113 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url) override; | 116 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url) override; |
| 114 const extensions::Extension* GetExtensionForAppID( | 117 const extensions::Extension* GetExtensionForAppID( |
| 115 const std::string& app_id) const override; | 118 const std::string& app_id) const override; |
| 116 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( | 119 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( |
| 117 ui::BaseWindow* window, | 120 ui::BaseWindow* window, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 227 |
| 225 // Pin a running app with |shelf_id| internally to |index|. It returns | 228 // Pin a running app with |shelf_id| internally to |index|. It returns |
| 226 // the index where the item was pinned. | 229 // the index where the item was pinned. |
| 227 int PinRunningAppInternal(int index, ash::ShelfID shelf_id); | 230 int PinRunningAppInternal(int index, ash::ShelfID shelf_id); |
| 228 | 231 |
| 229 // Unpin a locked application. This is an internal call which converts the | 232 // Unpin a locked application. This is an internal call which converts the |
| 230 // model type of the given app index from a shortcut into an unpinned running | 233 // model type of the given app index from a shortcut into an unpinned running |
| 231 // app. | 234 // app. |
| 232 void UnpinRunningAppInternal(int index); | 235 void UnpinRunningAppInternal(int index); |
| 233 | 236 |
| 234 // Re-syncs shelf model with prefs::kPinnedLauncherApps. | 237 // Updates pin position for the item specified by |id| in sync model. |
| 238 void SyncPinPosition(ash::ShelfID id); |
| 239 |
| 240 // Re-syncs shelf model. |
| 235 void UpdateAppLaunchersFromPref(); | 241 void UpdateAppLaunchersFromPref(); |
| 236 | 242 |
| 237 // Sets the shelf auto-hide behavior from prefs. | 243 // Sets the shelf auto-hide behavior from prefs. |
| 238 void SetShelfAutoHideBehaviorFromPrefs(); | 244 void SetShelfAutoHideBehaviorFromPrefs(); |
| 239 | 245 |
| 240 // Sets the shelf alignment from prefs. | 246 // Sets the shelf alignment from prefs. |
| 241 void SetShelfAlignmentFromPrefs(); | 247 void SetShelfAlignmentFromPrefs(); |
| 242 | 248 |
| 243 // Sets both of auto-hide behavior and alignment from prefs. | 249 // Sets both of auto-hide behavior and alignment from prefs. |
| 244 void SetShelfBehaviorsFromPrefs(); | 250 void SetShelfBehaviorsFromPrefs(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 263 // Enumerate all Web contents which match a given shortcut |controller|. | 269 // Enumerate all Web contents which match a given shortcut |controller|. |
| 264 std::vector<content::WebContents*> GetV1ApplicationsFromController( | 270 std::vector<content::WebContents*> GetV1ApplicationsFromController( |
| 265 LauncherItemController* controller); | 271 LauncherItemController* controller); |
| 266 | 272 |
| 267 // Create ShelfItem for Browser Shortcut. | 273 // Create ShelfItem for Browser Shortcut. |
| 268 ash::ShelfID CreateBrowserShortcutLauncherItem(); | 274 ash::ShelfID CreateBrowserShortcutLauncherItem(); |
| 269 | 275 |
| 270 // Check if the given |web_contents| is in incognito mode. | 276 // Check if the given |web_contents| is in incognito mode. |
| 271 bool IsIncognito(const content::WebContents* web_contents) const; | 277 bool IsIncognito(const content::WebContents* web_contents) const; |
| 272 | 278 |
| 273 // Update browser shortcut's index. | |
| 274 void PersistChromeItemIndex(int index); | |
| 275 | |
| 276 // Depending on the provided flags, move either the chrome icon, the app icon | |
| 277 // or none to the given |target_index|. The provided |chrome_index| and | |
| 278 // |app_list_index| locations will get adjusted within this call to finalize | |
| 279 // the action and to make sure that the other item can still be moved | |
| 280 // afterwards (index adjustments). | |
| 281 void MoveChromeOrApplistToFinalPosition(bool is_chrome, | |
| 282 bool is_app_list, | |
| 283 int target_index, | |
| 284 int* chrome_index, | |
| 285 int* app_list_index); | |
| 286 | |
| 287 // Finds the index of where to insert the next item. | 279 // Finds the index of where to insert the next item. |
| 288 int FindInsertionPoint(bool is_app_list); | 280 int FindInsertionPoint(); |
| 289 | |
| 290 // Get the browser shortcut's index in the shelf using the current's systems | |
| 291 // configuration of pinned and known (but not running) apps. | |
| 292 int GetChromeIconIndexForCreation(); | |
| 293 | 281 |
| 294 // Close all windowed V1 applications of a certain extension which was already | 282 // Close all windowed V1 applications of a certain extension which was already |
| 295 // deleted. | 283 // deleted. |
| 296 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, | 284 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, |
| 297 const Profile* profile); | 285 const Profile* profile); |
| 298 | 286 |
| 299 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. | 287 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. |
| 300 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. | 288 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. |
| 301 void SetShelfItemDelegate(ash::ShelfID id, | 289 void SetShelfItemDelegate(ash::ShelfID id, |
| 302 ash::ShelfItemDelegate* item_delegate); | 290 ash::ShelfItemDelegate* item_delegate); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 322 // ash::WindowTreeHostManager::Observer: | 310 // ash::WindowTreeHostManager::Observer: |
| 323 void OnDisplayConfigurationChanged() override; | 311 void OnDisplayConfigurationChanged() override; |
| 324 | 312 |
| 325 // AppSyncUIStateObserver: | 313 // AppSyncUIStateObserver: |
| 326 void OnAppSyncUIStatusChanged() override; | 314 void OnAppSyncUIStatusChanged() override; |
| 327 | 315 |
| 328 // AppIconLoaderDelegate: | 316 // AppIconLoaderDelegate: |
| 329 void OnAppImageUpdated(const std::string& app_id, | 317 void OnAppImageUpdated(const std::string& app_id, |
| 330 const gfx::ImageSkia& image) override; | 318 const gfx::ImageSkia& image) override; |
| 331 | 319 |
| 320 // app_list::AppListSyncableService::Observer: |
| 321 void OnSyncModelUpdated() override; |
| 322 |
| 332 ash::ShelfModel* model_; | 323 ash::ShelfModel* model_; |
| 333 | 324 |
| 334 ash::ShelfItemDelegateManager* item_delegate_manager_; | 325 ash::ShelfItemDelegateManager* item_delegate_manager_ = nullptr; |
| 335 | 326 |
| 336 // Profile used for prefs and loading extensions. This is NOT necessarily the | 327 // Profile used for prefs and loading extensions. This is NOT necessarily the |
| 337 // profile new windows are created with. | 328 // profile new windows are created with. |
| 338 Profile* profile_; | 329 Profile* profile_; |
| 339 | 330 |
| 340 // Controller items in this map are owned by |ShelfItemDelegateManager|. | 331 // Controller items in this map are owned by |ShelfItemDelegateManager|. |
| 341 IDToItemControllerMap id_to_item_controller_map_; | 332 IDToItemControllerMap id_to_item_controller_map_; |
| 342 | 333 |
| 343 // Direct access to app_id for a web contents. | 334 // Direct access to app_id for a web contents. |
| 344 WebContentsToAppIDMap web_contents_to_app_id_; | 335 WebContentsToAppIDMap web_contents_to_app_id_; |
| 345 | 336 |
| 346 // Used to track app windows. | 337 // Used to track app windows. |
| 347 std::vector<std::unique_ptr<AppWindowLauncherController>> | 338 std::vector<std::unique_ptr<AppWindowLauncherController>> |
| 348 app_window_controllers_; | 339 app_window_controllers_; |
| 349 | 340 |
| 350 // Used to get app info for tabs. | 341 // Used to get app info for tabs. |
| 351 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; | 342 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; |
| 352 | 343 |
| 353 // Used to load the images for app items. | 344 // Used to load the images for app items. |
| 354 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; | 345 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; |
| 355 | 346 |
| 356 // Used to handle app load/unload events. | 347 // Used to handle app load/unload events. |
| 357 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_; | 348 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_; |
| 358 | 349 |
| 359 PrefChangeRegistrar pref_change_registrar_; | 350 PrefChangeRegistrar pref_change_registrar_; |
| 360 | 351 |
| 361 AppSyncUIState* app_sync_ui_state_; | 352 AppSyncUIState* app_sync_ui_state_ = nullptr; |
| 362 | 353 |
| 363 // The owned browser status monitor. | 354 // The owned browser status monitor. |
| 364 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_; | 355 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_; |
| 365 | 356 |
| 366 // A special observer class to detect user switches. | 357 // A special observer class to detect user switches. |
| 367 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver> | 358 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver> |
| 368 user_switch_observer_; | 359 user_switch_observer_; |
| 369 | 360 |
| 370 std::unique_ptr<ash::ChromeLauncherPrefsObserver> prefs_observer_; | 361 std::unique_ptr<ash::launcher::ChromeLauncherPrefsObserver> prefs_observer_; |
| 371 | 362 |
| 372 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_; | 363 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_; |
| 373 | 364 |
| 374 // If true, incoming pinned state changes should be ignored. | 365 // If true, incoming pinned state changes should be ignored. |
| 375 bool ignore_persist_pinned_state_change_; | 366 bool ignore_persist_pinned_state_change_ = false; |
| 376 | 367 |
| 377 // The list of running & un-pinned applications for different users on hidden | 368 // The list of running & un-pinned applications for different users on hidden |
| 378 // desktops. | 369 // desktops. |
| 379 typedef std::vector<std::string> RunningAppListIds; | 370 typedef std::vector<std::string> RunningAppListIds; |
| 380 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; | 371 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; |
| 381 RunningAppListIdMap last_used_running_application_order_; | 372 RunningAppListIdMap last_used_running_application_order_; |
| 382 | 373 |
| 383 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImpl); | 374 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImpl); |
| 384 }; | 375 }; |
| 385 | 376 |
| 386 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ | 377 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| OLD | NEW |