| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 using base::android::ConvertJavaStringToUTF8; | 33 using base::android::ConvertJavaStringToUTF8; |
| 34 using base::android::ConvertJavaStringToUTF16; | 34 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertUTF8ToJavaString; | 35 using base::android::ConvertUTF8ToJavaString; |
| 36 using base::android::ConvertUTF16ToJavaString; | 36 using base::android::ConvertUTF16ToJavaString; |
| 37 using base::android::JavaParamRef; | 37 using base::android::JavaParamRef; |
| 38 using base::android::ScopedJavaLocalRef; | 38 using base::android::ScopedJavaLocalRef; |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 bool IsInfoEmpty(const ShortcutInfo* info) { | 42 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) { |
| 43 return !info || info->url.is_empty(); | 43 return !info || info->url.is_empty(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 } | 46 } |
| 47 | 47 |
| 48 namespace banners { | 48 namespace banners { |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 bool AppBannerInfoBarDelegateAndroid::Create( | 51 bool AppBannerInfoBarDelegateAndroid::Create( |
| 52 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>( | 91 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>( |
| 92 std::move(infobar_delegate), native_app_data)); | 92 std::move(infobar_delegate), native_app_data)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { | 95 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { |
| 96 weak_ptr_factory_.InvalidateWeakPtrs(); | 96 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 97 | 97 |
| 98 if (!has_user_interaction_) { | 98 if (!has_user_interaction_) { |
| 99 if (!native_app_data_.is_null()) | 99 if (!native_app_data_.is_null()) |
| 100 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); | 100 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); |
| 101 else if (!IsInfoEmpty(shortcut_info_.get())) | 101 else if (!IsInfoEmpty(shortcut_info_)) |
| 102 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); | 102 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TrackDismissEvent(DISMISS_EVENT_DISMISSED); | 105 TrackDismissEvent(DISMISS_EVENT_DISMISSED); |
| 106 JNIEnv* env = base::android::AttachCurrentThread(); | 106 JNIEnv* env = base::android::AttachCurrentThread(); |
| 107 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); | 107 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); |
| 108 java_delegate_.Reset(); | 108 java_delegate_.Reset(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( | 111 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); | 155 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); |
| 156 UpdateInstallState(env, obj); | 156 UpdateInstallState(env, obj); |
| 157 } else if (infobar()->owner()) { | 157 } else if (infobar()->owner()) { |
| 158 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); | 158 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); |
| 159 infobar()->owner()->RemoveInfoBar(infobar()); | 159 infobar()->owner()->RemoveInfoBar(infobar()); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | 163 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
| 164 content::WebContents* web_contents) { | 164 content::WebContents* web_contents) { |
| 165 if (IsInfoEmpty(shortcut_info_.get())) | 165 if (IsInfoEmpty(shortcut_info_)) |
| 166 return true; | 166 return true; |
| 167 | 167 |
| 168 JNIEnv* env = base::android::AttachCurrentThread(); | 168 JNIEnv* env = base::android::AttachCurrentThread(); |
| 169 // |webapk_package_name_| is set when the WebAPK has finished installing. | 169 // |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" | 170 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" |
| 171 // button is pressed, so request WebAPK installation. Otherwise, it means | 171 // button is pressed, so request WebAPK installation. Otherwise, it means |
| 172 // the "Open" button is pressed, so open the installed WebAPK. | 172 // the "Open" button is pressed, so open the installed WebAPK. |
| 173 if (!webapk_package_name_.empty()) { | 173 if (!webapk_package_name_.empty()) { |
| 174 // Open the WebAPK. | 174 // Open the WebAPK. |
| 175 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 175 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 int event_request_id, | 210 int event_request_id, |
| 211 bool is_webapk) | 211 bool is_webapk) |
| 212 : weak_manager_(weak_manager), | 212 : weak_manager_(weak_manager), |
| 213 app_title_(app_title), | 213 app_title_(app_title), |
| 214 shortcut_info_(std::move(shortcut_info)), | 214 shortcut_info_(std::move(shortcut_info)), |
| 215 icon_(std::move(icon)), | 215 icon_(std::move(icon)), |
| 216 event_request_id_(event_request_id), | 216 event_request_id_(event_request_id), |
| 217 has_user_interaction_(false), | 217 has_user_interaction_(false), |
| 218 is_webapk_(is_webapk), | 218 is_webapk_(is_webapk), |
| 219 weak_ptr_factory_(this) { | 219 weak_ptr_factory_(this) { |
| 220 DCHECK(!IsInfoEmpty(shortcut_info_.get())); | 220 DCHECK(!IsInfoEmpty(shortcut_info_)); |
| 221 CreateJavaDelegate(); | 221 CreateJavaDelegate(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 224 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 225 const base::string16& app_title, | 225 const base::string16& app_title, |
| 226 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 226 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 227 std::unique_ptr<SkBitmap> icon, | 227 std::unique_ptr<SkBitmap> icon, |
| 228 const std::string& native_app_package, | 228 const std::string& native_app_package, |
| 229 const std::string& referrer, | 229 const std::string& referrer, |
| 230 int event_request_id) | 230 int event_request_id) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 has_user_interaction_ = true; | 269 has_user_interaction_ = true; |
| 270 | 270 |
| 271 content::WebContents* web_contents = | 271 content::WebContents* web_contents = |
| 272 InfoBarService::WebContentsFromInfoBar(infobar()); | 272 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 273 | 273 |
| 274 web_contents->GetMainFrame()->Send( | 274 web_contents->GetMainFrame()->Send( |
| 275 new ChromeViewMsg_AppBannerDismissed( | 275 new ChromeViewMsg_AppBannerDismissed( |
| 276 web_contents->GetMainFrame()->GetRoutingID(), | 276 web_contents->GetMainFrame()->GetRoutingID(), |
| 277 event_request_id_)); | 277 event_request_id_)); |
| 278 | 278 |
| 279 if (!native_app_data_.is_null()) { | 279 if (native_app_data_.is_null()) { |
| 280 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); |
| 281 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 282 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 283 } else { |
| 280 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); | 284 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); |
| 281 AppBannerSettingsHelper::RecordBannerDismissEvent( | 285 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 282 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); | 286 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); |
| 283 } else { | |
| 284 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); | |
| 285 AppBannerSettingsHelper::RecordBannerDismissEvent( | |
| 286 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { | 290 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { |
| 291 return app_title_; | 291 return app_title_; |
| 292 } | 292 } |
| 293 | 293 |
| 294 int AppBannerInfoBarDelegateAndroid::GetButtons() const { | 294 int AppBannerInfoBarDelegateAndroid::GetButtons() const { |
| 295 return BUTTON_OK; | 295 return BUTTON_OK; |
| 296 } | 296 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); | 333 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); |
| 334 else | 334 else |
| 335 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); | 335 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); |
| 336 | 336 |
| 337 SendBannerAccepted(web_contents, "play"); | 337 SendBannerAccepted(web_contents, "play"); |
| 338 return was_opened; | 338 return was_opened; |
| 339 } | 339 } |
| 340 | 340 |
| 341 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( | 341 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( |
| 342 content::WebContents* web_contents) { | 342 content::WebContents* web_contents) { |
| 343 if (IsInfoEmpty(shortcut_info_.get())) | 343 if (IsInfoEmpty(shortcut_info_)) |
| 344 return true; | 344 return true; |
| 345 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 345 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 346 | 346 |
| 347 AppBannerSettingsHelper::RecordBannerInstallEvent( | 347 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 348 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 348 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 349 | 349 |
| 350 if (weak_manager_) { | 350 if (weak_manager_) { |
| 351 const std::string& uid = base::GenerateGUID(); | 351 const std::string& uid = base::GenerateGUID(); |
| 352 ShortcutHelper::AddToLauncherWithSkBitmap( | 352 ShortcutHelper::AddToLauncherWithSkBitmap( |
| 353 web_contents->GetBrowserContext(), *shortcut_info_, uid, | 353 web_contents->GetBrowserContext(), *shortcut_info_, uid, |
| 354 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid)); | 354 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 SendBannerAccepted(web_contents, "web"); | 357 SendBannerAccepted(web_contents, "web"); |
| 358 return true; | 358 return true; |
| 359 } | 359 } |
| 360 | 360 |
| 361 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( | 361 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( |
| 362 bool success, | 362 bool success, |
| 363 const std::string& webapk_package_name) { | 363 const std::string& webapk_package_name) { |
| 364 JNIEnv* env = base::android::AttachCurrentThread(); | 364 JNIEnv* env = base::android::AttachCurrentThread(); |
| 365 if (!success) { | 365 if (!success) { |
| 366 // The installation failed. | 366 DVLOG(1) << "The WebAPK installation failed."; |
| 367 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); |
| 367 if (infobar()) | 368 if (infobar()) |
| 368 infobar()->RemoveSelf(); | 369 infobar()->RemoveSelf(); |
| 369 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); | |
| 370 DVLOG(1) << "The WebAPK installation failed."; | |
| 371 return; | 370 return; |
| 372 } | 371 } |
| 373 | 372 |
| 374 webapk_package_name_ = webapk_package_name; | 373 webapk_package_name_ = webapk_package_name; |
| 375 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 374 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
| 376 base::android::ConvertUTF8ToJavaString(env, webapk_package_name); | 375 base::android::ConvertUTF8ToJavaString(env, webapk_package_name); |
| 377 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 376 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 378 env, java_delegate_, false); | 377 env, java_delegate_, false); |
| 379 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( | 378 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( |
| 380 env, java_delegate_, java_webapk_package_name); | 379 env, java_delegate_, java_webapk_package_name); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 399 | 398 |
| 400 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 399 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 401 return true; | 400 return true; |
| 402 } | 401 } |
| 403 | 402 |
| 404 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 403 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 405 return RegisterNativesImpl(env); | 404 return RegisterNativesImpl(env); |
| 406 } | 405 } |
| 407 | 406 |
| 408 } // namespace banners | 407 } // namespace banners |
| OLD | NEW |