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

Unified Diff: extensions/browser/app_window/app_window.cc

Issue 2209053004: Enhance chrome.app.window API with icon property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review v4 Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/app_window/app_window.cc
diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc
index 7df3954b504836f2fd675079e95c4e3afa9bf122..6165861430e2ca780d654c6bf82e0ad3928b545e 100644
--- a/extensions/browser/app_window/app_window.cc
+++ b/extensions/browser/app_window/app_window.cc
@@ -57,6 +57,7 @@
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/keycodes/keyboard_codes.h"
+#include "ui/gfx/image/image_skia_operations.h"
#if !defined(OS_MACOSX)
#include "components/prefs/pref_service.h"
@@ -298,6 +299,7 @@ void AppWindow::Init(const GURL& url,
requested_alpha_enabled_ = new_params.alpha_enabled;
is_ime_window_ = params.is_ime_window;
show_in_shelf_ = params.show_in_shelf;
+ window_icon_url_ = params.window_icon_url;
AppWindowClient* app_window_client = AppWindowClient::Get();
native_app_window_.reset(
@@ -307,6 +309,17 @@ void AppWindow::Init(const GURL& url,
browser_context_, extension_id_, web_contents(), app_delegate_.get()));
UpdateExtensionAppIcon();
+ // Download showInShelf=true window icon.
+ if (window_icon_url_.is_valid()) {
+ image_loader_ptr_factory_.InvalidateWeakPtrs();
+ web_contents()->DownloadImage(
+ window_icon_url_,
+ true, // is a favicon
+ 0, // no maximum size
+ false, // normal cache policy
+ base::Bind(&AppWindow::DidDownloadFavicon,
+ image_loader_ptr_factory_.GetWeakPtr()));
+ }
AppWindowRegistry::Get(browser_context_)->AddAppWindow(this);
if (new_params.hidden) {
@@ -605,7 +618,22 @@ void AppWindow::UpdateDraggableRegions(
void AppWindow::UpdateAppIcon(const gfx::Image& image) {
if (image.IsEmpty())
return;
- app_icon_ = image;
+ if (window_icon_url_.is_valid() && !app_icon_image_->image().IsEmpty()) {
+ app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge(
+ image.AsImageSkia(), app_icon_image_->image_skia()));
+ // Set default app icon placeholder with app_icon_image_ badge if
+ // the icon is empty.
+ if (app_icon_.IsEmpty()) {
stevenjb 2016/08/10 16:58:47 This will never happen since we already checked th
Andra Paraschiv 2016/08/11 07:20:55 Right, thank you for this, updated the CL.
+ image_loader_ptr_factory_.InvalidateWeakPtrs();
+ gfx::ImageSkia app_default_icon =
+ *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_APP_DEFAULT_ICON);
+ app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge(
+ app_default_icon, app_icon_image_->image_skia()));
+ }
+ } else {
+ app_icon_ = image;
+ }
native_app_window_->UpdateWindowIcon();
AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
}
@@ -814,8 +842,10 @@ void AppWindow::DidDownloadFavicon(
const GURL& image_url,
const std::vector<SkBitmap>& bitmaps,
const std::vector<gfx::Size>& original_bitmap_sizes) {
- if (image_url != app_icon_url_ || bitmaps.empty())
+ if (((image_url != app_icon_url_) && (image_url != window_icon_url_)) ||
+ bitmaps.empty()) {
return;
+ }
// Bitmaps are ordered largest to smallest. Choose the smallest bitmap
// whose height >= the preferred size.

Powered by Google App Engine
This is Rietveld 408576698