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

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

Issue 13139004: Deprecate Browser::TYPE_PANEL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
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.
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"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 browser->is_app() && 97 browser->is_app() &&
98 ChromeLauncherController::instance()->GetPerAppInterface()) { 98 ChromeLauncherController::instance()->GetPerAppInterface()) {
99 app_id = web_app::GetExtensionIdFromApplicationName( 99 app_id = web_app::GetExtensionIdFromApplicationName(
100 browser->app_name()); 100 browser->app_name());
101 // Only allow this for known applications. Some unit tests for example 101 // Only allow this for known applications. Some unit tests for example
102 // do not have one. 102 // do not have one.
103 if (!app_id.empty()) 103 if (!app_id.empty())
104 type = TYPE_WINDOWED_APP; 104 type = TYPE_WINDOWED_APP;
105 } 105 }
106 } else if (browser->is_app()) { 106 } else if (browser->is_app()) {
107 if (browser->is_type_panel()) { 107 type = TYPE_TABBED;
108 if (browser->app_type() == Browser::APP_TYPE_CHILD)
109 type = TYPE_EXTENSION_PANEL;
110 else
111 type = TYPE_APP_PANEL;
112 } else {
113 type = TYPE_TABBED;
114 }
115 app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name()); 108 app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name());
116 } else { 109 } else {
117 return NULL; 110 return NULL;
118 } 111 }
119 BrowserLauncherItemController* controller = 112 BrowserLauncherItemController* controller =
120 new BrowserLauncherItemController(type, 113 new BrowserLauncherItemController(type,
121 browser->window()->GetNativeWindow(), 114 browser->window()->GetNativeWindow(),
122 browser->tab_strip_model(), 115 browser->tab_strip_model(),
123 ChromeLauncherController::instance(), 116 ChromeLauncherController::instance(),
124 app_id); 117 app_id);
125 controller->Init(); 118 controller->Init();
126 return controller; 119 return controller;
127 } 120 }
128 121
129 void BrowserLauncherItemController::BrowserActivationStateChanged() { 122 void BrowserLauncherItemController::BrowserActivationStateChanged() {
130 content::WebContents* active_contents = tab_model_->GetActiveWebContents(); 123 content::WebContents* active_contents = tab_model_->GetActiveWebContents();
131 if (active_contents) 124 if (active_contents)
132 UpdateAppState(active_contents); 125 UpdateAppState(active_contents);
133 UpdateItemStatus(); 126 UpdateItemStatus();
134 } 127 }
135 128
136 string16 BrowserLauncherItemController::GetTitle() { 129 string16 BrowserLauncherItemController::GetTitle() {
137 if (type() == TYPE_TABBED || type() == TYPE_EXTENSION_PANEL) { 130 if (type() == TYPE_TABBED) {
138 if (tab_model_->active_index() != TabStripModel::kNoTab) { 131 if (tab_model_->active_index() != TabStripModel::kNoTab) {
139 const content::WebContents* contents = tab_model_->GetActiveWebContents(); 132 const content::WebContents* contents = tab_model_->GetActiveWebContents();
140 if (contents) 133 if (contents)
141 return contents->GetTitle(); 134 return contents->GetTitle();
142 } 135 }
143 } 136 }
144 return GetAppTitle(); 137 return GetAppTitle();
145 } 138 }
146 139
147 bool BrowserLauncherItemController::HasWindow(aura::Window* window) const { 140 bool BrowserLauncherItemController::HasWindow(aura::Window* window) const {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 TabStripModel* tab_strip_model, 242 TabStripModel* tab_strip_model,
250 content::WebContents* old_contents, 243 content::WebContents* old_contents,
251 content::WebContents* new_contents, 244 content::WebContents* new_contents,
252 int index) { 245 int index) {
253 launcher_controller()->UpdateAppState( 246 launcher_controller()->UpdateAppState(
254 old_contents, 247 old_contents,
255 ChromeLauncherController::APP_STATE_REMOVED); 248 ChromeLauncherController::APP_STATE_REMOVED);
256 UpdateAppState(new_contents); 249 UpdateAppState(new_contents);
257 } 250 }
258 251
259 void BrowserLauncherItemController::FaviconUpdated() {
260 UpdateLauncher(tab_model_->GetActiveWebContents());
261 }
262
263 void BrowserLauncherItemController::OnWindowPropertyChanged( 252 void BrowserLauncherItemController::OnWindowPropertyChanged(
264 aura::Window* window, 253 aura::Window* window,
265 const void* key, 254 const void* key,
266 intptr_t old) { 255 intptr_t old) {
267 if (key == aura::client::kDrawAttentionKey) 256 if (key == aura::client::kDrawAttentionKey)
268 UpdateItemStatus(); 257 UpdateItemStatus();
269 } 258 }
270 259
271 void BrowserLauncherItemController::UpdateItemStatus() { 260 void BrowserLauncherItemController::UpdateItemStatus() {
272 if (launcher_controller()->GetPerAppInterface()) 261 if (launcher_controller()->GetPerAppInterface())
(...skipping 21 matching lines...) Expand all
294 return; // Maintained entirely by ChromeLauncherController. 283 return; // Maintained entirely by ChromeLauncherController.
295 284
296 if (!tab) 285 if (!tab)
297 return; // Assume the window is going to be closed if there are no tabs. 286 return; // Assume the window is going to be closed if there are no tabs.
298 287
299 int item_index = launcher_model()->ItemIndexByID(launcher_id()); 288 int item_index = launcher_model()->ItemIndexByID(launcher_id());
300 if (item_index == -1) 289 if (item_index == -1)
301 return; 290 return;
302 291
303 ash::LauncherItem item = launcher_model()->items()[item_index]; 292 ash::LauncherItem item = launcher_model()->items()[item_index];
304 if (type() == TYPE_EXTENSION_PANEL) { 293 DCHECK_EQ(TYPE_TABBED, type());
305 if (!favicon_loader_.get() || favicon_loader_->web_contents() != tab) 294 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
306 favicon_loader_.reset(new LauncherFaviconLoader(this, tab)); 295 FaviconTabHelper* favicon_tab_helper =
307 296 FaviconTabHelper::FromWebContents(tab);
308 // Update the icon for extension panels. 297 if (favicon_tab_helper->ShouldDisplayFavicon()) {
309 extensions::TabHelper* extensions_tab_helper = 298 item.image = favicon_tab_helper->GetFavicon().AsImageSkia();
310 extensions::TabHelper::FromWebContents(tab); 299 if (item.image.isNull()) {
311 gfx::ImageSkia new_image = gfx::ImageSkia::CreateFrom1xBitmap(
312 favicon_loader_->GetFavicon());
313 if (new_image.isNull() && extensions_tab_helper->GetExtensionAppIcon()) {
314 new_image = gfx::ImageSkia::CreateFrom1xBitmap(
315 *extensions_tab_helper->GetExtensionAppIcon());
316 }
317 // Only update the icon if we have a new image, or none has been set yet.
318 // This avoids flickering to an empty image when a pinned app is opened.
319 if (!new_image.isNull())
320 item.image = new_image;
321 else if (item.image.isNull())
322 item.image = extensions::IconsInfo::GetDefaultAppIcon();
323 } else {
324 DCHECK_EQ(TYPE_TABBED, type());
325 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
326 FaviconTabHelper* favicon_tab_helper =
327 FaviconTabHelper::FromWebContents(tab);
328 if (favicon_tab_helper->ShouldDisplayFavicon()) {
329 item.image = favicon_tab_helper->GetFavicon().AsImageSkia();
330 if (item.image.isNull()) {
331 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
332 }
333 } else {
334 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 300 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
335 } 301 }
302 } else {
303 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
336 } 304 }
337 launcher_model()->Set(item_index, item); 305 launcher_model()->Set(item_index, item);
338 } 306 }
339 307
340 void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) { 308 void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) {
341 ChromeLauncherController::AppState app_state; 309 ChromeLauncherController::AppState app_state;
342 310
343 if (!launcher_controller()->GetPerAppInterface() && 311 if (!launcher_controller()->GetPerAppInterface() &&
344 tab_model_->GetIndexOfWebContents(tab) == TabStripModel::kNoTab) { 312 tab_model_->GetIndexOfWebContents(tab) == TabStripModel::kNoTab) {
345 app_state = ChromeLauncherController::APP_STATE_REMOVED; 313 app_state = ChromeLauncherController::APP_STATE_REMOVED;
346 } else if (tab_model_->GetActiveWebContents() == tab) { 314 } else if (tab_model_->GetActiveWebContents() == tab) {
347 if (ash::wm::IsActiveWindow(window_)) 315 if (ash::wm::IsActiveWindow(window_))
348 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; 316 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
349 else 317 else
350 app_state = ChromeLauncherController::APP_STATE_ACTIVE; 318 app_state = ChromeLauncherController::APP_STATE_ACTIVE;
351 } else { 319 } else {
352 app_state = ChromeLauncherController::APP_STATE_INACTIVE; 320 app_state = ChromeLauncherController::APP_STATE_INACTIVE;
353 } 321 }
354 launcher_controller()->UpdateAppState(tab, app_state); 322 launcher_controller()->UpdateAppState(tab, app_state);
355 } 323 }
356 324
357 ash::LauncherModel* BrowserLauncherItemController::launcher_model() { 325 ash::LauncherModel* BrowserLauncherItemController::launcher_model() {
358 return launcher_controller()->model(); 326 return launcher_controller()->model();
359 } 327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698