Chromium Code Reviews| Index: chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc b/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| index a3d48e9b5f50bb135452f819c78e43821fab8358..b4f811941360be1520ed77ee3766d304b94c7af6 100644 |
| --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| @@ -13,11 +13,16 @@ |
| #include "build/build_config.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/app_mode/app_mode_utils.h" |
| +#include "chrome/browser/extensions/chrome_app_icon.h" |
| +#include "chrome/browser/extensions/chrome_app_icon_service.h" |
| +#include "chrome/browser/extensions/extension_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h" |
| #include "components/favicon/content/content_favicon_driver.h" |
| #include "components/zoom/page_zoom.h" |
| #include "components/zoom/zoom_controller.h" |
| +#include "extensions/browser/app_window/app_delegate.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| #include "ui/views/controls/webview/webview.h" |
| #include "ui/views/widget/widget.h" |
| @@ -249,11 +254,35 @@ bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { |
| // views::WidgetDelegate implementation. |
| gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() { |
| - gfx::Image app_icon = app_window()->app_icon(); |
| - if (app_icon.IsEmpty()) |
| - return GetWindowIcon(); |
| - else |
| - return *app_icon.ToImageSkia(); |
| + const gfx::Image& custom_image = app_window()->custom_app_icon(); |
|
msw
2017/05/23 00:02:29
Should the resulting icon be cached, if this funct
khmel
2017/05/23 16:11:44
Actually it is cached when a widget handles Update
msw
2017/05/23 17:17:40
Good to know, maybe mention that in a comment?
|
| + |
| + if (app_window()->app_icon_url().is_valid() && |
| + app_window()->show_in_shelf()) { |
|
msw
2017/05/23 00:02:29
Why does show_in_shelf matter here? It didn't in A
khmel
2017/05/23 16:11:44
This logic came from app_window.cc (with small ref
msw
2017/05/23 17:17:40
Hmm, it still seems odd to only load the app icon
khmel
2017/05/23 17:35:00
Base on this change history, Devlin might know mor
|
| + EnsureAppIconCreated(); |
| + gfx::Image base_image = |
| + !custom_image.IsEmpty() |
| + ? custom_image |
| + : gfx::Image(extensions::util::GetDefaultAppIcon()); |
| + // Scale the icon to EXTENSION_ICON_LARGE. |
| + const int large_icon_size = extension_misc::EXTENSION_ICON_LARGE; |
| + if (base_image.Width() != large_icon_size || |
| + base_image.Height() != large_icon_size) { |
| + gfx::ImageSkia resized_image = |
| + gfx::ImageSkiaOperations::CreateResizedImage( |
| + base_image.AsImageSkia(), skia::ImageOperations::RESIZE_BEST, |
| + gfx::Size(large_icon_size, large_icon_size)); |
| + return gfx::ImageSkiaOperations::CreateIconWithBadge( |
| + resized_image, app_icon_->image_skia()); |
| + } else { |
| + return gfx::ImageSkiaOperations::CreateIconWithBadge( |
| + base_image.AsImageSkia(), app_icon_->image_skia()); |
| + } |
| + } |
| + |
| + if (!custom_image.IsEmpty()) |
| + return *custom_image.ToImageSkia(); |
| + EnsureAppIconCreated(); |
| + return app_icon_->image_skia(); |
| } |
| gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { |
| @@ -372,3 +401,22 @@ void ChromeNativeAppWindowViews::InitializeWindow( |
| extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| NULL)); |
| } |
| + |
| +void ChromeNativeAppWindowViews::EnsureAppIconCreated() { |
| + if (app_icon_ && app_icon_->IsValid()) |
| + return; |
| + |
| + app_icon_.reset(); |
|
msw
2017/05/23 00:02:29
q: is this necessary right before an assignment?
khmel
2017/05/23 16:11:44
Note sure how to resolve this better. This is to a
msw
2017/05/23 17:17:40
What you have is probably fine with an explanatory
khmel
2017/05/23 17:35:00
Done.
|
| + app_icon_ = |
| + extensions::ChromeAppIconService::Get(app_window()->browser_context()) |
| + ->CreateIcon(this, app_window()->extension_id(), |
| + app_window()->app_delegate()->PreferredIconSize()); |
| +} |
| + |
| +void ChromeNativeAppWindowViews::OnIconUpdated( |
| + extensions::ChromeAppIcon* icon) { |
| + if (!app_icon_) |
| + return; |
| + DCHECK_EQ(app_icon_.get(), icon); |
| + UpdateWindowIcon(); |
| +} |