Chromium Code Reviews| Index: chrome/browser/ui/app_list/search/playstore/playstore_search_result.cc |
| diff --git a/chrome/browser/ui/app_list/search/playstore/playstore_search_result.cc b/chrome/browser/ui/app_list/search/playstore/playstore_search_result.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..57d4bc23e102f3313acee40fd2aabc0a8bc8af4f |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/search/playstore/playstore_search_result.cc |
| @@ -0,0 +1,134 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/app_list/search/playstore/playstore_search_result.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/grit/component_extension_resources.h" |
| +#include "components/crx_file/id_util.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "ui/app_list/app_list_constants.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gfx/geometry/size.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| +#include "ui/gfx/image/image_skia_rep.h" |
| +#include "ui/gfx/image/image_skia_source.h" |
| + |
| +using content::BrowserThread; |
| + |
| +#if defined(OS_CHROMEOS) |
| + |
| +namespace app_list { |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// IconSource |
| + |
| +class PlaystoreSearchResult::IconSource : public gfx::ImageSkiaSource { |
| + public: |
| + IconSource(const base::WeakPtr<PlaystoreSearchResult>& host, |
| + int resource_size_in_dip); |
| + ~IconSource() override; |
|
Luis Héctor Chávez
2017/06/16 22:24:34
nit: ~IconSource() override = default;
Jiaquan He
2017/06/22 04:30:03
Done.
|
| + |
| + private: |
| + gfx::ImageSkiaRep GetImageForScale(float scale) override; |
| + |
| + const int resource_size_in_dip_; |
| + const base::WeakPtr<PlaystoreSearchResult> host_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(IconSource); |
| +}; |
| + |
| +PlaystoreSearchResult::IconSource::IconSource( |
| + const base::WeakPtr<PlaystoreSearchResult>& host, |
| + int resource_size_in_dip) |
| + : resource_size_in_dip_(resource_size_in_dip), host_(host) {} |
| + |
| +PlaystoreSearchResult::IconSource::~IconSource() {} |
| + |
| +gfx::ImageSkiaRep PlaystoreSearchResult::IconSource::GetImageForScale( |
| + float scale) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + const gfx::ImageSkia* icon_to_scale; |
| + if (host_) { |
| + icon_to_scale = &host_->decoded_icon_; |
| + } else { |
| + int resource_id = |
| + scale >= 1.5f ? IDR_ARC_SUPPORT_ICON_96 : IDR_ARC_SUPPORT_ICON_48; |
| + icon_to_scale = |
| + ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| + } |
| + CHECK(icon_to_scale); |
|
Luis Héctor Chávez
2017/06/16 22:24:34
Do not use CHECK: https://chromium.googlesource.co
Jiaquan He
2017/06/22 04:30:03
Done.
|
| + |
| + gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( |
| + *icon_to_scale, skia::ImageOperations::RESIZE_BEST, |
| + gfx::Size(resource_size_in_dip_, resource_size_in_dip_)); |
| + return resized_image.GetRepresentation(scale); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// PlaystoreSearchResult |
| + |
| +PlaystoreSearchResult::PlaystoreSearchResult( |
| + const std::string& launch_intent_uri, |
| + const std::string& install_intent_uri, |
| + const std::string& label, |
| + bool is_instant_app, |
| + bool is_recent, |
| + const std::string& publisher_name, |
| + const std::vector<uint8_t>& icon_png_data) |
| + : launch_intent_uri_(launch_intent_uri), |
| + install_intent_uri_(install_intent_uri), |
| + label_(label), |
| + is_instant_app_(is_instant_app), |
| + is_recent_(is_recent), |
| + publisher_name_(publisher_name), |
| + icon_png_data_(icon_png_data), |
| + weak_ptr_factory_(this) { |
| + set_title(base::ASCIIToUTF16(label)); |
|
Luis Héctor Chávez
2017/06/16 22:24:33
I don't think there's a guarantee that this is ASC
Jiaquan He
2017/06/22 04:30:03
Done.
|
| + set_id(kPlayAppPrefix + crx_file::id_util::GenerateId(install_intent_uri_)); |
| + set_display_type(DISPLAY_TILE); |
| + |
| + // Decode the icon |
| + SkBitmap decoded_bitmap; |
| + if (gfx::PNGCodec::Decode( |
|
Luis Héctor Chávez
2017/06/16 22:24:34
I don't think it's safe to call this from the brow
Jiaquan He
2017/06/22 04:30:03
Done.
|
| + reinterpret_cast<const unsigned char*>(&(icon_png_data_[0])), |
|
Luis Héctor Chávez
2017/06/16 22:24:34
nit: s/&(icon_png_data_[0])/icon_png_data_.data()/
Jiaquan He
2017/06/22 04:30:03
Done.
|
| + icon_png_data_.size(), &decoded_bitmap)) { |
| + // Now decoded_bitmap holds an icon of its original size. |
| + // We store it into decoded_icon_, from which we'll get scaled icons |
| + // in the future. |
| + decoded_icon_.AddRepresentation(gfx::ImageSkiaRep( |
| + decoded_bitmap, ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P))); |
| + |
| + int resource_size_in_dip = app_list::kGridIconDimension; |
| + source_ = |
|
Luis Héctor Chávez
2017/06/16 22:24:34
You cannot hold to the created IconSource since gf
Jiaquan He
2017/06/22 04:30:03
Done.
|
| + new IconSource(weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip); |
| + gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); |
| + gfx::ImageSkia icon = gfx::ImageSkia(source_, resource_size); |
| + icon.EnsureRepsForSupportedScales(); |
| + |
| + SetIcon(icon); |
| + } |
| +} |
| + |
| +PlaystoreSearchResult::~PlaystoreSearchResult() {} |
| + |
| +std::unique_ptr<SearchResult> PlaystoreSearchResult::Duplicate() const { |
| + std::unique_ptr<SearchResult> result = |
| + base::MakeUnique<PlaystoreSearchResult>( |
| + launch_intent_uri_, install_intent_uri_, label_, is_instant_app_, |
| + is_recent_, publisher_name_, icon_png_data_); |
| + result->SetIcon(icon()); |
| + return result; |
| +} |
| + |
| +void PlaystoreSearchResult::Open(int event_flags) { |
| + arc::mojom::AppInstance* app_instance = GET_APP_INSTANCE(LaunchIntent); |
| + if (app_instance == nullptr) |
| + return; |
| + |
| + app_instance->LaunchIntent(install_intent_uri_, base::Optional<gfx::Rect>()); |
| +} |
| + |
| +} // namespace app_list |
| + |
| +#endif |