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

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

Issue 2050933002: Upstream: Add additional checks before creating a WebAPK after clicking "Add to Homescreen" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'create_webapk_requirements_enum_class' into create_webapk_requirements2 Created 4 years, 5 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h" 5 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" 13 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
13 #include "chrome/browser/android/shortcut_helper.h" 14 #include "chrome/browser/android/shortcut_helper.h"
14 #include "chrome/browser/banners/app_banner_metrics.h" 15 #include "chrome/browser/banners/app_banner_metrics.h"
15 #include "chrome/browser/infobars/infobar_service.h" 16 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/manifest/manifest_icon_selector.h" 17 #include "chrome/browser/manifest/manifest_icon_selector.h"
17 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" 18 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
19 #include "chrome/common/chrome_switches.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
19 21
20 namespace banners { 22 namespace banners {
21 23
22 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( 24 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid(
23 content::WebContents* web_contents, 25 content::WebContents* web_contents,
24 base::WeakPtr<Delegate> weak_delegate, 26 base::WeakPtr<Delegate> weak_delegate,
25 int ideal_icon_size_in_dp, 27 int ideal_icon_size_in_dp,
26 int minimum_icon_size_in_dp, 28 int minimum_icon_size_in_dp,
27 int ideal_splash_image_size_in_dp, 29 int ideal_splash_image_size_in_dp,
28 int minimum_splash_image_size_in_dp, 30 int minimum_splash_image_size_in_dp,
29 bool is_debug_mode) 31 bool is_debug_mode)
30 : AppBannerDataFetcher(web_contents, 32 : AppBannerDataFetcher(web_contents,
31 weak_delegate, 33 weak_delegate,
32 ideal_icon_size_in_dp, 34 ideal_icon_size_in_dp,
33 minimum_icon_size_in_dp, 35 minimum_icon_size_in_dp,
34 is_debug_mode), 36 is_debug_mode),
37 webapp_type_(ShortcutInfo::Type::OTHER),
35 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), 38 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) {} 39 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {}
37 40
38 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { 41 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() {
39 } 42 }
40 43
41 std::string AppBannerDataFetcherAndroid::GetBannerType() { 44 std::string AppBannerDataFetcherAndroid::GetBannerType() {
42 return native_app_data_.is_null() 45 return native_app_data_.is_null()
43 ? AppBannerDataFetcher::GetBannerType() : "android"; 46 ? AppBannerDataFetcher::GetBannerType() : "android";
44 } 47 }
45 48
46 bool AppBannerDataFetcherAndroid::ContinueFetching( 49 bool AppBannerDataFetcherAndroid::ContinueFetching(
47 const base::string16& app_title, 50 const base::string16& app_title,
48 const std::string& app_package, 51 const std::string& app_package,
49 const base::android::JavaRef<jobject>& app_data, 52 const base::android::JavaRef<jobject>& app_data,
50 const GURL& image_url) { 53 const GURL& image_url) {
51 set_app_title(app_title); 54 set_app_title(app_title);
52 native_app_package_ = app_package; 55 native_app_package_ = app_package;
53 native_app_data_.Reset(app_data); 56 native_app_data_.Reset(app_data);
54 return FetchAppIcon(GetWebContents(), image_url); 57 return FetchAppIcon(GetWebContents(), image_url);
55 } 58 }
56 59
60 bool AppBannerDataFetcherAndroid::CheckManifest(
61 const content::Manifest& manifest,
62 OutputDeveloperMessageCode* code) {
63 bool manifest_valid_for_webapp =
64 AppBannerDataFetcher::CheckManifest(manifest, code);
65 if (manifest_valid_for_webapp) {
66 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
67 webapp_type_ = command_line->HasSwitch(switches::kEnableWebApk)
68 ? ShortcutInfo::Type::WEBAPK
69 : ShortcutInfo::Type::WEBAPP;
70 }
71 return manifest_valid_for_webapp;
72 }
73
57 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { 74 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() {
58 return native_app_data_.is_null() 75 return native_app_data_.is_null()
59 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; 76 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_;
60 } 77 }
61 78
62 base::Closure AppBannerDataFetcherAndroid::FetchWebappSplashScreenImageCallback( 79 base::Closure AppBannerDataFetcherAndroid::FetchWebappSplashScreenImageCallback(
63 const std::string& webapp_id) { 80 const std::string& webapp_id) {
64 content::WebContents* web_contents = GetWebContents(); 81 content::WebContents* web_contents = GetWebContents();
65 DCHECK(web_contents); 82 DCHECK(web_contents);
66 83
(...skipping 11 matching lines...) Expand all
78 const base::string16& title, 95 const base::string16& title,
79 const std::string& referrer) { 96 const std::string& referrer) {
80 content::WebContents* web_contents = GetWebContents(); 97 content::WebContents* web_contents = GetWebContents();
81 DCHECK(web_contents); 98 DCHECK(web_contents);
82 99
83 infobars::InfoBar* infobar = nullptr; 100 infobars::InfoBar* infobar = nullptr;
84 if (native_app_data_.is_null()) { 101 if (native_app_data_.is_null()) {
85 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( 102 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate(
86 new AppBannerInfoBarDelegateAndroid(event_request_id(), this, title, 103 new AppBannerInfoBarDelegateAndroid(event_request_id(), this, title,
87 icon_url, new SkBitmap(*icon), 104 icon_url, new SkBitmap(*icon),
88 manifest_url(), manifest())); 105 manifest_url(), manifest(),
106 webapp_type_));
89 107
90 infobar = new AppBannerInfoBarAndroid(std::move(delegate), 108 infobar = new AppBannerInfoBarAndroid(std::move(delegate),
91 manifest().start_url); 109 manifest().start_url);
92 if (infobar) { 110 if (infobar) {
93 RecordDidShowBanner("AppBanner.WebApp.Shown"); 111 RecordDidShowBanner("AppBanner.WebApp.Shown");
94 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); 112 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
95 } 113 }
96 } else { 114 } else {
97 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( 115 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate(
98 new AppBannerInfoBarDelegateAndroid( 116 new AppBannerInfoBarDelegateAndroid(
99 event_request_id(), title, new SkBitmap(*icon), native_app_data_, 117 event_request_id(), title, new SkBitmap(*icon), native_app_data_,
100 native_app_package_, referrer)); 118 native_app_package_, referrer));
101 infobar = 119 infobar =
102 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_); 120 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_);
103 if (infobar) { 121 if (infobar) {
104 RecordDidShowBanner("AppBanner.NativeApp.Shown"); 122 RecordDidShowBanner("AppBanner.NativeApp.Shown");
105 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); 123 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED);
106 } 124 }
107 } 125 }
108 InfoBarService::FromWebContents(web_contents) 126 InfoBarService::FromWebContents(web_contents)
109 ->AddInfoBar(base::WrapUnique(infobar)); 127 ->AddInfoBar(base::WrapUnique(infobar));
110 } 128 }
111 129
112 } // namespace banners 130 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698