OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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. |
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
Note: This entire controller should go. In a separ
simonhong_
2013/08/19 05:26:11
Yep!
I'll do it right after this CL is landing.
| |
4 | 4 |
5 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
13 #include "chrome/browser/favicon/favicon_tab_helper.h" | 13 #include "chrome/browser/favicon/favicon_tab_helper.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 return LauncherItemController::app_id(); | 58 return LauncherItemController::app_id(); |
59 } | 59 } |
60 | 60 |
61 void BrowserLauncherItemController::Init() { | 61 void BrowserLauncherItemController::Init() { |
62 tab_model_->AddObserver(this); | 62 tab_model_->AddObserver(this); |
63 ash::LauncherItemStatus app_status = | 63 ash::LauncherItemStatus app_status = |
64 ash::wm::IsActiveWindow(window_) ? | 64 ash::wm::IsActiveWindow(window_) ? |
65 ash::STATUS_ACTIVE : ash::STATUS_RUNNING; | 65 ash::STATUS_ACTIVE : ash::STATUS_RUNNING; |
66 if (type() != TYPE_TABBED && type() != TYPE_WINDOWED_APP) { | 66 if (type() != TYPE_TABBED && type() != TYPE_WINDOWED_APP) { |
67 launcher_controller()->CreateAppLauncherItem(this, app_id(), app_status); | 67 launcher_controller()->CreateAppLauncherItem(this, app_id(), app_status); |
68 } else { | 68 } else { |
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
} else if (..) {
}
simonhong_
2013/08/19 05:26:11
Done.
| |
69 launcher_controller()->CreateTabbedLauncherItem( | |
70 this, | |
71 is_incognito_ ? ChromeLauncherController::STATE_INCOGNITO : | |
72 ChromeLauncherController::STATE_NOT_INCOGNITO, | |
73 app_status); | |
74 if (type() == TYPE_WINDOWED_APP) | 69 if (type() == TYPE_WINDOWED_APP) |
75 launcher_controller()->LockV1AppWithID(LauncherItemController::app_id()); | 70 launcher_controller()->LockV1AppWithID(LauncherItemController::app_id()); |
76 } | 71 } |
77 // In testing scenarios we can get tab strips with no active contents. | 72 // In testing scenarios we can get tab strips with no active contents. |
78 if (tab_model_->active_index() != TabStripModel::kNoTab) | 73 if (tab_model_->active_index() != TabStripModel::kNoTab) |
79 UpdateLauncher(tab_model_->GetActiveWebContents()); | 74 UpdateLauncher(tab_model_->GetActiveWebContents()); |
80 } | 75 } |
81 | 76 |
82 // static | 77 // static |
83 BrowserLauncherItemController* BrowserLauncherItemController::Create( | 78 BrowserLauncherItemController* BrowserLauncherItemController::Create( |
84 Browser* browser) { | 79 Browser* browser) { |
85 // Under testing this can be called before the controller is created. | 80 // Under testing this can be called before the controller is created. |
86 if (!ChromeLauncherController::instance()) | 81 if (!ChromeLauncherController::instance()) |
87 return NULL; | 82 return NULL; |
88 | 83 |
89 Type type; | 84 Type type; |
90 std::string app_id; | 85 std::string app_id; |
91 if (browser->is_type_tabbed() || browser->is_type_popup()) { | 86 if (browser->is_type_tabbed() || browser->is_type_popup()) { |
92 type = TYPE_TABBED; | 87 type = TYPE_TABBED; |
93 if (!browser->is_type_tabbed() && | 88 if (!browser->is_type_tabbed() && |
94 browser->is_type_popup() && | 89 browser->is_type_popup() && |
95 browser->is_app() && | 90 browser->is_app()) { |
96 ChromeLauncherController::instance()->GetPerAppInterface()) { | |
97 app_id = web_app::GetExtensionIdFromApplicationName( | 91 app_id = web_app::GetExtensionIdFromApplicationName( |
98 browser->app_name()); | 92 browser->app_name()); |
99 // Only allow this for known applications. Some unit tests for example | 93 // Only allow this for known applications. Some unit tests for example |
100 // do not have one. | 94 // do not have one. |
101 if (!app_id.empty()) | 95 if (!app_id.empty()) |
102 type = TYPE_WINDOWED_APP; | 96 type = TYPE_WINDOWED_APP; |
103 } | 97 } |
104 } else if (browser->is_app()) { | 98 } else if (browser->is_app()) { |
105 type = TYPE_TABBED; | 99 type = TYPE_TABBED; |
106 app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name()); | 100 app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 Activate(); | 167 Activate(); |
174 } | 168 } |
175 } | 169 } |
176 | 170 |
177 void BrowserLauncherItemController::OnRemoved() { | 171 void BrowserLauncherItemController::OnRemoved() { |
178 } | 172 } |
179 | 173 |
180 void BrowserLauncherItemController::LauncherItemChanged( | 174 void BrowserLauncherItemController::LauncherItemChanged( |
181 int index, | 175 int index, |
182 const ash::LauncherItem& old_item) { | 176 const ash::LauncherItem& old_item) { |
183 if (!launcher_controller()->GetPerAppInterface() && | |
184 launcher_model()->items()[index].status == ash::STATUS_ACTIVE && | |
185 old_item.status == ash::STATUS_RUNNING) { | |
186 Activate(); | |
187 } | |
188 } | 177 } |
189 | 178 |
190 ChromeLauncherAppMenuItems | 179 ChromeLauncherAppMenuItems |
191 BrowserLauncherItemController::GetApplicationList(int event_flags) { | 180 BrowserLauncherItemController::GetApplicationList(int event_flags) { |
192 // This will never be called and the entire class will go away. | 181 // This will never be called and the entire class will go away. |
193 ChromeLauncherAppMenuItems items; | 182 ChromeLauncherAppMenuItems items; |
194 return items.Pass(); | 183 return items.Pass(); |
195 } | 184 } |
196 | 185 |
197 void BrowserLauncherItemController::ActiveTabChanged( | 186 void BrowserLauncherItemController::ActiveTabChanged( |
198 content::WebContents* old_contents, | 187 content::WebContents* old_contents, |
199 content::WebContents* new_contents, | 188 content::WebContents* new_contents, |
200 int index, | 189 int index, |
201 int reason) { | 190 int reason) { |
202 // Update immediately on a tab change. | 191 // Update immediately on a tab change. |
203 if (old_contents && | 192 if (old_contents && |
204 (!launcher_controller()->GetPerAppInterface() || | 193 TabStripModel::kNoTab != |
205 TabStripModel::kNoTab != | 194 tab_model_->GetIndexOfWebContents(old_contents)) |
206 tab_model_->GetIndexOfWebContents(old_contents))) | |
207 UpdateAppState(old_contents); | 195 UpdateAppState(old_contents); |
208 UpdateAppState(new_contents); | 196 UpdateAppState(new_contents); |
209 UpdateLauncher(new_contents); | 197 UpdateLauncher(new_contents); |
210 } | 198 } |
211 | 199 |
212 void BrowserLauncherItemController::TabInsertedAt( | 200 void BrowserLauncherItemController::TabInsertedAt( |
213 content::WebContents* contents, | 201 content::WebContents* contents, |
214 int index, | 202 int index, |
215 bool foreground) { | 203 bool foreground) { |
216 UpdateAppState(contents); | 204 UpdateAppState(contents); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 | 238 |
251 void BrowserLauncherItemController::OnWindowPropertyChanged( | 239 void BrowserLauncherItemController::OnWindowPropertyChanged( |
252 aura::Window* window, | 240 aura::Window* window, |
253 const void* key, | 241 const void* key, |
254 intptr_t old) { | 242 intptr_t old) { |
255 if (key == aura::client::kDrawAttentionKey) | 243 if (key == aura::client::kDrawAttentionKey) |
256 UpdateItemStatus(); | 244 UpdateItemStatus(); |
257 } | 245 } |
258 | 246 |
259 void BrowserLauncherItemController::UpdateItemStatus() { | 247 void BrowserLauncherItemController::UpdateItemStatus() { |
260 if (launcher_controller()->GetPerAppInterface()) | 248 return; |
261 return; | |
262 | |
263 ash::LauncherItemStatus status; | |
264 if (ash::wm::IsActiveWindow(window_)) { | |
265 // Clear attention state if active. | |
266 if (window_->GetProperty(aura::client::kDrawAttentionKey)) | |
267 window_->SetProperty(aura::client::kDrawAttentionKey, false); | |
268 status = ash::STATUS_ACTIVE; | |
269 } else if (window_->GetProperty(aura::client::kDrawAttentionKey)) { | |
270 status = ash::STATUS_ATTENTION; | |
271 } else { | |
272 status = ash::STATUS_RUNNING; | |
273 } | |
274 launcher_controller()->SetItemStatus(launcher_id(), status); | |
275 } | 249 } |
276 | 250 |
277 void BrowserLauncherItemController::UpdateLauncher(content::WebContents* tab) { | 251 void BrowserLauncherItemController::UpdateLauncher(content::WebContents* tab) { |
278 if (launcher_controller()->GetPerAppInterface()) | 252 return; |
279 return; | |
280 | |
281 if (type() == TYPE_APP_PANEL) | |
282 return; // Maintained entirely by ChromeLauncherController. | |
283 | |
284 if (!tab) | |
285 return; // Assume the window is going to be closed if there are no tabs. | |
286 | |
287 int item_index = launcher_model()->ItemIndexByID(launcher_id()); | |
288 if (item_index == -1) | |
289 return; | |
290 | |
291 ash::LauncherItem item = launcher_model()->items()[item_index]; | |
292 DCHECK_EQ(TYPE_TABBED, type()); | |
293 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
294 FaviconTabHelper* favicon_tab_helper = | |
295 FaviconTabHelper::FromWebContents(tab); | |
296 if (favicon_tab_helper->ShouldDisplayFavicon()) { | |
297 item.image = favicon_tab_helper->GetFavicon().AsImageSkia(); | |
298 if (item.image.isNull()) { | |
299 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); | |
300 } | |
301 } else { | |
302 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); | |
303 } | |
304 launcher_model()->Set(item_index, item); | |
305 } | 253 } |
306 | 254 |
307 void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) { | 255 void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) { |
308 ChromeLauncherController::AppState app_state; | 256 ChromeLauncherController::AppState app_state; |
309 | 257 |
310 if (!launcher_controller()->GetPerAppInterface() && | 258 if (tab_model_->GetActiveWebContents() == tab) { |
311 tab_model_->GetIndexOfWebContents(tab) == TabStripModel::kNoTab) { | |
312 app_state = ChromeLauncherController::APP_STATE_REMOVED; | |
313 } else if (tab_model_->GetActiveWebContents() == tab) { | |
314 if (ash::wm::IsActiveWindow(window_)) | 259 if (ash::wm::IsActiveWindow(window_)) |
315 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; | 260 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; |
316 else | 261 else |
317 app_state = ChromeLauncherController::APP_STATE_ACTIVE; | 262 app_state = ChromeLauncherController::APP_STATE_ACTIVE; |
318 } else { | 263 } else { |
319 app_state = ChromeLauncherController::APP_STATE_INACTIVE; | 264 app_state = ChromeLauncherController::APP_STATE_INACTIVE; |
320 } | 265 } |
321 launcher_controller()->UpdateAppState(tab, app_state); | 266 launcher_controller()->UpdateAppState(tab, app_state); |
322 } | 267 } |
323 | 268 |
324 ash::LauncherModel* BrowserLauncherItemController::launcher_model() { | 269 ash::LauncherModel* BrowserLauncherItemController::launcher_model() { |
325 return launcher_controller()->model(); | 270 return launcher_controller()->model(); |
326 } | 271 } |
OLD | NEW |