| 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_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "ash/common/shelf/shelf_item_delegate.h" | 14 #include "ash/common/shelf/shelf_item_delegate.h" |
| 15 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 15 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| 16 #include "ash/common/shelf/shelf_item_types.h" | 16 #include "ash/common/shelf/shelf_item_types.h" |
| 17 #include "ash/common/shelf/shelf_model_observer.h" | 17 #include "ash/common/shelf/shelf_model_observer.h" |
| 18 #include "ash/common/shelf/shelf_types.h" | 18 #include "ash/common/shelf/shelf_types.h" |
| 19 #include "ash/display/window_tree_host_manager.h" | 19 #include "ash/display/window_tree_host_manager.h" |
| 20 #include "ash/shelf/shelf_delegate.h" | 20 #include "ash/shelf/shelf_delegate.h" |
| 21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/scoped_vector.h" | 23 #include "base/memory/scoped_vector.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "chrome/browser/ui/app_icon_loader.h" | 25 #include "chrome/browser/ui/app_icon_loader.h" |
| 26 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 26 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 27 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 27 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | 28 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| 28 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | 30 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
| 30 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" | 31 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" |
| 31 #include "components/prefs/pref_change_registrar.h" | 32 #include "components/prefs/pref_change_registrar.h" |
| 32 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 33 #include "ui/aura/window_observer.h" | 34 #include "ui/aura/window_observer.h" |
| 34 | 35 |
| 35 class AppSyncUIState; | 36 class AppSyncUIState; |
| 36 class ArcAppDeferredLauncherController; | 37 class ArcAppDeferredLauncherController; |
| 37 class Browser; | 38 class Browser; |
| 38 class BrowserShortcutLauncherItemController; | 39 class BrowserShortcutLauncherItemController; |
| 39 class BrowserStatusMonitor; | 40 class BrowserStatusMonitor; |
| 40 class GURL; | 41 class GURL; |
| 41 class LauncherControllerHelper; | 42 class LauncherControllerHelper; |
| 42 class LauncherItemController; | 43 class LauncherItemController; |
| 43 class Profile; | 44 class Profile; |
| 44 class AppWindowLauncherController; | 45 class AppWindowLauncherController; |
| 45 class TabContents; | 46 class TabContents; |
| 46 | 47 |
| 47 namespace ash { | 48 namespace ash { |
| 48 class ChromeLauncherPrefsObserver; | |
| 49 class ShelfItemDelegateManager; | 49 class ShelfItemDelegateManager; |
| 50 class ShelfModel; | 50 class ShelfModel; |
| 51 namespace launcher { |
| 52 class ChromeLauncherPrefsObserver; |
| 53 } |
| 51 } | 54 } |
| 52 | 55 |
| 53 namespace aura { | 56 namespace aura { |
| 54 class Window; | 57 class Window; |
| 55 } | 58 } |
| 56 | 59 |
| 57 namespace content { | 60 namespace content { |
| 58 class BrowserContext; | 61 class BrowserContext; |
| 59 class WebContents; | 62 class WebContents; |
| 60 } | 63 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 80 // * App windows have AppWindowLauncherItemController, owned by | 83 // * App windows have AppWindowLauncherItemController, owned by |
| 81 // AppWindowLauncherController. | 84 // AppWindowLauncherController. |
| 82 // * Shortcuts have no LauncherItemController. | 85 // * Shortcuts have no LauncherItemController. |
| 83 class ChromeLauncherController | 86 class ChromeLauncherController |
| 84 : public ash::ShelfDelegate, | 87 : public ash::ShelfDelegate, |
| 85 public ash::ShelfModelObserver, | 88 public ash::ShelfModelObserver, |
| 86 public ash::WindowTreeHostManager::Observer, | 89 public ash::WindowTreeHostManager::Observer, |
| 87 public AppIconLoaderDelegate, | 90 public AppIconLoaderDelegate, |
| 88 public AppSyncUIStateObserver, | 91 public AppSyncUIStateObserver, |
| 89 public LauncherAppUpdater::Delegate, | 92 public LauncherAppUpdater::Delegate, |
| 90 public ash::ShelfItemDelegateManagerObserver { | 93 public ash::ShelfItemDelegateManagerObserver, |
| 94 public app_list::AppListSyncableService::Observer { |
| 91 public: | 95 public: |
| 92 // Used to update the state of non plaform apps, as web contents change. | 96 // Used to update the state of non plaform apps, as web contents change. |
| 93 enum AppState { | 97 enum AppState { |
| 94 APP_STATE_ACTIVE, | 98 APP_STATE_ACTIVE, |
| 95 APP_STATE_WINDOW_ACTIVE, | 99 APP_STATE_WINDOW_ACTIVE, |
| 96 APP_STATE_INACTIVE, | 100 APP_STATE_INACTIVE, |
| 97 APP_STATE_REMOVED | 101 APP_STATE_REMOVED |
| 98 }; | 102 }; |
| 99 | 103 |
| 100 ChromeLauncherController(Profile* profile, ash::ShelfModel* model); | 104 ChromeLauncherController(Profile* profile, ash::ShelfModel* model); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // Set the image for a specific shelf item (e.g. when set by the app). | 190 // Set the image for a specific shelf item (e.g. when set by the app). |
| 187 void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image); | 191 void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image); |
| 188 | 192 |
| 189 // Find out if the given application |id| is a windowed app item and not a | 193 // Find out if the given application |id| is a windowed app item and not a |
| 190 // pinned item in the shelf. | 194 // pinned item in the shelf. |
| 191 bool IsWindowedAppInLauncher(const std::string& app_id); | 195 bool IsWindowedAppInLauncher(const std::string& app_id); |
| 192 | 196 |
| 193 // Updates the launch type of the app for the specified id to |launch_type|. | 197 // Updates the launch type of the app for the specified id to |launch_type|. |
| 194 void SetLaunchType(ash::ShelfID id, extensions::LaunchType launch_type); | 198 void SetLaunchType(ash::ShelfID id, extensions::LaunchType launch_type); |
| 195 | 199 |
| 196 // Updates the pinned pref state. The pinned state consists of a list pref. | |
| 197 // Each item of the list is a dictionary. The key |kAppIDPath| gives the | |
| 198 // id of the app. | |
| 199 void PersistPinnedState(); | |
| 200 | |
| 201 // Accessor to the currently loaded profile. Note that in multi profile use | 200 // Accessor to the currently loaded profile. Note that in multi profile use |
| 202 // cases this might change over time. | 201 // cases this might change over time. |
| 203 Profile* profile(); | 202 Profile* profile(); |
| 204 | 203 |
| 205 // Notify the controller that the state of an non platform app's tabs | 204 // Notify the controller that the state of an non platform app's tabs |
| 206 // have changed, | 205 // have changed, |
| 207 void UpdateAppState(content::WebContents* contents, AppState app_state); | 206 void UpdateAppState(content::WebContents* contents, AppState app_state); |
| 208 | 207 |
| 209 // Returns ShelfID for |contents|. If |contents| is not an app or is not | 208 // Returns ShelfID for |contents|. If |contents| is not an app or is not |
| 210 // pinned, returns the id of browser shrotcut. | 209 // pinned, returns the id of browser shrotcut. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void OnAppUninstalled(content::BrowserContext* browser_context, | 260 void OnAppUninstalled(content::BrowserContext* browser_context, |
| 262 const std::string& app_id) override; | 261 const std::string& app_id) override; |
| 263 | 262 |
| 264 // AppSyncUIStateObserver: | 263 // AppSyncUIStateObserver: |
| 265 void OnAppSyncUIStatusChanged() override; | 264 void OnAppSyncUIStatusChanged() override; |
| 266 | 265 |
| 267 // AppIconLoaderDelegate: | 266 // AppIconLoaderDelegate: |
| 268 void OnAppImageUpdated(const std::string& app_id, | 267 void OnAppImageUpdated(const std::string& app_id, |
| 269 const gfx::ImageSkia& image) override; | 268 const gfx::ImageSkia& image) override; |
| 270 | 269 |
| 270 // app_list::AppListSyncableService::Observer: |
| 271 void OnSyncModelUpdated() override; |
| 272 |
| 271 // Called when the active user has changed. | 273 // Called when the active user has changed. |
| 272 void ActiveUserChanged(const std::string& user_email); | 274 void ActiveUserChanged(const std::string& user_email); |
| 273 | 275 |
| 274 // Called when a user got added to the session. | 276 // Called when a user got added to the session. |
| 275 void AdditionalUserAddedToSession(Profile* profile); | 277 void AdditionalUserAddedToSession(Profile* profile); |
| 276 | 278 |
| 277 // Get the list of all running incarnations of this item. | 279 // Get the list of all running incarnations of this item. |
| 278 // |event_flags| specifies the flags which were set by the event which | 280 // |event_flags| specifies the flags which were set by the event which |
| 279 // triggered this menu generation. It can be used to generate different lists. | 281 // triggered this menu generation. It can be used to generate different lists. |
| 280 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, | 282 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 392 |
| 391 // Pin a running app with |shelf_id| internally to |index|. It returns | 393 // Pin a running app with |shelf_id| internally to |index|. It returns |
| 392 // the index where the item was pinned. | 394 // the index where the item was pinned. |
| 393 int PinRunningAppInternal(int index, ash::ShelfID shelf_id); | 395 int PinRunningAppInternal(int index, ash::ShelfID shelf_id); |
| 394 | 396 |
| 395 // Unpin a locked application. This is an internal call which converts the | 397 // Unpin a locked application. This is an internal call which converts the |
| 396 // model type of the given app index from a shortcut into an unpinned running | 398 // model type of the given app index from a shortcut into an unpinned running |
| 397 // app. | 399 // app. |
| 398 void UnpinRunningAppInternal(int index); | 400 void UnpinRunningAppInternal(int index); |
| 399 | 401 |
| 400 // Re-syncs shelf model with prefs::kPinnedLauncherApps. | 402 // Updates pin position for the item specified by |id| in sync model. |
| 403 void SyncPinPosition(ash::ShelfID id); |
| 404 |
| 405 // Re-syncs shelf model. |
| 401 void UpdateAppLaunchersFromPref(); | 406 void UpdateAppLaunchersFromPref(); |
| 402 | 407 |
| 403 // Sets the shelf auto-hide behavior from prefs. | 408 // Sets the shelf auto-hide behavior from prefs. |
| 404 void SetShelfAutoHideBehaviorFromPrefs(); | 409 void SetShelfAutoHideBehaviorFromPrefs(); |
| 405 | 410 |
| 406 // Sets the shelf alignment from prefs. | 411 // Sets the shelf alignment from prefs. |
| 407 void SetShelfAlignmentFromPrefs(); | 412 void SetShelfAlignmentFromPrefs(); |
| 408 | 413 |
| 409 // Sets both of auto-hide behavior and alignment from prefs. | 414 // Sets both of auto-hide behavior and alignment from prefs. |
| 410 void SetShelfBehaviorsFromPrefs(); | 415 void SetShelfBehaviorsFromPrefs(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 429 // Enumerate all Web contents which match a given shortcut |controller|. | 434 // Enumerate all Web contents which match a given shortcut |controller|. |
| 430 std::vector<content::WebContents*> GetV1ApplicationsFromController( | 435 std::vector<content::WebContents*> GetV1ApplicationsFromController( |
| 431 LauncherItemController* controller); | 436 LauncherItemController* controller); |
| 432 | 437 |
| 433 // Create ShelfItem for Browser Shortcut. | 438 // Create ShelfItem for Browser Shortcut. |
| 434 ash::ShelfID CreateBrowserShortcutLauncherItem(); | 439 ash::ShelfID CreateBrowserShortcutLauncherItem(); |
| 435 | 440 |
| 436 // Check if the given |web_contents| is in incognito mode. | 441 // Check if the given |web_contents| is in incognito mode. |
| 437 bool IsIncognito(const content::WebContents* web_contents) const; | 442 bool IsIncognito(const content::WebContents* web_contents) const; |
| 438 | 443 |
| 439 // Update browser shortcut's index. | |
| 440 void PersistChromeItemIndex(int index); | |
| 441 | |
| 442 // Depending on the provided flags, move either the chrome icon, the app icon | |
| 443 // or none to the given |target_index|. The provided |chrome_index| and | |
| 444 // |app_list_index| locations will get adjusted within this call to finalize | |
| 445 // the action and to make sure that the other item can still be moved | |
| 446 // afterwards (index adjustments). | |
| 447 void MoveChromeOrApplistToFinalPosition( | |
| 448 bool is_chrome, | |
| 449 bool is_app_list, | |
| 450 int target_index, | |
| 451 int* chrome_index, | |
| 452 int* app_list_index); | |
| 453 | |
| 454 // Finds the index of where to insert the next item. | 444 // Finds the index of where to insert the next item. |
| 455 int FindInsertionPoint(bool is_app_list); | 445 int FindInsertionPoint(); |
| 456 | 446 |
| 457 // Get the browser shortcut's index in the shelf using the current's systems | 447 // Get the browser shortcut's index in the shelf using the current's systems |
| 458 // configuration of pinned and known (but not running) apps. | 448 // configuration of pinned and known (but not running) apps. |
| 459 int GetChromeIconIndexForCreation(); | 449 int GetChromeIconIndexForCreation(); |
| 460 | 450 |
| 461 // Close all windowed V1 applications of a certain extension which was already | 451 // Close all windowed V1 applications of a certain extension which was already |
| 462 // deleted. | 452 // deleted. |
| 463 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, | 453 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, |
| 464 const Profile* profile); | 454 const Profile* profile); |
| 465 | 455 |
| 466 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. | 456 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. |
| 467 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. | 457 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. |
| 468 void SetShelfItemDelegate(ash::ShelfID id, | 458 void SetShelfItemDelegate(ash::ShelfID id, |
| 469 ash::ShelfItemDelegate* item_delegate); | 459 ash::ShelfItemDelegate* item_delegate); |
| 470 | 460 |
| 471 // Attach to a specific profile. | 461 // Attach to a specific profile. |
| 472 void AttachProfile(Profile* proifile); | 462 void AttachProfile(Profile* proifile); |
| 473 | 463 |
| 474 // Forget the current profile to allow attaching to a new one. | 464 // Forget the current profile to allow attaching to a new one. |
| 475 void ReleaseProfile(); | 465 void ReleaseProfile(); |
| 476 | 466 |
| 477 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); | 467 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); |
| 478 | 468 |
| 479 static ChromeLauncherController* instance_; | 469 static ChromeLauncherController* instance_; |
| 480 | 470 |
| 481 ash::ShelfModel* model_; | 471 ash::ShelfModel* model_; |
| 482 | 472 |
| 483 ash::ShelfItemDelegateManager* item_delegate_manager_; | 473 ash::ShelfItemDelegateManager* item_delegate_manager_ = nullptr; |
| 484 | 474 |
| 485 // Profile used for prefs and loading extensions. This is NOT necessarily the | 475 // Profile used for prefs and loading extensions. This is NOT necessarily the |
| 486 // profile new windows are created with. | 476 // profile new windows are created with. |
| 487 Profile* profile_; | 477 Profile* profile_; |
| 488 | 478 |
| 489 // Controller items in this map are owned by |ShelfItemDelegateManager|. | 479 // Controller items in this map are owned by |ShelfItemDelegateManager|. |
| 490 IDToItemControllerMap id_to_item_controller_map_; | 480 IDToItemControllerMap id_to_item_controller_map_; |
| 491 | 481 |
| 492 // Direct access to app_id for a web contents. | 482 // Direct access to app_id for a web contents. |
| 493 WebContentsToAppIDMap web_contents_to_app_id_; | 483 WebContentsToAppIDMap web_contents_to_app_id_; |
| 494 | 484 |
| 495 // Used to track app windows. | 485 // Used to track app windows. |
| 496 std::vector<std::unique_ptr<AppWindowLauncherController>> | 486 std::vector<std::unique_ptr<AppWindowLauncherController>> |
| 497 app_window_controllers_; | 487 app_window_controllers_; |
| 498 | 488 |
| 499 // Used to get app info for tabs. | 489 // Used to get app info for tabs. |
| 500 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; | 490 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; |
| 501 | 491 |
| 502 // Used to load the images for app items. | 492 // Used to load the images for app items. |
| 503 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; | 493 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; |
| 504 | 494 |
| 505 // Used to handle app load/unload events. | 495 // Used to handle app load/unload events. |
| 506 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_; | 496 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_; |
| 507 | 497 |
| 508 PrefChangeRegistrar pref_change_registrar_; | 498 PrefChangeRegistrar pref_change_registrar_; |
| 509 | 499 |
| 510 AppSyncUIState* app_sync_ui_state_; | 500 AppSyncUIState* app_sync_ui_state_ = nullptr; |
| 511 | 501 |
| 512 // The owned browser status monitor. | 502 // The owned browser status monitor. |
| 513 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_; | 503 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_; |
| 514 | 504 |
| 515 // A special observer class to detect user switches. | 505 // A special observer class to detect user switches. |
| 516 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver> | 506 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver> |
| 517 user_switch_observer_; | 507 user_switch_observer_; |
| 518 | 508 |
| 519 std::unique_ptr<ash::ChromeLauncherPrefsObserver> prefs_observer_; | 509 std::unique_ptr<ash::launcher::ChromeLauncherPrefsObserver> prefs_observer_; |
| 520 | 510 |
| 521 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_; | 511 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_; |
| 522 | 512 |
| 523 // If true, incoming pinned state changes should be ignored. | 513 // If true, incoming pinned state changes should be ignored. |
| 524 bool ignore_persist_pinned_state_change_; | 514 bool ignore_persist_pinned_state_change_ = false; |
| 525 | 515 |
| 526 // The list of running & un-pinned applications for different users on hidden | 516 // The list of running & un-pinned applications for different users on hidden |
| 527 // desktops. | 517 // desktops. |
| 528 typedef std::vector<std::string> RunningAppListIds; | 518 typedef std::vector<std::string> RunningAppListIds; |
| 529 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; | 519 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; |
| 530 RunningAppListIdMap last_used_running_application_order_; | 520 RunningAppListIdMap last_used_running_application_order_; |
| 531 | 521 |
| 532 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | 522 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
| 533 }; | 523 }; |
| 534 | 524 |
| 535 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 525 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| OLD | NEW |