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

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_window.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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ash/launcher/arc_app_window.h" 5 #include "chrome/browser/ui/ash/launcher/arc_app_window.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" 8 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h"
9 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 9 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
10 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 10 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
11 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h" 11 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h"
12 #include "components/exo/shell_surface.h" 12 #include "components/exo/shell_surface.h"
13 #include "extensions/common/constants.h" 13 #include "extensions/common/constants.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/gfx/codec/png_codec.h" 15 #include "ui/gfx/codec/png_codec.h"
16 #include "ui/gfx/image/image_skia_operations.h" 16 #include "ui/gfx/image/image_skia_operations.h"
17 #include "ui/views/widget/native_widget_aura.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 19
19 ArcAppWindow::ArcAppWindow(int task_id, 20 ArcAppWindow::ArcAppWindow(int task_id,
20 const arc::ArcAppShelfId& app_shelf_id, 21 const arc::ArcAppShelfId& app_shelf_id,
21 views::Widget* widget, 22 views::Widget* widget,
22 ArcAppWindowLauncherController* owner) 23 ArcAppWindowLauncherController* owner)
23 : task_id_(task_id), 24 : task_id_(task_id),
24 app_shelf_id_(app_shelf_id), 25 app_shelf_id_(app_shelf_id),
25 widget_(widget), 26 widget_(widget),
26 owner_(owner) {} 27 owner_(owner) {}
27 28
28 ArcAppWindow::~ArcAppWindow() { 29 ArcAppWindow::~ArcAppWindow() {
29 ImageDecoder::Cancel(this); 30 ImageDecoder::Cancel(this);
30 } 31 }
31 32
32 void ArcAppWindow::SetController( 33 void ArcAppWindow::SetController(
33 ArcAppWindowLauncherItemController* controller) { 34 ArcAppWindowLauncherItemController* controller) {
34 DCHECK(!controller_ || !controller); 35 DCHECK(!controller_ || !controller);
35 controller_ = controller; 36 controller_ = controller;
36 if (controller_)
37 controller_->UpdateLauncherItem();
38 } 37 }
39 38
40 void ArcAppWindow::SetFullscreenMode(FullScreenMode mode) { 39 void ArcAppWindow::SetFullscreenMode(FullScreenMode mode) {
41 DCHECK(mode != FullScreenMode::NOT_DEFINED); 40 DCHECK(mode != FullScreenMode::NOT_DEFINED);
42 fullscreen_mode_ = mode; 41 fullscreen_mode_ = mode;
43 } 42 }
44 43
45 void ArcAppWindow::SetDescription( 44 void ArcAppWindow::SetDescription(
46 const std::string& title, 45 const std::string& title,
47 const std::vector<uint8_t>& unsafe_icon_data_png) { 46 const std::vector<uint8_t>& unsafe_icon_data_png) {
48 if (!title.empty()) 47 if (!title.empty())
49 GetNativeWindow()->SetTitle(base::UTF8ToUTF16(title)); 48 GetNativeWindow()->SetTitle(base::UTF8ToUTF16(title));
50 ImageDecoder::Cancel(this); 49 ImageDecoder::Cancel(this);
51 if (unsafe_icon_data_png.empty()) { 50 if (unsafe_icon_data_png.empty()) {
52 ResetIcon(); 51 SetIcon(gfx::ImageSkia());
53 return; 52 return;
54 } 53 }
55 54
56 if (ArcAppIcon::IsSafeDecodingDisabledForTesting()) { 55 if (ArcAppIcon::IsSafeDecodingDisabledForTesting()) {
57 SkBitmap bitmap; 56 SkBitmap bitmap;
58 if (gfx::PNGCodec::Decode(&unsafe_icon_data_png[0], 57 if (gfx::PNGCodec::Decode(&unsafe_icon_data_png[0],
59 unsafe_icon_data_png.size(), &bitmap)) { 58 unsafe_icon_data_png.size(), &bitmap)) {
60 OnImageDecoded(bitmap); 59 OnImageDecoded(bitmap);
61 } else { 60 } else {
62 OnDecodeImageFailed(); 61 OnDecodeImageFailed();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 149
151 bool ArcAppWindow::IsAlwaysOnTop() const { 150 bool ArcAppWindow::IsAlwaysOnTop() const {
152 NOTREACHED(); 151 NOTREACHED();
153 return false; 152 return false;
154 } 153 }
155 154
156 void ArcAppWindow::SetAlwaysOnTop(bool always_on_top) { 155 void ArcAppWindow::SetAlwaysOnTop(bool always_on_top) {
157 NOTREACHED(); 156 NOTREACHED();
158 } 157 }
159 158
160 void ArcAppWindow::ResetIcon() { 159 void ArcAppWindow::SetIcon(const gfx::ImageSkia& icon) {
161 if (icon_.isNull()) 160 if (!exo::ShellSurface::GetMainSurface(GetNativeWindow())) {
161 // Support unit tests where we don't have exo system initialized.
162 views::NativeWidgetAura::AssignIconToAuraWindow(
163 GetNativeWindow(), gfx::ImageSkia() /* window_icon */,
164 icon /* app_icon */);
162 return; 165 return;
163 icon_ = gfx::ImageSkia(); 166 }
164 if (controller_) 167 exo::ShellSurface* shell_surface = static_cast<exo::ShellSurface*>(
165 controller_->UpdateLauncherItem(); 168 widget_->widget_delegate()->GetContentsView());
169 if (!shell_surface)
170 return;
171 shell_surface->SetIcon(icon);
166 } 172 }
167 173
168 void ArcAppWindow::OnImageDecoded(const SkBitmap& decoded_image) { 174 void ArcAppWindow::OnImageDecoded(const SkBitmap& decoded_image) {
169 // TODO(khmel): Use aura::Window property http://crbug.com/724292 175 SetIcon(gfx::ImageSkiaOperations::CreateResizedImage(
170 icon_ = gfx::ImageSkiaOperations::CreateResizedImage(
171 gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)), 176 gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)),
172 skia::ImageOperations::RESIZE_BEST, 177 skia::ImageOperations::RESIZE_BEST,
173 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, 178 gfx::Size(extension_misc::EXTENSION_ICON_SMALL,
174 extension_misc::EXTENSION_ICON_SMALL)); 179 extension_misc::EXTENSION_ICON_SMALL)));
175 if (controller_)
176 controller_->UpdateLauncherItem();
177 } 180 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_window.h ('k') | chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698