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/banners/app_banner_metrics.h"
9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
15 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid(
16 content::WebContents
* web_contents
,
17 base::WeakPtr
<Delegate
> weak_delegate
,
19 : AppBannerDataFetcher(web_contents
, weak_delegate
, ideal_icon_size
) {
22 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() {
25 std::string
AppBannerDataFetcherAndroid::GetBannerType() {
26 return native_app_data_
.is_null()
27 ? AppBannerDataFetcher::GetBannerType() : "android";
30 bool AppBannerDataFetcherAndroid::ContinueFetching(
31 const base::string16
& app_title
,
32 const std::string
& app_package
,
33 base::android::ScopedJavaLocalRef
<jobject
> app_data
,
34 const GURL
& image_url
) {
35 set_app_title(app_title
);
36 native_app_package_
= app_package
;
37 native_app_data_
.Reset(app_data
);
38 return FetchAppIcon(GetWebContents(), image_url
);
41 std::string
AppBannerDataFetcherAndroid::GetAppIdentifier() {
42 return native_app_data_
.is_null()
43 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_
;
46 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap
* icon
,
47 const base::string16
& title
,
48 const std::string
& referrer
) {
49 content::WebContents
* web_contents
= GetWebContents();
52 infobars::InfoBar
* infobar
= nullptr;
53 if (native_app_data_
.is_null()) {
54 scoped_ptr
<AppBannerInfoBarDelegateAndroid
> delegate(
55 new AppBannerInfoBarDelegateAndroid(
56 event_request_id(), title
, new SkBitmap(*icon
), web_app_data()));
59 new AppBannerInfoBarAndroid(delegate
.Pass(), web_app_data().start_url
);
61 RecordDidShowBanner("AppBanner.WebApp.Shown");
62 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED
);
65 scoped_ptr
<AppBannerInfoBarDelegateAndroid
> delegate(
66 new AppBannerInfoBarDelegateAndroid(
67 event_request_id(), title
, new SkBitmap(*icon
), native_app_data_
,
68 native_app_package_
, referrer
));
69 infobar
= new AppBannerInfoBarAndroid(delegate
.Pass(), native_app_data_
);
71 RecordDidShowBanner("AppBanner.NativeApp.Shown");
72 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED
);
75 InfoBarService::FromWebContents(web_contents
)
76 ->AddInfoBar(make_scoped_ptr(infobar
));
79 } // namespace banners