Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / banners / app_banner_data_fetcher_android.cc
blobd18eb59f058d297612600e3c46a6fb644af42965
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_splash_image_size_in_dp,
22 int ideal_icon_size_in_dp)
23 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size_in_dp),
24 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp) {
27 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() {
30 std::string AppBannerDataFetcherAndroid::GetBannerType() {
31 return native_app_data_.is_null()
32 ? AppBannerDataFetcher::GetBannerType() : "android";
35 bool AppBannerDataFetcherAndroid::ContinueFetching(
36 const base::string16& app_title,
37 const std::string& app_package,
38 base::android::ScopedJavaLocalRef<jobject> app_data,
39 const GURL& image_url) {
40 set_app_title(app_title);
41 native_app_package_ = app_package;
42 native_app_data_.Reset(app_data);
43 return FetchAppIcon(GetWebContents(), image_url);
46 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() {
47 return native_app_data_.is_null()
48 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_;
51 void AppBannerDataFetcherAndroid::FetchWebappSplashScreenImage(
52 const std::string& webapp_id) {
53 content::WebContents* web_contents = GetWebContents();
54 DCHECK(web_contents);
56 GURL image_url = ManifestIconSelector::FindBestMatchingIcon(
57 web_app_data().icons,
58 ideal_splash_image_size_in_dp_,
59 gfx::Screen::GetScreenFor(web_contents->GetNativeView()));
61 ShortcutHelper::FetchSplashScreenImage(
62 web_contents, image_url, ideal_splash_image_size_in_dp_, webapp_id);
65 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon,
66 const base::string16& title,
67 const std::string& referrer) {
68 content::WebContents* web_contents = GetWebContents();
69 DCHECK(web_contents);
71 infobars::InfoBar* infobar = nullptr;
72 if (native_app_data_.is_null()) {
73 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate(
74 new AppBannerInfoBarDelegateAndroid(
75 event_request_id(), this, title, new SkBitmap(*icon),
76 web_app_data()));
78 infobar =
79 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url);
80 if (infobar) {
81 RecordDidShowBanner("AppBanner.WebApp.Shown");
82 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
84 } else {
85 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate(
86 new AppBannerInfoBarDelegateAndroid(
87 event_request_id(), title, new SkBitmap(*icon), native_app_data_,
88 native_app_package_, referrer));
89 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_);
90 if (infobar) {
91 RecordDidShowBanner("AppBanner.NativeApp.Shown");
92 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED);
95 InfoBarService::FromWebContents(web_contents)
96 ->AddInfoBar(make_scoped_ptr(infobar));
99 } // namespace banners