| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Open the WebAPK. | 184 // Open the WebAPK. |
| 185 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 185 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
| 186 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); | 186 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); |
| 187 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, | 187 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, |
| 188 java_webapk_package_name); | 188 java_webapk_package_name); |
| 189 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 189 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
| 190 SendBannerAccepted(web_contents, "web"); | 190 SendBannerAccepted(web_contents, "web"); |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Request install the WebAPK. | 194 // Check whether the WebAPK has been installed. |
| 195 install_state_ = INSTALLING; | 195 std::string installed_webapk_package_name = |
| 196 ShortcutHelper::QueryWebApkPackage(web_contents->GetLastCommittedURL()); |
| 197 if (installed_webapk_package_name.empty()) { |
| 198 // Request install the WebAPK. |
| 199 install_state_ = INSTALLING; |
| 200 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 201 webapk::TrackInstallSource(webapk_install_source_); |
| 202 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 203 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 204 |
| 205 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 206 env, java_delegate_, true); |
| 207 UpdateInstallState(env, nullptr); |
| 208 WebApkInstaller::FinishCallback callback = |
| 209 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
| 210 weak_ptr_factory_.GetWeakPtr()); |
| 211 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), |
| 212 *shortcut_info_, |
| 213 *icon_.get(), callback); |
| 214 SendBannerAccepted(web_contents, "web"); |
| 215 |
| 216 // Prevent the infobar from disappearing, because the infobar will show |
| 217 // "Adding" during the installation process. |
| 218 return false; |
| 219 } |
| 220 |
| 221 // Bypass the installation since WebAPK is already installed. |
| 196 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 222 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 197 webapk::TrackInstallSource(webapk_install_source_); | 223 OnWebApkInstallFinished(true, installed_webapk_package_name); |
| 198 AppBannerSettingsHelper::RecordBannerInstallEvent( | |
| 199 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | |
| 200 | |
| 201 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | |
| 202 env, java_delegate_, true); | |
| 203 UpdateInstallState(env, nullptr); | |
| 204 WebApkInstaller::FinishCallback callback = | |
| 205 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | |
| 206 weak_ptr_factory_.GetWeakPtr()); | |
| 207 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), | |
| 208 *shortcut_info_, | |
| 209 *icon_.get(), callback); | |
| 210 SendBannerAccepted(web_contents, "web"); | |
| 211 | |
| 212 // Prevent the infobar from disappearing, because the infobar will show | |
| 213 // "Adding" during the installation process. | |
| 214 return false; | 224 return false; |
| 215 } | 225 } |
| 216 | 226 |
| 217 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 227 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 218 base::WeakPtr<AppBannerManager> weak_manager, | 228 base::WeakPtr<AppBannerManager> weak_manager, |
| 219 const base::string16& app_title, | 229 const base::string16& app_title, |
| 220 std::unique_ptr<ShortcutInfo> shortcut_info, | 230 std::unique_ptr<ShortcutInfo> shortcut_info, |
| 221 std::unique_ptr<SkBitmap> icon, | 231 std::unique_ptr<SkBitmap> icon, |
| 222 int event_request_id, | 232 int event_request_id, |
| 223 bool is_webapk, | 233 bool is_webapk, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 441 |
| 432 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 442 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 433 return true; | 443 return true; |
| 434 } | 444 } |
| 435 | 445 |
| 436 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 446 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 437 return RegisterNativesImpl(env); | 447 return RegisterNativesImpl(env); |
| 438 } | 448 } |
| 439 | 449 |
| 440 } // namespace banners | 450 } // namespace banners |
| OLD | NEW |