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 FetchIcon(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 content::WebContents
* web_contents
= GetWebContents();
51 infobars::InfoBar
* infobar
= nullptr;
52 if (native_app_data_
.is_null()) {
53 scoped_ptr
<AppBannerInfoBarDelegateAndroid
> delegate(
54 new AppBannerInfoBarDelegateAndroid(
55 event_request_id(), title
, new SkBitmap(*icon
), web_app_data()));
58 new AppBannerInfoBarAndroid(delegate
.Pass(), web_app_data().start_url
);
60 RecordDidShowBanner("AppBanner.WebApp.Shown");
61 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED
);
64 scoped_ptr
<AppBannerInfoBarDelegateAndroid
> delegate(
65 new AppBannerInfoBarDelegateAndroid(
66 event_request_id(), title
, new SkBitmap(*icon
), native_app_data_
,
67 native_app_package_
));
68 infobar
= new AppBannerInfoBarAndroid(delegate
.Pass(), native_app_data_
);
70 RecordDidShowBanner("AppBanner.NativeApp.Shown");
71 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED
);
74 InfoBarService::FromWebContents(web_contents
)
75 ->AddInfoBar(make_scoped_ptr(infobar
));
78 } // namespace banners