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

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: fix mac compile 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
« no previous file with comments | « chrome/browser/ui/views/apps/chrome_native_app_window_views.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 248 }
244 249
245 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { 250 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const {
246 // TODO(jackhou): On Mac, only docked panels are always-on-top. 251 // TODO(jackhou): On Mac, only docked panels are always-on-top.
247 return app_window()->window_type_is_panel() || widget()->IsAlwaysOnTop(); 252 return app_window()->window_type_is_panel() || widget()->IsAlwaysOnTop();
248 } 253 }
249 254
250 // views::WidgetDelegate implementation. 255 // views::WidgetDelegate implementation.
251 256
252 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() { 257 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() {
253 gfx::Image app_icon = app_window()->app_icon(); 258 // Resulting icon is cached in aura::client::kAppIconKey window property.
254 if (app_icon.IsEmpty()) 259 const gfx::Image& custom_image = app_window()->custom_app_icon();
255 return GetWindowIcon(); 260 if (app_window()->app_icon_url().is_valid() &&
256 else 261 app_window()->show_in_shelf()) {
257 return *app_icon.ToImageSkia(); 262 EnsureAppIconCreated();
263 gfx::Image base_image =
264 !custom_image.IsEmpty()
265 ? custom_image
266 : gfx::Image(extensions::util::GetDefaultAppIcon());
267 // Scale the icon to EXTENSION_ICON_LARGE.
268 const int large_icon_size = extension_misc::EXTENSION_ICON_LARGE;
269 if (base_image.Width() != large_icon_size ||
270 base_image.Height() != large_icon_size) {
271 gfx::ImageSkia resized_image =
272 gfx::ImageSkiaOperations::CreateResizedImage(
273 base_image.AsImageSkia(), skia::ImageOperations::RESIZE_BEST,
274 gfx::Size(large_icon_size, large_icon_size));
275 return gfx::ImageSkiaOperations::CreateIconWithBadge(
276 resized_image, app_icon_->image_skia());
277 }
278 return gfx::ImageSkiaOperations::CreateIconWithBadge(
279 base_image.AsImageSkia(), app_icon_->image_skia());
280 }
281
282 if (!custom_image.IsEmpty())
283 return *custom_image.ToImageSkia();
284 EnsureAppIconCreated();
285 return app_icon_->image_skia();
258 } 286 }
259 287
260 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { 288 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() {
289 // Resulting icon is cached in aura::client::kWindowIconKey window property.
261 content::WebContents* web_contents = app_window()->web_contents(); 290 content::WebContents* web_contents = app_window()->web_contents();
262 if (web_contents) { 291 if (web_contents) {
263 favicon::FaviconDriver* favicon_driver = 292 favicon::FaviconDriver* favicon_driver =
264 favicon::ContentFaviconDriver::FromWebContents(web_contents); 293 favicon::ContentFaviconDriver::FromWebContents(web_contents);
265 gfx::Image app_icon = favicon_driver->GetFavicon(); 294 gfx::Image app_icon = favicon_driver->GetFavicon();
266 if (!app_icon.IsEmpty()) 295 if (!app_icon.IsEmpty())
267 return *app_icon.ToImageSkia(); 296 return *app_icon.ToImageSkia();
268 } 297 }
269 return gfx::ImageSkia(); 298 return gfx::ImageSkia();
270 } 299 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 InitializePanelWindow(create_params); 388 InitializePanelWindow(create_params);
360 } else { 389 } else {
361 InitializeDefaultWindow(create_params); 390 InitializeDefaultWindow(create_params);
362 } 391 }
363 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( 392 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
364 Profile::FromBrowserContext(app_window->browser_context()), 393 Profile::FromBrowserContext(app_window->browser_context()),
365 widget()->GetFocusManager(), 394 widget()->GetFocusManager(),
366 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, 395 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
367 NULL)); 396 NULL));
368 } 397 }
398
399 void ChromeNativeAppWindowViews::EnsureAppIconCreated() {
400 if (app_icon_ && app_icon_->IsValid())
401 return;
402
403 // To avoid recursive call, reset the smart pointer. It will be checked in
404 // OnIconUpdated to determine if this is a real update or the initial callback
405 // on icon creation.
406 app_icon_.reset();
407 app_icon_ =
408 extensions::ChromeAppIconService::Get(app_window()->browser_context())
409 ->CreateIcon(this, app_window()->extension_id(),
410 app_window()->app_delegate()->PreferredIconSize());
411 }
412
413 void ChromeNativeAppWindowViews::OnIconUpdated(
414 extensions::ChromeAppIcon* icon) {
415 if (!app_icon_)
416 return;
417 DCHECK_EQ(app_icon_.get(), icon);
418 UpdateWindowIcon();
419 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/apps/chrome_native_app_window_views.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698