Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Side by Side Diff: chrome/browser/android/banners/app_banner_data_fetcher_android.cc

Issue 2156113002: Replace AppBannerDataFetcher with InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@banner-refactor
Patch Set: Naming, includes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
13 #include "chrome/browser/android/shortcut_helper.h"
14 #include "chrome/browser/banners/app_banner_metrics.h"
15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/manifest/manifest_icon_selector.h"
17 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
19
20 namespace banners {
21
22 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid(
23 content::WebContents* web_contents,
24 base::WeakPtr<Delegate> weak_delegate,
25 int ideal_icon_size_in_dp,
26 int minimum_icon_size_in_dp,
27 int ideal_splash_image_size_in_dp,
28 int minimum_splash_image_size_in_dp,
29 bool is_debug_mode)
30 : AppBannerDataFetcher(web_contents,
31 weak_delegate,
32 ideal_icon_size_in_dp,
33 minimum_icon_size_in_dp,
34 is_debug_mode),
35 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp),
36 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {}
37
38 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() {
39 }
40
41 std::string AppBannerDataFetcherAndroid::GetBannerType() {
42 return native_app_data_.is_null()
43 ? AppBannerDataFetcher::GetBannerType() : "android";
44 }
45
46 bool AppBannerDataFetcherAndroid::ContinueFetching(
47 const base::string16& app_title,
48 const std::string& app_package,
49 const base::android::JavaRef<jobject>& app_data,
50 const GURL& image_url) {
51 set_app_title(app_title);
52 native_app_package_ = app_package;
53 native_app_data_.Reset(app_data);
54 return FetchAppIcon(GetWebContents(), image_url);
55 }
56
57 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() {
58 return native_app_data_.is_null()
59 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_;
60 }
61
62 base::Closure AppBannerDataFetcherAndroid::FetchWebappSplashScreenImageCallback(
63 const std::string& webapp_id) {
64 content::WebContents* web_contents = GetWebContents();
65 DCHECK(web_contents);
66
67 GURL image_url = ManifestIconSelector::FindBestMatchingIcon(
68 manifest().icons, ideal_splash_image_size_in_dp_,
69 minimum_splash_image_size_in_dp_);
70
71 return base::Bind(&ShortcutHelper::FetchSplashScreenImage,
72 web_contents, image_url, ideal_splash_image_size_in_dp_,
73 minimum_splash_image_size_in_dp_, webapp_id);
74 }
75
76 bool AppBannerDataFetcherAndroid::IsWebAppInstalled(
77 content::BrowserContext* browser_context,
78 const GURL& start_url) {
79 // Check whether a WebAPK is installed in order to block showing the app
80 // banner if a WebAPK is installed even after a user clears Chrome's data.
81 // This function does not check whether a non-WebAPK web app is installed.
82 return ShortcutHelper::IsWebApkInstalled(start_url);
83 }
84
85 void AppBannerDataFetcherAndroid::ShowBanner(const GURL& icon_url,
86 const SkBitmap* icon,
87 const base::string16& title,
88 const std::string& referrer) {
89 content::WebContents* web_contents = GetWebContents();
90 DCHECK(web_contents);
91
92 infobars::InfoBar* infobar = nullptr;
93 if (native_app_data_.is_null()) {
94 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate(
95 new AppBannerInfoBarDelegateAndroid(event_request_id(), this, title,
96 icon_url, new SkBitmap(*icon),
97 manifest_url(), manifest()));
98
99 infobar = new AppBannerInfoBarAndroid(std::move(delegate),
100 manifest().start_url);
101 if (infobar) {
102 RecordDidShowBanner("AppBanner.WebApp.Shown");
103 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
104 }
105 } else {
106 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate(
107 new AppBannerInfoBarDelegateAndroid(
108 event_request_id(), title, new SkBitmap(*icon), native_app_data_,
109 native_app_package_, referrer));
110 infobar =
111 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_);
112 if (infobar) {
113 RecordDidShowBanner("AppBanner.NativeApp.Shown");
114 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED);
115 }
116 }
117 InfoBarService::FromWebContents(web_contents)
118 ->AddInfoBar(base::WrapUnique(infobar));
119 }
120
121 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698