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

Side by Side Diff: chrome/browser/ui/views/apps/chrome_native_app_window_views.cc

Issue 2900783003: Handle app custom icon via aura::Window property. (Closed)
Patch Set: forgot to add test_app_window_observer.* Created 3 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/apps/chrome_native_app_window_views.h" 5 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "apps/ui/views/app_window_frame_view.h" 10 #include "apps/ui/views/app_window_frame_view.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/app_mode/app_mode_utils.h" 15 #include "chrome/browser/app_mode/app_mode_utils.h"
16 #include "chrome/browser/extensions/chrome_app_icon.h"
17 #include "chrome/browser/extensions/chrome_app_icon_service.h"
18 #include "chrome/browser/extensions/extension_util.h"
16 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
18 #include "components/favicon/content/content_favicon_driver.h" 21 #include "components/favicon/content/content_favicon_driver.h"
19 #include "components/zoom/page_zoom.h" 22 #include "components/zoom/page_zoom.h"
20 #include "components/zoom/zoom_controller.h" 23 #include "components/zoom/zoom_controller.h"
24 #include "extensions/browser/app_window/app_delegate.h"
25 #include "ui/gfx/image/image_skia_operations.h"
21 #include "ui/views/controls/webview/webview.h" 26 #include "ui/views/controls/webview/webview.h"
22 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
23 28
24 using extensions::AppWindow; 29 using extensions::AppWindow;
25 30
26 namespace { 31 namespace {
27 32
28 const int kMinPanelWidth = 100; 33 const int kMinPanelWidth = 100;
29 const int kMinPanelHeight = 100; 34 const int kMinPanelHeight = 100;
30 const int kDefaultPanelWidth = 200; 35 const int kDefaultPanelWidth = 200;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 247 }
243 248
244 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { 249 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const {
245 // TODO(jackhou): On Mac, only docked panels are always-on-top. 250 // TODO(jackhou): On Mac, only docked panels are always-on-top.
246 return app_window()->window_type_is_panel() || widget()->IsAlwaysOnTop(); 251 return app_window()->window_type_is_panel() || widget()->IsAlwaysOnTop();
247 } 252 }
248 253
249 // views::WidgetDelegate implementation. 254 // views::WidgetDelegate implementation.
250 255
251 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() { 256 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() {
252 gfx::Image app_icon = app_window()->app_icon(); 257 // Resulting icon is cached in aura::client::kAppIconKey window property.
253 if (app_icon.IsEmpty()) 258 const gfx::Image& custom_image = app_window()->custom_app_icon();
254 return GetWindowIcon(); 259 if (app_window()->app_icon_url().is_valid() &&
255 else 260 app_window()->show_in_shelf()) {
256 return *app_icon.ToImageSkia(); 261 EnsureAppIconCreated();
262 gfx::Image base_image =
263 !custom_image.IsEmpty()
264 ? custom_image
265 : gfx::Image(extensions::util::GetDefaultAppIcon());
266 // Scale the icon to EXTENSION_ICON_LARGE.
267 const int large_icon_size = extension_misc::EXTENSION_ICON_LARGE;
268 if (base_image.Width() != large_icon_size ||
269 base_image.Height() != large_icon_size) {
270 gfx::ImageSkia resized_image =
271 gfx::ImageSkiaOperations::CreateResizedImage(
272 base_image.AsImageSkia(), skia::ImageOperations::RESIZE_BEST,
273 gfx::Size(large_icon_size, large_icon_size));
274 return gfx::ImageSkiaOperations::CreateIconWithBadge(
275 resized_image, app_icon_->image_skia());
276 } else {
stevenjb 2017/05/25 22:25:20 nit: no else after return
khmel 2017/06/01 16:56:52 Done.
277 return gfx::ImageSkiaOperations::CreateIconWithBadge(
278 base_image.AsImageSkia(), app_icon_->image_skia());
279 }
280 }
281
282 if (!custom_image.IsEmpty())
283 return *custom_image.ToImageSkia();
284 EnsureAppIconCreated();
285 return app_icon_->image_skia();
257 } 286 }
258 287
259 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { 288 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() {
289 // Resulting icon is cached in aura::client::kWindowIconKey window property.
260 content::WebContents* web_contents = app_window()->web_contents(); 290 content::WebContents* web_contents = app_window()->web_contents();
261 if (web_contents) { 291 if (web_contents) {
262 favicon::FaviconDriver* favicon_driver = 292 favicon::FaviconDriver* favicon_driver =
263 favicon::ContentFaviconDriver::FromWebContents(web_contents); 293 favicon::ContentFaviconDriver::FromWebContents(web_contents);
264 gfx::Image app_icon = favicon_driver->GetFavicon(); 294 gfx::Image app_icon = favicon_driver->GetFavicon();
265 if (!app_icon.IsEmpty()) 295 if (!app_icon.IsEmpty())
266 return *app_icon.ToImageSkia(); 296 return *app_icon.ToImageSkia();
267 } 297 }
268 return gfx::ImageSkia(); 298 return gfx::ImageSkia();
269 } 299 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 InitializePanelWindow(create_params); 395 InitializePanelWindow(create_params);
366 } else { 396 } else {
367 InitializeDefaultWindow(create_params); 397 InitializeDefaultWindow(create_params);
368 } 398 }
369 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( 399 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
370 Profile::FromBrowserContext(app_window->browser_context()), 400 Profile::FromBrowserContext(app_window->browser_context()),
371 widget()->GetFocusManager(), 401 widget()->GetFocusManager(),
372 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, 402 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
373 NULL)); 403 NULL));
374 } 404 }
405
406 void ChromeNativeAppWindowViews::EnsureAppIconCreated() {
407 if (app_icon_ && app_icon_->IsValid())
408 return;
409
410 // To avoid recursive call reset smart pointer. It will be checked at
411 // OnIconUpdated to determine if this is real update or initial callback on
412 // icon creation.
413 app_icon_.reset();
414 app_icon_ =
415 extensions::ChromeAppIconService::Get(app_window()->browser_context())
416 ->CreateIcon(this, app_window()->extension_id(),
417 app_window()->app_delegate()->PreferredIconSize());
418 }
419
420 void ChromeNativeAppWindowViews::OnIconUpdated(
421 extensions::ChromeAppIcon* icon) {
422 if (!app_icon_)
423 return;
424 DCHECK_EQ(app_icon_.get(), icon);
425 UpdateWindowIcon();
426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698