| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/app_list/arc/arc_app_icon.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "extensions/grit/extensions_browser_resources.h" | 26 #include "extensions/grit/extensions_browser_resources.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
| 29 #include "ui/gfx/geometry/size.h" | 29 #include "ui/gfx/geometry/size.h" |
| 30 #include "ui/gfx/image/image_skia_operations.h" | 30 #include "ui/gfx/image/image_skia_operations.h" |
| 31 #include "ui/gfx/image/image_skia_source.h" | 31 #include "ui/gfx/image/image_skia_source.h" |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 bool disable_safe_decoding = false; | 35 bool disable_safe_decoding_for_testing = false; |
| 36 | 36 |
| 37 std::string GetAppFromAppOrGroupId(content::BrowserContext* context, | 37 std::string GetAppFromAppOrGroupId(content::BrowserContext* context, |
| 38 const std::string& app_or_group_id) { | 38 const std::string& app_or_group_id) { |
| 39 const arc::ArcAppShelfId app_shelf_id = arc::ArcAppShelfId::FromString( | 39 const arc::ArcAppShelfId app_shelf_id = arc::ArcAppShelfId::FromString( |
| 40 app_or_group_id); | 40 app_or_group_id); |
| 41 if (!app_shelf_id.has_shelf_group_id()) | 41 if (!app_shelf_id.has_shelf_group_id()) |
| 42 return app_shelf_id.app_id(); | 42 return app_shelf_id.app_id(); |
| 43 | 43 |
| 44 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(context); | 44 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(context); |
| 45 DCHECK(prefs); | 45 DCHECK(prefs); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 host_->MaybeRequestIcon(scale_factor_); | 230 host_->MaybeRequestIcon(scale_factor_); |
| 231 host_->DiscardDecodeRequest(this); | 231 host_->DiscardDecodeRequest(this); |
| 232 } | 232 } |
| 233 | 233 |
| 234 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
| 235 // ArcAppIcon | 235 // ArcAppIcon |
| 236 | 236 |
| 237 // static | 237 // static |
| 238 void ArcAppIcon::DisableSafeDecodingForTesting() { | 238 void ArcAppIcon::DisableSafeDecodingForTesting() { |
| 239 disable_safe_decoding = true; | 239 disable_safe_decoding_for_testing = true; |
| 240 } |
| 241 |
| 242 // static |
| 243 bool ArcAppIcon::IsSafeDecodingDisabledForTesting() { |
| 244 return disable_safe_decoding_for_testing; |
| 240 } | 245 } |
| 241 | 246 |
| 242 ArcAppIcon::ArcAppIcon(content::BrowserContext* context, | 247 ArcAppIcon::ArcAppIcon(content::BrowserContext* context, |
| 243 const std::string& app_id, | 248 const std::string& app_id, |
| 244 int resource_size_in_dip, | 249 int resource_size_in_dip, |
| 245 Observer* observer) | 250 Observer* observer) |
| 246 : context_(context), | 251 : context_(context), |
| 247 app_id_(GetAppFromAppOrGroupId(context, app_id)), | 252 app_id_(GetAppFromAppOrGroupId(context, app_id)), |
| 248 resource_size_in_dip_(resource_size_in_dip), | 253 resource_size_in_dip_(resource_size_in_dip), |
| 249 observer_(observer), | 254 observer_(observer), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 std::unique_ptr<ArcAppIcon::ReadResult> read_result) { | 333 std::unique_ptr<ArcAppIcon::ReadResult> read_result) { |
| 329 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 330 | 335 |
| 331 if (read_result->request_to_install) | 336 if (read_result->request_to_install) |
| 332 MaybeRequestIcon(read_result->scale_factor); | 337 MaybeRequestIcon(read_result->scale_factor); |
| 333 | 338 |
| 334 if (!read_result->unsafe_icon_data.empty()) { | 339 if (!read_result->unsafe_icon_data.empty()) { |
| 335 decode_requests_.push_back(base::MakeUnique<DecodeRequest>( | 340 decode_requests_.push_back(base::MakeUnique<DecodeRequest>( |
| 336 weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip_, | 341 weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip_, |
| 337 read_result->scale_factor)); | 342 read_result->scale_factor)); |
| 338 if (disable_safe_decoding) { | 343 if (disable_safe_decoding_for_testing) { |
| 339 SkBitmap bitmap; | 344 SkBitmap bitmap; |
| 340 if (!read_result->unsafe_icon_data.empty() && | 345 if (!read_result->unsafe_icon_data.empty() && |
| 341 gfx::PNGCodec::Decode( | 346 gfx::PNGCodec::Decode( |
| 342 reinterpret_cast<const unsigned char*>( | 347 reinterpret_cast<const unsigned char*>( |
| 343 &read_result->unsafe_icon_data.front()), | 348 &read_result->unsafe_icon_data.front()), |
| 344 read_result->unsafe_icon_data.length(), | 349 read_result->unsafe_icon_data.length(), |
| 345 &bitmap)) { | 350 &bitmap)) { |
| 346 decode_requests_.back()->OnImageDecoded(bitmap); | 351 decode_requests_.back()->OnImageDecoded(bitmap); |
| 347 } else { | 352 } else { |
| 348 decode_requests_.back()->OnDecodeImageFailed(); | 353 decode_requests_.back()->OnDecodeImageFailed(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 372 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { | 377 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { |
| 373 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 374 | 379 |
| 375 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), | 380 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), |
| 376 [request](const std::unique_ptr<DecodeRequest>& ptr) { | 381 [request](const std::unique_ptr<DecodeRequest>& ptr) { |
| 377 return ptr.get() == request; | 382 return ptr.get() == request; |
| 378 }); | 383 }); |
| 379 CHECK(it != decode_requests_.end()); | 384 CHECK(it != decode_requests_.end()); |
| 380 decode_requests_.erase(it); | 385 decode_requests_.erase(it); |
| 381 } | 386 } |
| OLD | NEW |