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

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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return; // Maintained entirely by ChromeLauncherController. 287 return; // Maintained entirely by ChromeLauncherController.
295 288
296 if (!tab) 289 if (!tab)
297 return; // Assume the window is going to be closed if there are no tabs. 290 return; // Assume the window is going to be closed if there are no tabs.
298 291
299 int item_index = launcher_model()->ItemIndexByID(launcher_id()); 292 int item_index = launcher_model()->ItemIndexByID(launcher_id());
300 if (item_index == -1) 293 if (item_index == -1)
301 return; 294 return;
302 295
303 ash::LauncherItem item = launcher_model()->items()[item_index]; 296 ash::LauncherItem item = launcher_model()->items()[item_index];
304 if (type() == TYPE_EXTENSION_PANEL) { 297 DCHECK_EQ(TYPE_TABBED, type());
305 if (!favicon_loader_.get() || favicon_loader_->web_contents() != tab) 298 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
306 favicon_loader_.reset(new LauncherFaviconLoader(this, tab)); 299 FaviconTabHelper* favicon_tab_helper =
307 300 FaviconTabHelper::FromWebContents(tab);
308 // Update the icon for extension panels. 301 if (favicon_tab_helper->ShouldDisplayFavicon()) {
309 extensions::TabHelper* extensions_tab_helper = 302 item.image = favicon_tab_helper->GetFavicon().AsImageSkia();
310 extensions::TabHelper::FromWebContents(tab); 303 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); 304 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
335 } 305 }
306 } else {
307 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
336 } 308 }
337 launcher_model()->Set(item_index, item); 309 launcher_model()->Set(item_index, item);
338 } 310 }
339 311
340 void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) { 312 void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) {
341 ChromeLauncherController::AppState app_state; 313 ChromeLauncherController::AppState app_state;
342 314
343 if (!launcher_controller()->GetPerAppInterface() && 315 if (!launcher_controller()->GetPerAppInterface() &&
344 tab_model_->GetIndexOfWebContents(tab) == TabStripModel::kNoTab) { 316 tab_model_->GetIndexOfWebContents(tab) == TabStripModel::kNoTab) {
345 app_state = ChromeLauncherController::APP_STATE_REMOVED; 317 app_state = ChromeLauncherController::APP_STATE_REMOVED;
346 } else if (tab_model_->GetActiveWebContents() == tab) { 318 } else if (tab_model_->GetActiveWebContents() == tab) {
347 if (ash::wm::IsActiveWindow(window_)) 319 if (ash::wm::IsActiveWindow(window_))
348 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; 320 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
349 else 321 else
350 app_state = ChromeLauncherController::APP_STATE_ACTIVE; 322 app_state = ChromeLauncherController::APP_STATE_ACTIVE;
351 } else { 323 } else {
352 app_state = ChromeLauncherController::APP_STATE_INACTIVE; 324 app_state = ChromeLauncherController::APP_STATE_INACTIVE;
353 } 325 }
354 launcher_controller()->UpdateAppState(tab, app_state); 326 launcher_controller()->UpdateAppState(tab, app_state);
355 } 327 }
356 328
357 ash::LauncherModel* BrowserLauncherItemController::launcher_model() { 329 ash::LauncherModel* BrowserLauncherItemController::launcher_model() {
358 return launcher_controller()->model(); 330 return launcher_controller()->model();
359 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698