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

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_window.cc

Issue 2894443002: arc: Set custom icon in shelf for ARC apps. (Closed)
Patch Set: comments addressed Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/launcher/arc_app_window.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
9 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
10 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h"
11 #include "components/exo/shell_surface.h"
12 #include "extensions/common/constants.h"
13 #include "ui/aura/window.h"
14 #include "ui/gfx/codec/png_codec.h"
15 #include "ui/gfx/image/image_skia_operations.h"
16 #include "ui/views/widget/widget.h"
17
18 namespace {
19
20 // Set to true for unit tests to avoid IPC icon decoding.
21 bool disable_safe_icon_decoding = false;
22
23 } // namespace
24
25 ArcAppWindow::ArcAppWindow(int task_id,
26 const arc::ArcAppShelfId& app_shelf_id,
27 views::Widget* widget,
28 ArcAppWindowLauncherController* owner)
29 : task_id_(task_id),
30 app_shelf_id_(app_shelf_id),
31 widget_(widget),
32 owner_(owner) {}
33
34 ArcAppWindow::~ArcAppWindow() {
35 ImageDecoder::Cancel(this);
36 }
37
38 // static
39 void ArcAppWindow::DisableSafeIconDecodingForTesting() {
40 disable_safe_icon_decoding = true;
41 }
42
43 void ArcAppWindow::SetController(
44 ArcAppWindowLauncherItemController* controller) {
45 DCHECK(!controller_ && controller);
46 controller_ = controller;
47 controller_->UpdateLauncherItem();
48 }
49
50 void ArcAppWindow::ResetController() {
51 controller_ = nullptr;
52 }
53
54 void ArcAppWindow::SetFullscreenMode(FullScreenMode mode) {
55 DCHECK(mode != FullScreenMode::NOT_DEFINED);
56 fullscreen_mode_ = mode;
57 }
58
59 void ArcAppWindow::SetDescription(
60 const std::string& title,
61 const std::vector<uint8_t>& unsafe_icon_data_png) {
62 if (title.length())
63 GetNativeWindow()->SetTitle(base::string16(base::UTF8ToUTF16(title)));
64 ImageDecoder::Cancel(this);
65 if (unsafe_icon_data_png.empty()) {
66 ResetIcon();
67 return;
68 }
69
70 if (disable_safe_icon_decoding) {
71 SkBitmap bitmap;
72 if (gfx::PNGCodec::Decode(&unsafe_icon_data_png[0],
73 unsafe_icon_data_png.size(), &bitmap)) {
74 OnImageDecoded(bitmap);
75 } else {
76 OnDecodeImageFailed();
77 }
78 } else {
79 ImageDecoder::Start(this, unsafe_icon_data_png);
80 }
81 }
82
83 bool ArcAppWindow::IsActive() const {
84 return widget_->IsActive() && owner_->active_task_id() == task_id_;
85 }
86
87 bool ArcAppWindow::IsMaximized() const {
88 NOTREACHED();
89 return false;
90 }
91
92 bool ArcAppWindow::IsMinimized() const {
93 NOTREACHED();
94 return false;
95 }
96
97 bool ArcAppWindow::IsFullscreen() const {
98 NOTREACHED();
99 return false;
100 }
101
102 gfx::NativeWindow ArcAppWindow::GetNativeWindow() const {
103 return widget_->GetNativeWindow();
104 }
105
106 gfx::Rect ArcAppWindow::GetRestoredBounds() const {
107 NOTREACHED();
108 return gfx::Rect();
109 }
110
111 ui::WindowShowState ArcAppWindow::GetRestoredState() const {
112 NOTREACHED();
113 return ui::SHOW_STATE_NORMAL;
114 }
115
116 gfx::Rect ArcAppWindow::GetBounds() const {
117 NOTREACHED();
118 return gfx::Rect();
119 }
120
121 void ArcAppWindow::Show() {
122 widget_->Show();
123 }
124
125 void ArcAppWindow::ShowInactive() {
126 NOTREACHED();
127 }
128
129 void ArcAppWindow::Hide() {
130 NOTREACHED();
131 }
132
133 void ArcAppWindow::Close() {
134 arc::CloseTask(task_id_);
135 }
136
137 void ArcAppWindow::Activate() {
138 widget_->Activate();
139 }
140
141 void ArcAppWindow::Deactivate() {
142 NOTREACHED();
143 }
144
145 void ArcAppWindow::Maximize() {
146 NOTREACHED();
147 }
148
149 void ArcAppWindow::Minimize() {
150 widget_->Minimize();
151 }
152
153 void ArcAppWindow::Restore() {
154 NOTREACHED();
155 }
156
157 void ArcAppWindow::SetBounds(const gfx::Rect& bounds) {
158 NOTREACHED();
159 }
160
161 void ArcAppWindow::FlashFrame(bool flash) {
162 NOTREACHED();
163 }
164
165 bool ArcAppWindow::IsAlwaysOnTop() const {
166 NOTREACHED();
167 return false;
168 }
169
170 void ArcAppWindow::SetAlwaysOnTop(bool always_on_top) {
171 NOTREACHED();
172 }
173
174 void ArcAppWindow::ResetIcon() {
175 if (image_skia_.isNull())
176 return;
177 image_skia_ = gfx::ImageSkia();
178 if (controller_)
179 controller_->UpdateLauncherItem();
180 }
181
182 void ArcAppWindow::OnImageDecoded(const SkBitmap& decoded_image) {
183 image_skia_ = gfx::ImageSkiaOperations::CreateResizedImage(
184 gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)),
185 skia::ImageOperations::RESIZE_BEST,
186 gfx::Size(extension_misc::EXTENSION_ICON_SMALL,
187 extension_misc::EXTENSION_ICON_SMALL));
188 if (controller_)
189 controller_->UpdateLauncherItem();
190 }
191
192 void ArcAppWindow::OnDecodeImageFailed() {
193 ResetIcon();
194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698