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

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

Issue 2676863002: Update WebApkInstaller to support badge icon in installation. (Closed)
Patch Set: Addressing comments Created 3 years, 8 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_infobar_delegate_android.h" 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
6 6
dominickn 2017/04/04 05:25:33 #include <utility> for std::move
F 2017/04/04 15:21:26 Done.
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/android/shortcut_helper.h" 11 #include "chrome/browser/android/shortcut_helper.h"
12 #include "chrome/browser/android/shortcut_info.h" 12 #include "chrome/browser/android/shortcut_info.h"
13 #include "chrome/browser/android/tab_android.h" 13 #include "chrome/browser/android/tab_android.h"
14 #include "chrome/browser/android/webapk/chrome_webapk_host.h" 14 #include "chrome/browser/android/webapk/chrome_webapk_host.h"
15 #include "chrome/browser/android/webapk/webapk_install_service.h" 15 #include "chrome/browser/android/webapk/webapk_install_service.h"
16 #include "chrome/browser/banners/app_banner_manager.h" 16 #include "chrome/browser/banners/app_banner_manager.h"
(...skipping 26 matching lines...) Expand all
43 } // anonymous namespace 43 } // anonymous namespace
44 44
45 namespace banners { 45 namespace banners {
46 46
47 // static 47 // static
48 bool AppBannerInfoBarDelegateAndroid::Create( 48 bool AppBannerInfoBarDelegateAndroid::Create(
49 content::WebContents* web_contents, 49 content::WebContents* web_contents,
50 base::WeakPtr<AppBannerManager> weak_manager, 50 base::WeakPtr<AppBannerManager> weak_manager,
51 const base::string16& app_title, 51 const base::string16& app_title,
52 std::unique_ptr<ShortcutInfo> shortcut_info, 52 std::unique_ptr<ShortcutInfo> shortcut_info,
53 std::unique_ptr<SkBitmap> icon, 53 const SkBitmap& primary_icon,
54 const SkBitmap& badge_icon,
54 int event_request_id, 55 int event_request_id,
55 webapk::InstallSource webapk_install_source) { 56 webapk::InstallSource webapk_install_source) {
56 bool is_webapk = ChromeWebApkHost::CanInstallWebApk(); 57 bool is_webapk = ChromeWebApkHost::CanInstallWebApk();
57 const GURL url = shortcut_info->url; 58 const GURL url = shortcut_info->url;
58 auto infobar_delegate = 59 auto infobar_delegate =
59 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( 60 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid(
60 weak_manager, app_title, std::move(shortcut_info), std::move(icon), 61 weak_manager, app_title, std::move(shortcut_info), primary_icon,
61 event_request_id, is_webapk, webapk_install_source)); 62 badge_icon, event_request_id, is_webapk, webapk_install_source));
62 auto* raw_delegate = infobar_delegate.get(); 63 auto* raw_delegate = infobar_delegate.get();
63 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( 64 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>(
64 std::move(infobar_delegate), url, is_webapk); 65 std::move(infobar_delegate), url, is_webapk);
65 if (!InfoBarService::FromWebContents(web_contents) 66 if (!InfoBarService::FromWebContents(web_contents)
66 ->AddInfoBar(std::move(infobar))) 67 ->AddInfoBar(std::move(infobar)))
67 return false; 68 return false;
68 69
69 if (is_webapk) { 70 if (is_webapk) {
70 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { 71 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) {
71 webapk::TrackInstallInfoBarShown( 72 webapk::TrackInstallInfoBarShown(
72 webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU); 73 webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU);
73 raw_delegate->Accept(); 74 raw_delegate->Accept();
74 } else { 75 } else {
75 webapk::TrackInstallInfoBarShown( 76 webapk::TrackInstallInfoBarShown(
76 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER); 77 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER);
77 } 78 }
78 } 79 }
79 80
80 return true; 81 return true;
81 } 82 }
82 83
83 // static 84 // static
84 bool AppBannerInfoBarDelegateAndroid::Create( 85 bool AppBannerInfoBarDelegateAndroid::Create(
85 content::WebContents* web_contents, 86 content::WebContents* web_contents,
86 const base::string16& app_title, 87 const base::string16& app_title,
87 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 88 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
88 std::unique_ptr<SkBitmap> icon, 89 const SkBitmap& icon,
89 const std::string& native_app_package, 90 const std::string& native_app_package,
90 const std::string& referrer, 91 const std::string& referrer,
91 int event_request_id) { 92 int event_request_id) {
92 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid( 93 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid(
93 app_title, native_app_data, std::move(icon), native_app_package, referrer, 94 app_title, native_app_data, icon, native_app_package, referrer,
94 event_request_id)); 95 event_request_id));
95 return InfoBarService::FromWebContents(web_contents) 96 return InfoBarService::FromWebContents(web_contents)
96 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>( 97 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>(
97 std::move(infobar_delegate), native_app_data)); 98 std::move(infobar_delegate), native_app_data));
98 } 99 }
99 100
100 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { 101 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() {
101 weak_ptr_factory_.InvalidateWeakPtrs(); 102 weak_ptr_factory_.InvalidateWeakPtrs();
102 103
103 if (!has_user_interaction_) { 104 if (!has_user_interaction_) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( 201 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName(
201 env, java_delegate_, java_webapk_package_name); 202 env, java_delegate_, java_webapk_package_name);
202 UpdateInstallState(env, nullptr); 203 UpdateInstallState(env, nullptr);
203 install_state_ = INSTALLED; 204 install_state_ = INSTALLED;
204 } 205 }
205 206
206 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 207 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
207 base::WeakPtr<AppBannerManager> weak_manager, 208 base::WeakPtr<AppBannerManager> weak_manager,
208 const base::string16& app_title, 209 const base::string16& app_title,
209 std::unique_ptr<ShortcutInfo> shortcut_info, 210 std::unique_ptr<ShortcutInfo> shortcut_info,
210 std::unique_ptr<SkBitmap> icon, 211 const SkBitmap& primary_icon,
212 const SkBitmap& badge_icon,
211 int event_request_id, 213 int event_request_id,
212 bool is_webapk, 214 bool is_webapk,
213 webapk::InstallSource webapk_install_source) 215 webapk::InstallSource webapk_install_source)
214 : weak_manager_(weak_manager), 216 : weak_manager_(weak_manager),
215 app_title_(app_title), 217 app_title_(app_title),
216 shortcut_info_(std::move(shortcut_info)), 218 shortcut_info_(std::move(shortcut_info)),
217 icon_(std::move(icon)), 219 primary_icon_(primary_icon),
220 badge_icon_(badge_icon),
218 event_request_id_(event_request_id), 221 event_request_id_(event_request_id),
219 has_user_interaction_(false), 222 has_user_interaction_(false),
220 is_webapk_(is_webapk), 223 is_webapk_(is_webapk),
221 install_state_(INSTALL_NOT_STARTED), 224 install_state_(INSTALL_NOT_STARTED),
222 webapk_install_source_(webapk_install_source), 225 webapk_install_source_(webapk_install_source),
223 weak_ptr_factory_(this) { 226 weak_ptr_factory_(this) {
224 DCHECK(!IsInfoEmpty(shortcut_info_)); 227 DCHECK(!IsInfoEmpty(shortcut_info_));
225 CreateJavaDelegate(); 228 CreateJavaDelegate();
226 } 229 }
227 230
228 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 231 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
229 const base::string16& app_title, 232 const base::string16& app_title,
230 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 233 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
231 std::unique_ptr<SkBitmap> icon, 234 const SkBitmap& icon,
232 const std::string& native_app_package, 235 const std::string& native_app_package,
233 const std::string& referrer, 236 const std::string& referrer,
234 int event_request_id) 237 int event_request_id)
235 : app_title_(app_title), 238 : app_title_(app_title),
236 native_app_data_(native_app_data), 239 native_app_data_(native_app_data),
237 icon_(std::move(icon)), 240 primary_icon_(icon),
238 native_app_package_(native_app_package), 241 native_app_package_(native_app_package),
239 referrer_(referrer), 242 referrer_(referrer),
240 event_request_id_(event_request_id), 243 event_request_id_(event_request_id),
241 has_user_interaction_(false), 244 has_user_interaction_(false),
242 weak_ptr_factory_(this) { 245 weak_ptr_factory_(this) {
243 DCHECK(!native_app_data_.is_null()); 246 DCHECK(!native_app_data_.is_null());
244 CreateJavaDelegate(); 247 CreateJavaDelegate();
245 } 248 }
246 249
247 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { 250 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() {
(...skipping 29 matching lines...) Expand all
277 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( 280 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp(
278 content::WebContents* web_contents) { 281 content::WebContents* web_contents) {
279 if (IsInfoEmpty(shortcut_info_)) 282 if (IsInfoEmpty(shortcut_info_))
280 return true; 283 return true;
281 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 284 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
282 285
283 AppBannerSettingsHelper::RecordBannerInstallEvent( 286 AppBannerSettingsHelper::RecordBannerInstallEvent(
284 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 287 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
285 288
286 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, 289 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_,
287 *icon_.get()); 290 primary_icon_);
288 291
289 SendBannerAccepted(); 292 SendBannerAccepted();
290 return true; 293 return true;
291 } 294 }
292 295
293 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( 296 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk(
294 content::WebContents* web_contents) { 297 content::WebContents* web_contents) {
295 if (IsInfoEmpty(shortcut_info_)) 298 if (IsInfoEmpty(shortcut_info_))
296 return true; 299 return true;
297 300
(...skipping 27 matching lines...) Expand all
325 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 328 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
326 AppBannerManager::GetCurrentTime()); 329 AppBannerManager::GetCurrentTime());
327 } 330 }
328 331
329 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( 332 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
330 env, java_delegate_, true); 333 env, java_delegate_, true);
331 UpdateInstallState(env, nullptr); 334 UpdateInstallState(env, nullptr);
332 WebApkInstallService::FinishCallback callback = 335 WebApkInstallService::FinishCallback callback =
333 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, 336 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
334 weak_ptr_factory_.GetWeakPtr()); 337 weak_ptr_factory_.GetWeakPtr());
335 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents, *shortcut_info_, 338 ShortcutHelper::InstallWebApkWithSkBitmap(
336 *icon_.get(), callback); 339 web_contents, *shortcut_info_, primary_icon_, badge_icon_, callback);
340
337 SendBannerAccepted(); 341 SendBannerAccepted();
338 342
339 // Prevent the infobar from disappearing, because the infobar will show 343 // Prevent the infobar from disappearing, because the infobar will show
340 // "Adding" during the installation process. 344 // "Adding" during the installation process.
341 return false; 345 return false;
342 } 346 }
343 347
344 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { 348 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const {
345 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; 349 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER;
346 } 350 }
(...skipping 25 matching lines...) Expand all
372 return; 376 return;
373 377
374 // If the install didn't definitely fail, we don't add a shortcut. This could 378 // If the install didn't definitely fail, we don't add a shortcut. This could
375 // happen if Play was busy with another install and this one is still queued 379 // happen if Play was busy with another install and this one is still queued
376 // (and hence might succeed in the future). 380 // (and hence might succeed in the future).
377 if (result == WebApkInstallResult::FAILURE) { 381 if (result == WebApkInstallResult::FAILURE) {
378 content::WebContents* web_contents = 382 content::WebContents* web_contents =
379 InfoBarService::WebContentsFromInfoBar(infobar()); 383 InfoBarService::WebContentsFromInfoBar(infobar());
380 // Add webapp shortcut to the homescreen. 384 // Add webapp shortcut to the homescreen.
381 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, 385 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_,
382 *icon_.get()); 386 primary_icon_);
383 } 387 }
384 388
385 infobar()->RemoveSelf(); 389 infobar()->RemoveSelf();
386 } 390 }
387 391
388 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( 392 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents(
389 InstallState install_state) { 393 InstallState install_state) {
390 if (install_state == INSTALL_NOT_STARTED) { 394 if (install_state == INSTALL_NOT_STARTED) {
391 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); 395 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION);
392 } else if (install_state == INSTALLING) { 396 } else if (install_state == INSTALLING) {
393 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); 397 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION);
394 } else if (install_state == INSTALLED) { 398 } else if (install_state == INSTALLED) {
395 // If WebAPK is installed from this banner, TrackInstallEvent() is called in 399 // If WebAPK is installed from this banner, TrackInstallEvent() is called in
396 // WebApkInstaller::OnResult(). 400 // WebApkInstaller::OnResult().
397 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); 401 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS);
398 } 402 }
399 } 403 }
400 404
401 infobars::InfoBarDelegate::InfoBarIdentifier 405 infobars::InfoBarDelegate::InfoBarIdentifier
402 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { 406 AppBannerInfoBarDelegateAndroid::GetIdentifier() const {
403 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; 407 return APP_BANNER_INFOBAR_DELEGATE_ANDROID;
404 } 408 }
405 409
406 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { 410 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const {
407 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); 411 return gfx::Image::CreateFrom1xBitmap(primary_icon_);
408 } 412 }
409 413
410 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { 414 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() {
411 has_user_interaction_ = true; 415 has_user_interaction_ = true;
412 416
413 content::WebContents* web_contents = 417 content::WebContents* web_contents =
414 InfoBarService::WebContentsFromInfoBar(infobar()); 418 InfoBarService::WebContentsFromInfoBar(infobar());
415 419
416 if (weak_manager_ && TriggeredFromBanner()) 420 if (weak_manager_ && TriggeredFromBanner())
417 weak_manager_->SendBannerDismissed(event_request_id_); 421 weak_manager_->SendBannerDismissed(event_request_id_);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 462
459 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 463 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
460 return true; 464 return true;
461 } 465 }
462 466
463 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 467 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
464 return RegisterNativesImpl(env); 468 return RegisterNativesImpl(env);
465 } 469 }
466 470
467 } // namespace banners 471 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698