Chromium Code Reviews| 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 "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/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 std::move(infobar_delegate), native_app_data)); | 107 std::move(infobar_delegate), native_app_data)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { | 110 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { |
| 111 weak_ptr_factory_.InvalidateWeakPtrs(); | 111 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 112 | 112 |
| 113 if (!has_user_interaction_) { | 113 if (!has_user_interaction_) { |
| 114 if (!native_app_data_.is_null()) { | 114 if (!native_app_data_.is_null()) { |
| 115 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); | 115 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); |
| 116 } else { | 116 } else { |
| 117 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); | 117 if (TriggeredFromBanner()) |
| 118 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); | |
| 118 if (is_webapk_) | 119 if (is_webapk_) |
| 119 webapk::TrackInstallEvent(webapk::INFOBAR_IGNORED); | 120 webapk::TrackInstallEvent(webapk::INFOBAR_IGNORED); |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 | 123 |
| 123 TrackDismissEvent(DISMISS_EVENT_DISMISSED); | 124 if (TriggeredFromBanner()) |
| 125 TrackDismissEvent(DISMISS_EVENT_DISMISSED); | |
| 124 JNIEnv* env = base::android::AttachCurrentThread(); | 126 JNIEnv* env = base::android::AttachCurrentThread(); |
| 125 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); | 127 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); |
| 126 java_delegate_.Reset(); | 128 java_delegate_.Reset(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( | 131 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( |
| 130 JNIEnv* env, | 132 JNIEnv* env, |
| 131 const JavaParamRef<jobject>& obj) { | 133 const JavaParamRef<jobject>& obj) { |
| 132 if (native_app_data_.is_null() && !is_webapk_) | 134 if (native_app_data_.is_null() && !is_webapk_) |
| 133 return; | 135 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 infobar()->owner()->RemoveInfoBar(infobar()); | 179 infobar()->owner()->RemoveInfoBar(infobar()); |
| 178 } | 180 } |
| 179 } | 181 } |
| 180 | 182 |
| 181 bool AppBannerInfoBarDelegateAndroid::Accept() { | 183 bool AppBannerInfoBarDelegateAndroid::Accept() { |
| 182 has_user_interaction_ = true; | 184 has_user_interaction_ = true; |
| 183 | 185 |
| 184 content::WebContents* web_contents = | 186 content::WebContents* web_contents = |
| 185 InfoBarService::WebContentsFromInfoBar(infobar()); | 187 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 186 if (!web_contents) { | 188 if (!web_contents) { |
| 187 TrackDismissEvent(DISMISS_EVENT_ERROR); | 189 if (TriggeredFromBanner()) |
| 190 TrackDismissEvent(DISMISS_EVENT_ERROR); | |
| 188 return true; | 191 return true; |
| 189 } | 192 } |
| 190 | 193 |
| 191 if (!native_app_data_.is_null()) | 194 if (!native_app_data_.is_null()) |
| 192 return AcceptNativeApp(web_contents); | 195 return AcceptNativeApp(web_contents); |
| 193 | 196 |
| 194 if (is_webapk_) | 197 if (is_webapk_) |
| 195 return AcceptWebApk(web_contents); | 198 return AcceptWebApk(web_contents); |
| 196 | 199 |
| 197 return AcceptWebApp(web_contents); | 200 return AcceptWebApp(web_contents); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 // WebAPK. | 317 // WebAPK. |
| 315 if (install_state_ == INSTALLED) { | 318 if (install_state_ == INSTALLED) { |
| 316 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); | 319 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); |
| 317 if (is_webapk_already_installed_) | 320 if (is_webapk_already_installed_) |
| 318 webapk::TrackUserAction(webapk::USER_ACTION_OPEN); | 321 webapk::TrackUserAction(webapk::USER_ACTION_OPEN); |
| 319 else | 322 else |
| 320 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 323 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
| 321 SendBannerAccepted(); | 324 SendBannerAccepted(); |
| 322 return true; | 325 return true; |
| 323 } | 326 } |
| 324 | 327 |
|
pkotwicz
2016/11/04 01:34:33
Nit: Move the comment on lines 337 - 338 here. The
dominickn
2016/11/04 01:44:51
Done.
| |
| 328 if (TriggeredFromBanner()) { | |
| 329 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | |
| 330 AppBannerSettingsHelper::RecordBannerInstallEvent( | |
| 331 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | |
| 332 } | |
| 333 | |
| 334 install_state_ = INSTALLING; | |
| 335 webapk::TrackInstallSource(webapk_install_source_); | |
| 336 | |
| 325 // If the WebAPK is not installed and the "Add to Home Screen" button is | 337 // If the WebAPK is not installed and the "Add to Home Screen" button is |
| 326 // clicked, install the WebAPK. | 338 // clicked, install the WebAPK. |
| 327 install_state_ = INSTALLING; | |
| 328 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | |
| 329 webapk::TrackInstallSource(webapk_install_source_); | |
| 330 AppBannerSettingsHelper::RecordBannerInstallEvent( | |
| 331 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | |
| 332 | |
| 333 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 339 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 334 env, java_delegate_, true); | 340 env, java_delegate_, true); |
| 335 UpdateInstallState(env, nullptr); | 341 UpdateInstallState(env, nullptr); |
| 336 WebApkInstaller::FinishCallback callback = | 342 WebApkInstaller::FinishCallback callback = |
| 337 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 343 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
| 338 weak_ptr_factory_.GetWeakPtr()); | 344 weak_ptr_factory_.GetWeakPtr()); |
| 339 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), | 345 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), |
| 340 *shortcut_info_, | 346 *shortcut_info_, |
| 341 *icon_.get(), callback); | 347 *icon_.get(), callback); |
| 342 SendBannerAccepted(); | 348 SendBannerAccepted(); |
| 343 | 349 |
| 344 // Prevent the infobar from disappearing, because the infobar will show | 350 // Prevent the infobar from disappearing, because the infobar will show |
| 345 // "Adding" during the installation process. | 351 // "Adding" during the installation process. |
| 346 return false; | 352 return false; |
| 347 } | 353 } |
| 348 | 354 |
| 355 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { | |
| 356 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; | |
| 357 } | |
| 358 | |
| 349 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() { | 359 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() { |
| 350 if (weak_manager_) | 360 if (weak_manager_ && TriggeredFromBanner()) |
| 351 weak_manager_->SendBannerAccepted(event_request_id_); | 361 weak_manager_->SendBannerAccepted(event_request_id_); |
| 352 } | 362 } |
| 353 | 363 |
| 354 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( | 364 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( |
| 355 bool success, | 365 bool success, |
| 356 const std::string& webapk_package_name) { | 366 const std::string& webapk_package_name) { |
| 357 JNIEnv* env = base::android::AttachCurrentThread(); | 367 JNIEnv* env = base::android::AttachCurrentThread(); |
| 358 if (!success) { | 368 if (!success) { |
| 359 DVLOG(1) << "The WebAPK installation failed."; | 369 DVLOG(1) << "The WebAPK installation failed."; |
| 360 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); | 370 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { | 402 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { |
| 393 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); | 403 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); |
| 394 } | 404 } |
| 395 | 405 |
| 396 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { | 406 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { |
| 397 has_user_interaction_ = true; | 407 has_user_interaction_ = true; |
| 398 | 408 |
| 399 content::WebContents* web_contents = | 409 content::WebContents* web_contents = |
| 400 InfoBarService::WebContentsFromInfoBar(infobar()); | 410 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 401 | 411 |
| 402 if (weak_manager_) | 412 if (weak_manager_ && TriggeredFromBanner()) |
| 403 weak_manager_->SendBannerDismissed(event_request_id_); | 413 weak_manager_->SendBannerDismissed(event_request_id_); |
| 404 | 414 |
| 405 if (native_app_data_.is_null()) { | 415 if (native_app_data_.is_null()) { |
| 406 if (is_webapk_) | 416 if (is_webapk_) |
| 407 TrackWebApkInstallationDismissEvents(install_state_); | 417 TrackWebApkInstallationDismissEvents(install_state_); |
| 408 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); | 418 if (TriggeredFromBanner()) { |
| 409 AppBannerSettingsHelper::RecordBannerDismissEvent( | 419 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); |
| 410 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 420 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 421 web_contents, shortcut_info_->url.spec(), | |
| 422 AppBannerSettingsHelper::WEB); | |
| 423 } | |
| 411 } else { | 424 } else { |
| 412 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); | 425 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); |
| 413 AppBannerSettingsHelper::RecordBannerDismissEvent( | 426 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 414 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); | 427 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); |
| 415 } | 428 } |
| 416 } | 429 } |
| 417 | 430 |
| 418 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { | 431 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { |
| 419 return app_title_; | 432 return app_title_; |
| 420 } | 433 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 441 | 454 |
| 442 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 455 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 443 return true; | 456 return true; |
| 444 } | 457 } |
| 445 | 458 |
| 446 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 459 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 447 return RegisterNativesImpl(env); | 460 return RegisterNativesImpl(env); |
| 448 } | 461 } |
| 449 | 462 |
| 450 } // namespace banners | 463 } // namespace banners |
| OLD | NEW |