Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_status_monitor.cc

Issue 23534022: Handling browser item status in BrowserShortcutLauncherItemController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/window_util.h" 8 #include "ash/wm/window_util.h"
9 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/web_applications/web_app.h" 16 #include "chrome/browser/web_applications/web_app.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 18 #include "content/public/browser/web_contents_view.h"
18 #include "ui/aura/client/activation_client.h" 19 #include "ui/aura/client/activation_client.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 65
65 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active, 66 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active,
66 aura::Window* lost_active) { 67 aura::Window* lost_active) {
67 Browser* browser = chrome::FindBrowserWithWindow(lost_active); 68 Browser* browser = chrome::FindBrowserWithWindow(lost_active);
68 content::WebContents* active_contents = NULL; 69 content::WebContents* active_contents = NULL;
69 70
70 if (browser) { 71 if (browser) {
71 active_contents = browser->tab_strip_model()->GetActiveWebContents(); 72 active_contents = browser->tab_strip_model()->GetActiveWebContents();
72 if (active_contents) 73 if (active_contents)
73 UpdateAppState(active_contents); 74 UpdateAppState(active_contents);
75 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
Mr4D (OOO till 08-26) 2013/09/04 15:12:33 Coincidentally the "UpdateAppState" goes hand in h
simonhong_ 2013/09/04 17:08:31 Yes, it can call by UpdateAppState() and it has sa
Mr4D (OOO till 08-26) 2013/09/05 23:30:13 You misunderstood - I was wondering why UpdateAppS
simonhong_ 2013/09/06 00:40:02 Ah.. your concern is why UpdateAppState() and Upda
Mr4D (OOO till 08-26) 2013/09/06 16:11:12 For line 75 / 83: An if .. else .. could resolve t
simonhong_ 2013/09/06 18:52:57 Done.
74 } 76 }
75 77
76 browser = chrome::FindBrowserWithWindow(gained_active); 78 browser = chrome::FindBrowserWithWindow(gained_active);
77 if (browser) { 79 if (browser) {
78 active_contents = browser->tab_strip_model()->GetActiveWebContents(); 80 active_contents = browser->tab_strip_model()->GetActiveWebContents();
79 if (active_contents) 81 if (active_contents)
80 UpdateAppState(active_contents); 82 UpdateAppState(active_contents);
83 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
81 } 84 }
82 } 85 }
83 86
84 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { 87 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) {
85 // Remove RootWindow and its ActivationClient from observed list. 88 // Remove RootWindow and its ActivationClient from observed list.
86 observed_root_windows_.Remove(window); 89 observed_root_windows_.Remove(window);
87 observed_activation_clients_.Remove(aura::client::GetActivationClient( 90 observed_activation_clients_.Remove(aura::client::GetActivationClient(
88 static_cast<aura::RootWindow*>(window))); 91 static_cast<aura::RootWindow*>(window)));
89 } 92 }
90 93
91 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) { 94 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) {
92 browser->tab_strip_model()->AddObserver(this); 95 browser->tab_strip_model()->AddObserver(this);
93 96
94 if (browser->is_type_popup() && browser->is_app()) { 97 if (browser->is_type_popup() && browser->is_app()) {
95 std::string app_id = 98 std::string app_id =
96 web_app::GetExtensionIdFromApplicationName(browser->app_name()); 99 web_app::GetExtensionIdFromApplicationName(browser->app_name());
97 if (!app_id.empty()) { 100 if (!app_id.empty()) {
98 browser_to_app_id_map_[browser] = app_id; 101 browser_to_app_id_map_[browser] = app_id;
99 launcher_controller_->LockV1AppWithID(app_id); 102 launcher_controller_->LockV1AppWithID(app_id);
100 } 103 }
101 } 104 }
105 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
102 } 106 }
103 107
104 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { 108 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
105 browser->tab_strip_model()->RemoveObserver(this); 109 browser->tab_strip_model()->RemoveObserver(this);
106 110
107 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { 111 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) {
108 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); 112 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]);
109 browser_to_app_id_map_.erase(browser); 113 browser_to_app_id_map_.erase(browser);
110 } 114 }
111 launcher_controller_->UpdateBrowserItemStatus(); 115 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
112 } 116 }
113 117
114 void BrowserStatusMonitor::OnDisplayBoundsChanged( 118 void BrowserStatusMonitor::OnDisplayBoundsChanged(
115 const gfx::Display& display) { 119 const gfx::Display& display) {
116 // Do nothing here. 120 // Do nothing here.
117 } 121 }
118 122
119 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) { 123 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) {
120 // Add a new RootWindow and its ActivationClient to observed list. 124 // Add a new RootWindow and its ActivationClient to observed list.
121 aura::RootWindow* root_window = ash::Shell::GetInstance()-> 125 aura::RootWindow* root_window = ash::Shell::GetInstance()->
(...skipping 17 matching lines...) Expand all
139 if (old_contents) 143 if (old_contents)
140 browser = chrome::FindBrowserWithWebContents(old_contents); 144 browser = chrome::FindBrowserWithWebContents(old_contents);
141 145
142 // Update immediately on a tab change. 146 // Update immediately on a tab change.
143 if (browser && 147 if (browser &&
144 (TabStripModel::kNoTab != 148 (TabStripModel::kNoTab !=
145 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) 149 browser->tab_strip_model()->GetIndexOfWebContents(old_contents)))
146 UpdateAppState(old_contents); 150 UpdateAppState(old_contents);
147 151
148 UpdateAppState(new_contents); 152 UpdateAppState(new_contents);
153 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
149 } 154 }
150 155
151 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents, 156 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents,
152 int index, 157 int index,
153 bool foreground) { 158 bool foreground) {
154 UpdateAppState(contents); 159 UpdateAppState(contents);
160 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
155 } 161 }
156 162
157 void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents, 163 void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents,
158 int index) { 164 int index) {
159 launcher_controller_->UpdateAppState( 165 launcher_controller_->UpdateAppState(
160 contents, ChromeLauncherController::APP_STATE_REMOVED); 166 contents, ChromeLauncherController::APP_STATE_REMOVED);
167 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
161 } 168 }
162 169
163 void BrowserStatusMonitor::TabChangedAt( 170 void BrowserStatusMonitor::TabChangedAt(
164 content::WebContents* contents, 171 content::WebContents* contents,
165 int index, 172 int index,
166 TabStripModelObserver::TabChangeType change_type) { 173 TabStripModelObserver::TabChangeType change_type) {
167 UpdateAppState(contents); 174 UpdateAppState(contents);
175 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
168 } 176 }
169 177
170 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model, 178 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model,
171 content::WebContents* old_contents, 179 content::WebContents* old_contents,
172 content::WebContents* new_contents, 180 content::WebContents* new_contents,
173 int index) { 181 int index) {
174 launcher_controller_->UpdateAppState( 182 launcher_controller_->UpdateAppState(
175 old_contents, 183 old_contents,
176 ChromeLauncherController::APP_STATE_REMOVED); 184 ChromeLauncherController::APP_STATE_REMOVED);
177 UpdateAppState(new_contents); 185 UpdateAppState(new_contents);
186 GetBrowserShortcutLauncherItemController()->UpdateBrowserItemStatus();
178 } 187 }
179 188
180 void BrowserStatusMonitor::UpdateAppState(content::WebContents* contents) { 189 void BrowserStatusMonitor::UpdateAppState(content::WebContents* contents) {
181 if (!contents) 190 if (!contents)
182 return; 191 return;
183 192
184 ChromeLauncherController::AppState app_state = 193 ChromeLauncherController::AppState app_state =
185 ChromeLauncherController::APP_STATE_INACTIVE; 194 ChromeLauncherController::APP_STATE_INACTIVE;
186 195
187 Browser* browser = chrome::FindBrowserWithWebContents(contents); 196 Browser* browser = chrome::FindBrowserWithWebContents(contents);
188 if (browser->tab_strip_model()->GetActiveWebContents() == contents) { 197 if (browser->tab_strip_model()->GetActiveWebContents() == contents) {
189 if (browser->window()->IsActive()) 198 if (browser->window()->IsActive())
190 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; 199 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
191 else 200 else
192 app_state = ChromeLauncherController::APP_STATE_ACTIVE; 201 app_state = ChromeLauncherController::APP_STATE_ACTIVE;
193 } 202 }
194 203
195 launcher_controller_->UpdateAppState(contents, app_state); 204 launcher_controller_->UpdateAppState(contents, app_state);
196 } 205 }
206
207 BrowserShortcutLauncherItemController*
208 BrowserStatusMonitor::GetBrowserShortcutLauncherItemController() {
Mr4D (OOO till 08-26) 2013/09/04 15:12:33 You need this function only to get access to the "
simonhong_ 2013/09/04 17:08:31 Same reason as above comments. This class is just
Mr4D (OOO till 08-26) 2013/09/05 23:30:13 You have misunderstood: void BrowserStatusMonitor
simonhong_ 2013/09/06 00:40:02 Ah.. I made ugly code.. Done.
209 return launcher_controller_->GetBrowserShortcutLauncherItemController();
210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698