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