| 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" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "chrome/browser/android/shortcut_helper.h" | 12 #include "chrome/browser/android/shortcut_helper.h" |
| 15 #include "chrome/browser/android/shortcut_info.h" | 13 #include "chrome/browser/android/shortcut_info.h" |
| 16 #include "chrome/browser/android/tab_android.h" | 14 #include "chrome/browser/android/tab_android.h" |
| 17 #include "chrome/browser/android/webapk/webapk_installer.h" | 15 #include "chrome/browser/android/webapk/webapk_installer.h" |
| 18 #include "chrome/browser/banners/app_banner_manager.h" | |
| 19 #include "chrome/browser/banners/app_banner_metrics.h" | 16 #include "chrome/browser/banners/app_banner_metrics.h" |
| 20 #include "chrome/browser/banners/app_banner_settings_helper.h" | 17 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 21 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 23 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 20 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| 24 #include "chrome/common/render_messages.h" | |
| 25 #include "components/rappor/rappor_utils.h" | 21 #include "components/rappor/rappor_utils.h" |
| 26 #include "content/public/browser/render_frame_host.h" | |
| 27 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/manifest.h" | 23 #include "content/public/common/manifest.h" |
| 29 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" | 24 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" |
| 30 #include "ui/gfx/android/java_bitmap.h" | 25 #include "ui/gfx/android/java_bitmap.h" |
| 31 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 32 | 27 |
| 33 using base::android::ConvertJavaStringToUTF8; | 28 using base::android::ConvertJavaStringToUTF8; |
| 34 using base::android::ConvertJavaStringToUTF16; | 29 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertUTF8ToJavaString; | 30 using base::android::ConvertUTF8ToJavaString; |
| 36 using base::android::ConvertUTF16ToJavaString; | 31 using base::android::ConvertUTF16ToJavaString; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" | 175 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" |
| 181 // button is pressed, so request WebAPK installation. Otherwise, it means | 176 // button is pressed, so request WebAPK installation. Otherwise, it means |
| 182 // the "Open" button is pressed, so open the installed WebAPK. | 177 // the "Open" button is pressed, so open the installed WebAPK. |
| 183 if (!webapk_package_name_.empty()) { | 178 if (!webapk_package_name_.empty()) { |
| 184 // Open the WebAPK. | 179 // Open the WebAPK. |
| 185 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 180 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
| 186 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); | 181 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); |
| 187 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, | 182 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, |
| 188 java_webapk_package_name); | 183 java_webapk_package_name); |
| 189 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 184 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
| 190 SendBannerAccepted(web_contents, "web"); | 185 SendBannerAccepted(); |
| 191 return true; | 186 return true; |
| 192 } | 187 } |
| 193 | 188 |
| 194 // Check whether the WebAPK has been installed. | 189 // Check whether the WebAPK has been installed. |
| 195 std::string installed_webapk_package_name = | 190 std::string installed_webapk_package_name = |
| 196 ShortcutHelper::QueryWebApkPackage(web_contents->GetLastCommittedURL()); | 191 ShortcutHelper::QueryWebApkPackage(web_contents->GetLastCommittedURL()); |
| 197 if (installed_webapk_package_name.empty()) { | 192 if (installed_webapk_package_name.empty()) { |
| 198 // Request install the WebAPK. | 193 // Request install the WebAPK. |
| 199 install_state_ = INSTALLING; | 194 install_state_ = INSTALLING; |
| 200 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 195 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 201 webapk::TrackInstallSource(webapk_install_source_); | 196 webapk::TrackInstallSource(webapk_install_source_); |
| 202 AppBannerSettingsHelper::RecordBannerInstallEvent( | 197 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 203 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 198 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 204 | 199 |
| 205 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 200 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 206 env, java_delegate_, true); | 201 env, java_delegate_, true); |
| 207 UpdateInstallState(env, nullptr); | 202 UpdateInstallState(env, nullptr); |
| 208 WebApkInstaller::FinishCallback callback = | 203 WebApkInstaller::FinishCallback callback = |
| 209 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 204 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
| 210 weak_ptr_factory_.GetWeakPtr()); | 205 weak_ptr_factory_.GetWeakPtr()); |
| 211 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), | 206 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), |
| 212 *shortcut_info_, | 207 *shortcut_info_, |
| 213 *icon_.get(), callback); | 208 *icon_.get(), callback); |
| 214 SendBannerAccepted(web_contents, "web"); | 209 SendBannerAccepted(); |
| 215 | 210 |
| 216 // Prevent the infobar from disappearing, because the infobar will show | 211 // Prevent the infobar from disappearing, because the infobar will show |
| 217 // "Adding" during the installation process. | 212 // "Adding" during the installation process. |
| 218 return false; | 213 return false; |
| 219 } | 214 } |
| 220 | 215 |
| 221 // Bypass the installation since WebAPK is already installed. | 216 // Bypass the installation since WebAPK is already installed. |
| 222 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 217 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 223 OnWebApkInstallFinished(true, installed_webapk_package_name); | 218 OnWebApkInstallFinished(true, installed_webapk_package_name); |
| 224 return false; | 219 return false; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 DCHECK(!native_app_data_.is_null()); | 259 DCHECK(!native_app_data_.is_null()); |
| 265 CreateJavaDelegate(); | 260 CreateJavaDelegate(); |
| 266 } | 261 } |
| 267 | 262 |
| 268 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { | 263 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { |
| 269 java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create( | 264 java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create( |
| 270 base::android::AttachCurrentThread(), | 265 base::android::AttachCurrentThread(), |
| 271 reinterpret_cast<intptr_t>(this))); | 266 reinterpret_cast<intptr_t>(this))); |
| 272 } | 267 } |
| 273 | 268 |
| 274 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted( | 269 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() { |
| 275 content::WebContents* web_contents, | 270 if (weak_manager_) |
| 276 const std::string& platform) { | 271 weak_manager_->SendBannerAccepted(event_request_id_); |
| 277 web_contents->GetMainFrame()->Send( | |
| 278 new ChromeViewMsg_AppBannerAccepted( | |
| 279 web_contents->GetMainFrame()->GetRoutingID(), | |
| 280 event_request_id_, | |
| 281 platform)); | |
| 282 } | 272 } |
| 283 | 273 |
| 284 infobars::InfoBarDelegate::InfoBarIdentifier | 274 infobars::InfoBarDelegate::InfoBarIdentifier |
| 285 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { | 275 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { |
| 286 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; | 276 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; |
| 287 } | 277 } |
| 288 | 278 |
| 289 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { | 279 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { |
| 290 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); | 280 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); |
| 291 } | 281 } |
| 292 | 282 |
| 293 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { | 283 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { |
| 294 has_user_interaction_ = true; | 284 has_user_interaction_ = true; |
| 295 | 285 |
| 296 content::WebContents* web_contents = | 286 content::WebContents* web_contents = |
| 297 InfoBarService::WebContentsFromInfoBar(infobar()); | 287 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 298 | 288 |
| 299 web_contents->GetMainFrame()->Send( | 289 if (weak_manager_) |
| 300 new ChromeViewMsg_AppBannerDismissed( | 290 weak_manager_->SendBannerDismissed(event_request_id_); |
| 301 web_contents->GetMainFrame()->GetRoutingID(), | |
| 302 event_request_id_)); | |
| 303 | 291 |
| 304 if (native_app_data_.is_null()) { | 292 if (native_app_data_.is_null()) { |
| 305 if (is_webapk_) | 293 if (is_webapk_) |
| 306 TrackWebApkInstallationDismissEvents(install_state_); | 294 TrackWebApkInstallationDismissEvents(install_state_); |
| 307 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); | 295 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); |
| 308 AppBannerSettingsHelper::RecordBannerDismissEvent( | 296 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 309 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 297 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 310 } else { | 298 } else { |
| 311 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); | 299 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); |
| 312 AppBannerSettingsHelper::RecordBannerDismissEvent( | 300 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 bool was_opened = | 342 bool was_opened = |
| 355 Java_AppBannerInfoBarDelegateAndroid_installOrOpenNativeApp( | 343 Java_AppBannerInfoBarDelegateAndroid_installOrOpenNativeApp( |
| 356 env, java_delegate_, tab->GetJavaObject(), | 344 env, java_delegate_, tab->GetJavaObject(), |
| 357 native_app_data_, jreferrer); | 345 native_app_data_, jreferrer); |
| 358 | 346 |
| 359 if (was_opened) | 347 if (was_opened) |
| 360 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); | 348 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); |
| 361 else | 349 else |
| 362 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); | 350 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); |
| 363 | 351 |
| 364 SendBannerAccepted(web_contents, "play"); | 352 SendBannerAccepted(); |
| 365 return was_opened; | 353 return was_opened; |
| 366 } | 354 } |
| 367 | 355 |
| 368 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( | 356 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( |
| 369 content::WebContents* web_contents) { | 357 content::WebContents* web_contents) { |
| 370 if (IsInfoEmpty(shortcut_info_)) | 358 if (IsInfoEmpty(shortcut_info_)) |
| 371 return true; | 359 return true; |
| 372 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 360 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 373 | 361 |
| 374 AppBannerSettingsHelper::RecordBannerInstallEvent( | 362 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 375 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 363 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 376 | 364 |
| 377 if (weak_manager_) { | 365 if (weak_manager_) { |
| 378 const std::string& uid = base::GenerateGUID(); | 366 const std::string& uid = base::GenerateGUID(); |
| 379 ShortcutHelper::AddToLauncherWithSkBitmap( | 367 ShortcutHelper::AddToLauncherWithSkBitmap( |
| 380 web_contents->GetBrowserContext(), *shortcut_info_, uid, | 368 web_contents->GetBrowserContext(), *shortcut_info_, uid, |
| 381 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid)); | 369 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid)); |
| 382 } | 370 } |
| 383 | 371 |
| 384 SendBannerAccepted(web_contents, "web"); | 372 SendBannerAccepted(); |
| 385 return true; | 373 return true; |
| 386 } | 374 } |
| 387 | 375 |
| 388 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( | 376 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( |
| 389 bool success, | 377 bool success, |
| 390 const std::string& webapk_package_name) { | 378 const std::string& webapk_package_name) { |
| 391 JNIEnv* env = base::android::AttachCurrentThread(); | 379 JNIEnv* env = base::android::AttachCurrentThread(); |
| 392 if (!success) { | 380 if (!success) { |
| 393 DVLOG(1) << "The WebAPK installation failed."; | 381 DVLOG(1) << "The WebAPK installation failed."; |
| 394 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); | 382 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 DCHECK(tab); | 425 DCHECK(tab); |
| 438 | 426 |
| 439 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( | 427 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( |
| 440 env, java_delegate_, tab->GetJavaObject(), native_app_data_); | 428 env, java_delegate_, tab->GetJavaObject(), native_app_data_); |
| 441 | 429 |
| 442 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 430 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 443 return true; | 431 return true; |
| 444 } | 432 } |
| 445 | 433 |
| 446 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 434 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 447 return RegisterNativesImpl(env); | 435 return RegisterNativesImpl(env); |
| 448 } | 436 } |
| 449 | 437 |
| 450 } // namespace banners | 438 } // namespace banners |
| OLD | NEW |