1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_ 7 8 #include <string> 9 10 #include "ash/launcher/launcher_types.h" 11 #include "base/basictypes.h" 12 #include "base/compiler_specific.h" 13 #include "base/gtest_prod_util.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/strings/string16.h" 16 #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" 17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 19 #include "ui/aura/window_observer.h" 20 21 class Browser; 22 23 namespace ash { 24 class LauncherModel; 25 } 26 27 // BrowserLauncherItemController is responsible for keeping the launcher 28 // representation of a window up to date as the active tab changes. 29 class BrowserLauncherItemController : public LauncherItemController, 30 public TabStripModelObserver, 31 public aura::WindowObserver { 32 public: 33 // This API is to be used as part of testing only. 34 class TestApi { 35 public: 36 explicit TestApi(BrowserLauncherItemController* controller) 37 : controller_(controller) {} 38 ~TestApi() {} 39 40 // Returns the launcher id for the browser window. 41 ash::LauncherID item_id() const { return controller_->launcher_id(); } 42 43 private: 44 BrowserLauncherItemController* controller_; 45 }; 46 47 BrowserLauncherItemController(Type type, 48 aura::Window* window, 49 TabStripModel* tab_model, 50 ChromeLauncherController* launcher_controller, 51 const std::string& app_id); 52 virtual ~BrowserLauncherItemController(); 53 54 // Overriding the app id for V1 apps. 55 virtual const std::string& app_id() const OVERRIDE; 56 57 // Sets up this BrowserLauncherItemController. 58 void Init(); 59 60 // Creates and returns a new BrowserLauncherItemController for |browser|. This 61 // returns NULL if a BrowserLauncherItemController is not needed for the 62 // specified browser. 63 static BrowserLauncherItemController* Create(Browser* browser); 64 65 // Call to indicate that the window the tabcontents are in has changed its 66 // activation state. 67 void BrowserActivationStateChanged(); 68 69 // LauncherItemController overrides: 70 virtual string16 GetTitle() OVERRIDE; 71 virtual bool HasWindow(aura::Window* window) const OVERRIDE; 72 virtual bool IsOpen() const OVERRIDE; 73 virtual bool IsVisible() const OVERRIDE; 74 virtual void Launch(int event_flags) OVERRIDE; 75 virtual void Activate() OVERRIDE; 76 virtual void Close() OVERRIDE; 77 virtual void Clicked(const ui::Event& event) OVERRIDE; 78 virtual void OnRemoved() OVERRIDE; 79 virtual void LauncherItemChanged(int index, 80 const ash::LauncherItem& old_item) OVERRIDE; 81 virtual ChromeLauncherAppMenuItems GetApplicationList( 82 int event_flags) OVERRIDE; 83 84 // TabStripModel overrides: 85 virtual void ActiveTabChanged(content::WebContents* old_contents, 86 content::WebContents* new_contents, 87 int index, 88 int reason) OVERRIDE; 89 virtual void TabInsertedAt(content::WebContents* contents, 90 int index, 91 bool foreground) OVERRIDE; 92 virtual void TabDetachedAt(content::WebContents* contents, 93 int index) OVERRIDE; 94 virtual void TabChangedAt( 95 content::WebContents* contents, 96 int index, 97 TabStripModelObserver::TabChangeType change_type) OVERRIDE; 98 virtual void TabReplacedAt(TabStripModel* tab_strip_model, 99 content::WebContents* old_contents, 100 content::WebContents* new_contents, 101 int index) OVERRIDE; 102 103 // aura::WindowObserver overrides: 104 virtual void OnWindowPropertyChanged(aura::Window* window, 105 const void* key, 106 intptr_t old) OVERRIDE; 107 108 private: 109 FRIEND_TEST_ALL_PREFIXES(BrowserLauncherItemControllerTest, PanelItem); 110 111 // Used to identify what an update corresponds to. 112 enum UpdateType { 113 UPDATE_TAB_REMOVED, 114 UPDATE_TAB_CHANGED, 115 UPDATE_TAB_INSERTED, 116 }; 117 118 // Updates the launcher item status base on the activation and attention 119 // state of the window. 120 void UpdateItemStatus(); 121 122 // Updates the launcher from |tab|. 123 void UpdateLauncher(content::WebContents* tab); 124 125 void UpdateAppState(content::WebContents* tab); 126 127 ash::LauncherModel* launcher_model(); 128 129 // Browser window we're in. 130 aura::Window* window_; 131 132 // If running a windowed V1 app with the new launcher, this (empty) app id 133 // will be returned by app_id(). 134 std::string empty_app_id_; 135 136 TabStripModel* tab_model_; 137 138 // Whether this is associated with an incognito profile. 139 const bool is_incognito_; 140 141 DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemController); 142 }; 143 144 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_ 145