webapps: allow callers of icon downloader/selector to specify a minimum size
[chromium-blink-merge.git] / chrome / browser / android / banners / app_banner_data_fetcher_android.cc
blobb8a561d1dd000383d4e7601058efc1094966d9c0
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h"
7 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
8 #include "chrome/browser/android/shortcut_helper.h"
9 #include "chrome/browser/banners/app_banner_metrics.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/manifest/manifest_icon_selector.h"
12 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/screen.h"
16 namespace banners {
18 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid(
19 content::WebContents* web_contents,
20 base::WeakPtr<Delegate> weak_delegate,
21 int ideal_icon_size_in_dp,
22 int minimum_icon_size_in_dp,
23 int ideal_splash_image_size_in_dp,
24 int minimum_splash_image_size_in_dp)
25 : AppBannerDataFetcher(web_contents,
26 weak_delegate,
27 ideal_icon_size_in_dp,
28 minimum_icon_size_in_dp),
29 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp),
30 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {
33 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() {
36 std::string AppBannerDataFetcherAndroid::GetBannerType() {
37 return native_app_data_.is_null()
38 ? AppBannerDataFetcher::GetBannerType() : "android";
41 bool AppBannerDataFetcherAndroid::ContinueFetching(
42 const base::string16& app_title,
43 const std::string& app_package,
44 base::android::ScopedJavaLocalRef<jobject> app_data,
45 const GURL& image_url) {
46 set_app_title(app_title);
47 native_app_package_ = app_package;
48 native_app_data_.Reset(app_data);
49 return FetchAppIcon(GetWebContents(), image_url);
52 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() {
53 return native_app_data_.is_null()
54 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_;
57 void AppBannerDataFetcherAndroid::FetchWebappSplashScreenImage(
58 const std::string& webapp_id) {
59 content::WebContents* web_contents = GetWebContents();
60 DCHECK(web_contents);
62 GURL image_url = ManifestIconSelector::FindBestMatchingIcon(
63 web_app_data().icons,
64 ideal_splash_image_size_in_dp_,
65 minimum_splash_image_size_in_dp_,
66 gfx::Screen::GetScreenFor(web_contents->GetNativeView()));
68 ShortcutHelper::FetchSplashScreenImage(
69 web_contents,
70 image_url,
71 ideal_splash_image_size_in_dp_,
72 minimum_splash_image_size_in_dp_,
73 webapp_id);
76 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon,
77 const base::string16& title,
78 const std::string& referrer) {
79 content::WebContents* web_contents = GetWebContents();
80 DCHECK(web_contents);
82 infobars::InfoBar* infobar = nullptr;
83 if (native_app_data_.is_null()) {
84 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate(
85 new AppBannerInfoBarDelegateAndroid(
86 event_request_id(), this, title, new SkBitmap(*icon),
87 web_app_data()));
89 infobar =
90 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url);
91 if (infobar) {
92 RecordDidShowBanner("AppBanner.WebApp.Shown");
93 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
95 } else {
96 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate(
97 new AppBannerInfoBarDelegateAndroid(
98 event_request_id(), title, new SkBitmap(*icon), native_app_data_,
99 native_app_package_, referrer));
100 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_);
101 if (infobar) {
102 RecordDidShowBanner("AppBanner.NativeApp.Shown");
103 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED);
106 InfoBarService::FromWebContents(web_contents)
107 ->AddInfoBar(make_scoped_ptr(infobar));
110 } // namespace banners