| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/android/shortcut_helper.h" | 14 #include "chrome/browser/android/shortcut_helper.h" |
| 15 #include "chrome/browser/android/shortcut_info.h" | 15 #include "chrome/browser/android/shortcut_info.h" |
| 16 #include "chrome/browser/android/tab_android.h" | 16 #include "chrome/browser/android/tab_android.h" |
| 17 #include "chrome/browser/android/webapk/webapk_installer.h" | 17 #include "chrome/browser/android/webapk/webapk_installer.h" |
| 18 #include "chrome/browser/android/webapk/webapk_metrics.h" |
| 18 #include "chrome/browser/banners/app_banner_manager.h" | 19 #include "chrome/browser/banners/app_banner_manager.h" |
| 19 #include "chrome/browser/banners/app_banner_metrics.h" | 20 #include "chrome/browser/banners/app_banner_metrics.h" |
| 20 #include "chrome/browser/banners/app_banner_settings_helper.h" | 21 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/infobars/infobar_service.h" | 23 #include "chrome/browser/infobars/infobar_service.h" |
| 23 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 24 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| 24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 25 #include "components/rappor/rappor_utils.h" | 26 #include "components/rappor/rappor_utils.h" |
| 26 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/manifest.h" | 29 #include "content/public/common/manifest.h" |
| 29 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" | 30 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" |
| 30 #include "ui/gfx/android/java_bitmap.h" | 31 #include "ui/gfx/android/java_bitmap.h" |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 | 33 |
| 33 using base::android::ConvertJavaStringToUTF8; | 34 using base::android::ConvertJavaStringToUTF8; |
| 34 using base::android::ConvertJavaStringToUTF16; | 35 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertUTF8ToJavaString; | 36 using base::android::ConvertUTF8ToJavaString; |
| 36 using base::android::ConvertUTF16ToJavaString; | 37 using base::android::ConvertUTF16ToJavaString; |
| 37 using base::android::JavaParamRef; | 38 using base::android::JavaParamRef; |
| 38 using base::android::ScopedJavaLocalRef; | 39 using base::android::ScopedJavaLocalRef; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) { | 43 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) { |
| 43 return !info || info->url.is_empty(); | 44 return !info || info->url.is_empty(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 } | 47 } // anonymous namespace |
| 47 | 48 |
| 48 namespace banners { | 49 namespace banners { |
| 49 | 50 |
| 50 // static | 51 // static |
| 51 bool AppBannerInfoBarDelegateAndroid::Create( | 52 bool AppBannerInfoBarDelegateAndroid::Create( |
| 52 content::WebContents* web_contents, | 53 content::WebContents* web_contents, |
| 53 base::WeakPtr<AppBannerManager> weak_manager, | 54 base::WeakPtr<AppBannerManager> weak_manager, |
| 54 const base::string16& app_title, | 55 const base::string16& app_title, |
| 55 std::unique_ptr<ShortcutInfo> shortcut_info, | 56 std::unique_ptr<ShortcutInfo> shortcut_info, |
| 56 std::unique_ptr<SkBitmap> icon, | 57 std::unique_ptr<SkBitmap> icon, |
| 57 int event_request_id, | 58 int event_request_id, |
| 58 bool is_webapk, | 59 bool is_webapk, |
| 59 bool start_install_webapk) { | 60 bool start_install_webapk) { |
| 60 const GURL& url = shortcut_info->url; | 61 const GURL& url = shortcut_info->url; |
| 61 auto infobar_delegate = | 62 auto infobar_delegate = |
| 62 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( | 63 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( |
| 63 weak_manager, app_title, std::move(shortcut_info), std::move(icon), | 64 weak_manager, app_title, std::move(shortcut_info), std::move(icon), |
| 64 event_request_id, is_webapk)); | 65 event_request_id, is_webapk)); |
| 65 auto raw_delegate = infobar_delegate.get(); | 66 auto raw_delegate = infobar_delegate.get(); |
| 66 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( | 67 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( |
| 67 std::move(infobar_delegate), url, is_webapk); | 68 std::move(infobar_delegate), url, is_webapk); |
| 68 if (!InfoBarService::FromWebContents(web_contents) | 69 if (!InfoBarService::FromWebContents(web_contents) |
| 69 ->AddInfoBar(std::move(infobar))) | 70 ->AddInfoBar(std::move(infobar))) |
| 70 return false; | 71 return false; |
| 71 | 72 |
| 72 if (is_webapk && start_install_webapk) | 73 if (is_webapk) { |
| 73 raw_delegate->AcceptWebApk(web_contents); | 74 if (start_install_webapk) { |
| 75 raw_delegate->AcceptWebApk(web_contents); |
| 76 webapk::TrackInstallInfoBarShown(webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU); |
| 77 webapk::TrackInstallSource(webapk::INSTALL_SOURCE_MENU); |
| 78 } else { |
| 79 webapk::TrackInstallInfoBarShown( |
| 80 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER); |
| 81 } |
| 82 } |
| 74 | 83 |
| 75 return true; | 84 return true; |
| 76 } | 85 } |
| 77 | 86 |
| 78 // static | 87 // static |
| 79 bool AppBannerInfoBarDelegateAndroid::Create( | 88 bool AppBannerInfoBarDelegateAndroid::Create( |
| 80 content::WebContents* web_contents, | 89 content::WebContents* web_contents, |
| 81 const base::string16& app_title, | 90 const base::string16& app_title, |
| 82 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 91 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 83 std::unique_ptr<SkBitmap> icon, | 92 std::unique_ptr<SkBitmap> icon, |
| 84 const std::string& native_app_package, | 93 const std::string& native_app_package, |
| 85 const std::string& referrer, | 94 const std::string& referrer, |
| 86 int event_request_id) { | 95 int event_request_id) { |
| 87 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid( | 96 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid( |
| 88 app_title, native_app_data, std::move(icon), native_app_package, referrer, | 97 app_title, native_app_data, std::move(icon), native_app_package, referrer, |
| 89 event_request_id)); | 98 event_request_id)); |
| 90 return InfoBarService::FromWebContents(web_contents) | 99 return InfoBarService::FromWebContents(web_contents) |
| 91 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>( | 100 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>( |
| 92 std::move(infobar_delegate), native_app_data)); | 101 std::move(infobar_delegate), native_app_data)); |
| 93 } | 102 } |
| 94 | 103 |
| 95 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { | 104 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { |
| 96 weak_ptr_factory_.InvalidateWeakPtrs(); | 105 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 97 | 106 |
| 98 if (!has_user_interaction_) { | 107 if (!has_user_interaction_) { |
| 99 if (!native_app_data_.is_null()) | 108 if (!native_app_data_.is_null()) { |
| 100 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); | 109 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); |
| 101 else if (!IsInfoEmpty(shortcut_info_)) | 110 } else { |
| 102 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); | 111 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); |
| 112 if (is_webapk_) |
| 113 webapk::TrackInstallEvent(webapk::INFOBAR_IGNORED); |
| 114 } |
| 103 } | 115 } |
| 104 | 116 |
| 105 TrackDismissEvent(DISMISS_EVENT_DISMISSED); | 117 TrackDismissEvent(DISMISS_EVENT_DISMISSED); |
| 106 JNIEnv* env = base::android::AttachCurrentThread(); | 118 JNIEnv* env = base::android::AttachCurrentThread(); |
| 107 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); | 119 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); |
| 108 java_delegate_.Reset(); | 120 java_delegate_.Reset(); |
| 109 } | 121 } |
| 110 | 122 |
| 111 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( | 123 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( |
| 112 JNIEnv* env, | 124 JNIEnv* env, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); | 167 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); |
| 156 UpdateInstallState(env, obj); | 168 UpdateInstallState(env, obj); |
| 157 } else if (infobar()->owner()) { | 169 } else if (infobar()->owner()) { |
| 158 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); | 170 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); |
| 159 infobar()->owner()->RemoveInfoBar(infobar()); | 171 infobar()->owner()->RemoveInfoBar(infobar()); |
| 160 } | 172 } |
| 161 } | 173 } |
| 162 | 174 |
| 163 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | 175 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
| 164 content::WebContents* web_contents) { | 176 content::WebContents* web_contents) { |
| 177 has_user_interaction_ = true; |
| 165 if (IsInfoEmpty(shortcut_info_)) | 178 if (IsInfoEmpty(shortcut_info_)) |
| 166 return true; | 179 return true; |
| 167 | 180 |
| 168 JNIEnv* env = base::android::AttachCurrentThread(); | 181 JNIEnv* env = base::android::AttachCurrentThread(); |
| 169 // |webapk_package_name_| is set when the WebAPK has finished installing. | 182 // |webapk_package_name_| is set when the WebAPK has finished installing. |
| 170 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" | 183 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" |
| 171 // button is pressed, so request WebAPK installation. Otherwise, it means | 184 // button is pressed, so request WebAPK installation. Otherwise, it means |
| 172 // the "Open" button is pressed, so open the installed WebAPK. | 185 // the "Open" button is pressed, so open the installed WebAPK. |
| 173 if (!webapk_package_name_.empty()) { | 186 if (!webapk_package_name_.empty()) { |
| 174 // Open the WebAPK. | 187 // Open the WebAPK. |
| 175 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 188 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
| 176 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); | 189 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); |
| 177 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, | 190 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, |
| 178 java_webapk_package_name); | 191 java_webapk_package_name); |
| 179 | 192 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
| 180 SendBannerAccepted(web_contents, "web"); | 193 SendBannerAccepted(web_contents, "web"); |
| 181 return true; | 194 return true; |
| 182 } | 195 } |
| 183 | 196 |
| 184 // Request install the WebAPK. | 197 // Request install the WebAPK. |
| 198 install_state_ = INSTALLING; |
| 185 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 199 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 186 AppBannerSettingsHelper::RecordBannerInstallEvent( | 200 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 187 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 201 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 188 | 202 |
| 189 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 203 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 190 env, java_delegate_, true); | 204 env, java_delegate_, true); |
| 191 UpdateInstallState(env, nullptr); | 205 UpdateInstallState(env, nullptr); |
| 192 WebApkInstaller::FinishCallback callback = | 206 WebApkInstaller::FinishCallback callback = |
| 193 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 207 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
| 194 weak_ptr_factory_.GetWeakPtr()); | 208 weak_ptr_factory_.GetWeakPtr()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 209 std::unique_ptr<SkBitmap> icon, | 223 std::unique_ptr<SkBitmap> icon, |
| 210 int event_request_id, | 224 int event_request_id, |
| 211 bool is_webapk) | 225 bool is_webapk) |
| 212 : weak_manager_(weak_manager), | 226 : weak_manager_(weak_manager), |
| 213 app_title_(app_title), | 227 app_title_(app_title), |
| 214 shortcut_info_(std::move(shortcut_info)), | 228 shortcut_info_(std::move(shortcut_info)), |
| 215 icon_(std::move(icon)), | 229 icon_(std::move(icon)), |
| 216 event_request_id_(event_request_id), | 230 event_request_id_(event_request_id), |
| 217 has_user_interaction_(false), | 231 has_user_interaction_(false), |
| 218 is_webapk_(is_webapk), | 232 is_webapk_(is_webapk), |
| 233 install_state_(INSTALL_NOT_STARTED), |
| 219 weak_ptr_factory_(this) { | 234 weak_ptr_factory_(this) { |
| 220 DCHECK(!IsInfoEmpty(shortcut_info_)); | 235 DCHECK(!IsInfoEmpty(shortcut_info_)); |
| 221 CreateJavaDelegate(); | 236 CreateJavaDelegate(); |
| 222 } | 237 } |
| 223 | 238 |
| 224 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 239 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 225 const base::string16& app_title, | 240 const base::string16& app_title, |
| 226 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 241 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 227 std::unique_ptr<SkBitmap> icon, | 242 std::unique_ptr<SkBitmap> icon, |
| 228 const std::string& native_app_package, | 243 const std::string& native_app_package, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 285 |
| 271 content::WebContents* web_contents = | 286 content::WebContents* web_contents = |
| 272 InfoBarService::WebContentsFromInfoBar(infobar()); | 287 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 273 | 288 |
| 274 web_contents->GetMainFrame()->Send( | 289 web_contents->GetMainFrame()->Send( |
| 275 new ChromeViewMsg_AppBannerDismissed( | 290 new ChromeViewMsg_AppBannerDismissed( |
| 276 web_contents->GetMainFrame()->GetRoutingID(), | 291 web_contents->GetMainFrame()->GetRoutingID(), |
| 277 event_request_id_)); | 292 event_request_id_)); |
| 278 | 293 |
| 279 if (native_app_data_.is_null()) { | 294 if (native_app_data_.is_null()) { |
| 295 if (is_webapk_) |
| 296 TrackWebApkInstallationDismissEvents(install_state_); |
| 280 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); | 297 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); |
| 281 AppBannerSettingsHelper::RecordBannerDismissEvent( | 298 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 282 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 299 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 283 } else { | 300 } else { |
| 284 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); | 301 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); |
| 285 AppBannerSettingsHelper::RecordBannerDismissEvent( | 302 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 286 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); | 303 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); |
| 287 } | 304 } |
| 288 } | 305 } |
| 289 | 306 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 301 content::WebContents* web_contents = | 318 content::WebContents* web_contents = |
| 302 InfoBarService::WebContentsFromInfoBar(infobar()); | 319 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 303 if (!web_contents) { | 320 if (!web_contents) { |
| 304 TrackDismissEvent(DISMISS_EVENT_ERROR); | 321 TrackDismissEvent(DISMISS_EVENT_ERROR); |
| 305 return true; | 322 return true; |
| 306 } | 323 } |
| 307 | 324 |
| 308 if (!native_app_data_.is_null()) | 325 if (!native_app_data_.is_null()) |
| 309 return AcceptNativeApp(web_contents); | 326 return AcceptNativeApp(web_contents); |
| 310 | 327 |
| 311 if (is_webapk_) | 328 if (is_webapk_) { |
| 329 webapk::TrackInstallSource(webapk::INSTALL_SOURCE_BANNER); |
| 312 return AcceptWebApk(web_contents); | 330 return AcceptWebApk(web_contents); |
| 331 } |
| 313 | 332 |
| 314 return AcceptWebApp(web_contents); | 333 return AcceptWebApp(web_contents); |
| 315 } | 334 } |
| 316 | 335 |
| 317 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( | 336 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( |
| 318 content::WebContents* web_contents) { | 337 content::WebContents* web_contents) { |
| 319 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); | 338 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); |
| 320 JNIEnv* env = base::android::AttachCurrentThread(); | 339 JNIEnv* env = base::android::AttachCurrentThread(); |
| 321 | 340 |
| 322 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 341 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 return true; | 377 return true; |
| 359 } | 378 } |
| 360 | 379 |
| 361 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( | 380 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( |
| 362 bool success, | 381 bool success, |
| 363 const std::string& webapk_package_name) { | 382 const std::string& webapk_package_name) { |
| 364 JNIEnv* env = base::android::AttachCurrentThread(); | 383 JNIEnv* env = base::android::AttachCurrentThread(); |
| 365 if (!success) { | 384 if (!success) { |
| 366 DVLOG(1) << "The WebAPK installation failed."; | 385 DVLOG(1) << "The WebAPK installation failed."; |
| 367 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); | 386 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); |
| 387 webapk::TrackInstallEvent(webapk::INSTALL_FAILED); |
| 368 if (infobar()) | 388 if (infobar()) |
| 369 infobar()->RemoveSelf(); | 389 infobar()->RemoveSelf(); |
| 370 return; | 390 return; |
| 371 } | 391 } |
| 372 | 392 |
| 373 webapk_package_name_ = webapk_package_name; | 393 webapk_package_name_ = webapk_package_name; |
| 374 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 394 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
| 375 base::android::ConvertUTF8ToJavaString(env, webapk_package_name); | 395 base::android::ConvertUTF8ToJavaString(env, webapk_package_name); |
| 376 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 396 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 377 env, java_delegate_, false); | 397 env, java_delegate_, false); |
| 378 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( | 398 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( |
| 379 env, java_delegate_, java_webapk_package_name); | 399 env, java_delegate_, java_webapk_package_name); |
| 380 UpdateInstallState(env, nullptr); | 400 UpdateInstallState(env, nullptr); |
| 401 install_state_ = INSTALLED; |
| 402 webapk::TrackInstallEvent(webapk::INSTALL_COMPLETED); |
| 403 } |
| 404 |
| 405 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( |
| 406 InstallState install_state) { |
| 407 if (install_state == INSTALL_NOT_STARTED) { |
| 408 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); |
| 409 } else if (install_state == INSTALLING) { |
| 410 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); |
| 411 } else if (install_state == INSTALLED) { |
| 412 // When |install_state| is INSTALLED, the install Event will be recorded in |
| 413 // OnWebApkInstallFinished(). |
| 414 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); |
| 415 } |
| 381 } | 416 } |
| 382 | 417 |
| 383 bool AppBannerInfoBarDelegateAndroid::LinkClicked( | 418 bool AppBannerInfoBarDelegateAndroid::LinkClicked( |
| 384 WindowOpenDisposition disposition) { | 419 WindowOpenDisposition disposition) { |
| 385 if (native_app_data_.is_null()) | 420 if (native_app_data_.is_null()) |
| 386 return false; | 421 return false; |
| 387 | 422 |
| 388 // Try to show the details for the native app. | 423 // Try to show the details for the native app. |
| 389 JNIEnv* env = base::android::AttachCurrentThread(); | 424 JNIEnv* env = base::android::AttachCurrentThread(); |
| 390 | 425 |
| 391 content::WebContents* web_contents = | 426 content::WebContents* web_contents = |
| 392 InfoBarService::WebContentsFromInfoBar(infobar()); | 427 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 393 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 428 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 394 DCHECK(tab); | 429 DCHECK(tab); |
| 395 | 430 |
| 396 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( | 431 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( |
| 397 env, java_delegate_, tab->GetJavaObject(), native_app_data_); | 432 env, java_delegate_, tab->GetJavaObject(), native_app_data_); |
| 398 | 433 |
| 399 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 434 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 400 return true; | 435 return true; |
| 401 } | 436 } |
| 402 | 437 |
| 403 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 438 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 404 return RegisterNativesImpl(env); | 439 return RegisterNativesImpl(env); |
| 405 } | 440 } |
| 406 | 441 |
| 407 } // namespace banners | 442 } // namespace banners |
| OLD | NEW |