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

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 v5 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
« no previous file with comments | « extensions/browser/app_window/app_window.h ('k') | extensions/common/api/app_window.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..67c5019fed46c095e8be287eeb014e22f6758626 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) {
@@ -603,9 +616,23 @@ void AppWindow::UpdateDraggableRegions(
}
void AppWindow::UpdateAppIcon(const gfx::Image& image) {
- if (image.IsEmpty())
- return;
- app_icon_ = image;
+ // Set the showInShelf=true window icon and add the app_icon_image_
+ // as a badge. If the image is empty, set the default app icon placeholder
+ // as the base image.
+ if (window_icon_url_.is_valid() && !app_icon_image_->image().IsEmpty()) {
+ gfx::Image base_image =
+ !image.IsEmpty()
+ ? image
+ : gfx::Image(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_APP_DEFAULT_ICON));
+ app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge(
+ base_image.AsImageSkia(), app_icon_image_->image_skia()));
+ } else {
+ if (image.IsEmpty())
+ return;
+
+ app_icon_ = image;
+ }
native_app_window_->UpdateWindowIcon();
AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
}
@@ -814,8 +841,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.
« no previous file with comments | « extensions/browser/app_window/app_window.h ('k') | extensions/common/api/app_window.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698