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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 namespace banners { | 46 namespace banners { |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 bool AppBannerInfoBarDelegateAndroid::Create( | 49 bool AppBannerInfoBarDelegateAndroid::Create( |
| 50 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 51 base::WeakPtr<AppBannerManager> weak_manager, | 51 base::WeakPtr<AppBannerManager> weak_manager, |
| 52 const base::string16& app_title, | 52 const base::string16& app_title, |
| 53 std::unique_ptr<ShortcutInfo> shortcut_info, | 53 std::unique_ptr<ShortcutInfo> shortcut_info, |
| 54 std::unique_ptr<SkBitmap> icon, | 54 std::unique_ptr<SkBitmap> icon, |
| 55 int event_request_id, | 55 int event_request_id, |
| 56 bool can_use_webapk_install_flow, | |
| 56 webapk::InstallSource webapk_install_source) { | 57 webapk::InstallSource webapk_install_source) { |
| 57 bool is_webapk = ChromeWebApkHost::AreWebApkEnabled(); | 58 bool is_webapk_enabled = ChromeWebApkHost::AreWebApkEnabled(); |
| 58 std::string webapk_package_name = ""; | 59 std::string webapk_package_name = ""; |
| 59 const GURL& url = shortcut_info->url; | 60 const GURL& url = shortcut_info->url; |
| 60 if (is_webapk) | 61 if (is_webapk_enabled) |
|
pkotwicz
2017/02/03 18:56:32
For the sake of simplicity, I am ok with creating
Xi Han
2017/02/03 22:16:20
Yes it is complex, but I try to make it less diffi
pkotwicz
2017/02/03 23:05:05
Can we instead have the simpler behavior:
"Only ch
| |
| 61 webapk_package_name = ShortcutHelper::QueryWebApkPackage(url); | 62 webapk_package_name = ShortcutHelper::QueryWebApkPackage(url); |
| 62 bool is_webapk_already_installed = !webapk_package_name.empty(); | 63 bool is_webapk_already_installed = !webapk_package_name.empty(); |
| 64 // We continue the WebAPK flow if there is an associated WebAPK has been | |
| 65 // installed or WebAPKs are enabled and the install flow is available. | |
| 66 bool is_webapk = is_webapk_already_installed ? true | |
| 67 : is_webapk_enabled & can_use_webapk_install_flow; | |
| 63 auto infobar_delegate = | 68 auto infobar_delegate = |
| 64 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( | 69 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( |
| 65 weak_manager, app_title, std::move(shortcut_info), std::move(icon), | 70 weak_manager, app_title, std::move(shortcut_info), std::move(icon), |
| 66 event_request_id, is_webapk, is_webapk_already_installed, | 71 event_request_id, is_webapk, is_webapk_already_installed, |
| 67 webapk_install_source)); | 72 webapk_package_name, webapk_install_source)); |
| 68 auto raw_delegate = infobar_delegate.get(); | 73 auto raw_delegate = infobar_delegate.get(); |
| 69 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( | 74 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( |
| 70 std::move(infobar_delegate), url, is_webapk); | 75 std::move(infobar_delegate), url, is_webapk); |
| 71 if (!InfoBarService::FromWebContents(web_contents) | 76 if (!InfoBarService::FromWebContents(web_contents) |
| 72 ->AddInfoBar(std::move(infobar))) | 77 ->AddInfoBar(std::move(infobar))) |
| 73 return false; | 78 return false; |
| 74 | 79 |
| 75 if (is_webapk) { | 80 if (is_webapk) { |
| 76 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { | 81 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { |
| 77 webapk::TrackInstallInfoBarShown( | 82 webapk::TrackInstallInfoBarShown( |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 } | 218 } |
| 214 | 219 |
| 215 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 220 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 216 base::WeakPtr<AppBannerManager> weak_manager, | 221 base::WeakPtr<AppBannerManager> weak_manager, |
| 217 const base::string16& app_title, | 222 const base::string16& app_title, |
| 218 std::unique_ptr<ShortcutInfo> shortcut_info, | 223 std::unique_ptr<ShortcutInfo> shortcut_info, |
| 219 std::unique_ptr<SkBitmap> icon, | 224 std::unique_ptr<SkBitmap> icon, |
| 220 int event_request_id, | 225 int event_request_id, |
| 221 bool is_webapk, | 226 bool is_webapk, |
| 222 bool is_webapk_already_installed, | 227 bool is_webapk_already_installed, |
| 228 const std::string& webapk_package_name, | |
| 223 webapk::InstallSource webapk_install_source) | 229 webapk::InstallSource webapk_install_source) |
| 224 : weak_manager_(weak_manager), | 230 : weak_manager_(weak_manager), |
| 225 app_title_(app_title), | 231 app_title_(app_title), |
| 226 shortcut_info_(std::move(shortcut_info)), | 232 shortcut_info_(std::move(shortcut_info)), |
| 227 icon_(std::move(icon)), | 233 icon_(std::move(icon)), |
| 228 event_request_id_(event_request_id), | 234 event_request_id_(event_request_id), |
| 229 has_user_interaction_(false), | 235 has_user_interaction_(false), |
| 230 is_webapk_(is_webapk), | 236 is_webapk_(is_webapk), |
| 231 is_webapk_already_installed_(is_webapk_already_installed), | 237 is_webapk_already_installed_(is_webapk_already_installed), |
| 238 webapk_package_name_(webapk_package_name), | |
| 232 install_state_(INSTALL_NOT_STARTED), | 239 install_state_(INSTALL_NOT_STARTED), |
| 233 webapk_install_source_(webapk_install_source), | 240 webapk_install_source_(webapk_install_source), |
| 234 weak_ptr_factory_(this) { | 241 weak_ptr_factory_(this) { |
| 235 DCHECK(!IsInfoEmpty(shortcut_info_)); | 242 DCHECK(!IsInfoEmpty(shortcut_info_)); |
| 236 CreateJavaDelegate(); | 243 CreateJavaDelegate(); |
| 237 } | 244 } |
| 238 | 245 |
| 239 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 246 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 240 const base::string16& app_title, | 247 const base::string16& app_title, |
| 241 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 248 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // If the WebAPK is installed and the "Open" button is clicked, open the | 322 // If the WebAPK is installed and the "Open" button is clicked, open the |
| 316 // WebAPK. | 323 // WebAPK. |
| 317 if (install_state_ == INSTALLED) { | 324 if (install_state_ == INSTALLED) { |
| 318 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); | 325 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); |
| 319 if (is_webapk_already_installed_) | 326 if (is_webapk_already_installed_) |
| 320 webapk::TrackUserAction(webapk::USER_ACTION_OPEN); | 327 webapk::TrackUserAction(webapk::USER_ACTION_OPEN); |
| 321 else | 328 else |
| 322 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 329 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
| 323 SendBannerAccepted(); | 330 SendBannerAccepted(); |
| 324 return true; | 331 return true; |
| 332 } else if (is_webapk_already_installed_) { | |
| 333 // If a WebAPK has installed, but the |install_state_| hasn't changed | |
| 334 // yet, we updates the text of button on the banner, and return false to | |
| 335 // prevent the banner from disappear. | |
| 336 UpdateStateForInstalledWebAPK(webapk_package_name_); | |
| 337 return false; | |
| 325 } | 338 } |
| 326 | 339 |
| 327 // If the WebAPK is not installed and the "Add to Home Screen" button is | 340 // If the WebAPK is not installed and the "Add to Home Screen" button is |
| 328 // clicked, install the WebAPK. | 341 // clicked, install the WebAPK. |
| 329 install_state_ = INSTALLING; | 342 install_state_ = INSTALLING; |
| 330 webapk::TrackInstallSource(webapk_install_source_); | 343 webapk::TrackInstallSource(webapk_install_source_); |
| 331 | 344 |
| 332 if (TriggeredFromBanner()) { | 345 if (TriggeredFromBanner()) { |
| 333 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 346 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 334 AppBannerSettingsHelper::RecordBannerInstallEvent( | 347 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 | 482 |
| 470 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 483 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 471 return true; | 484 return true; |
| 472 } | 485 } |
| 473 | 486 |
| 474 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 487 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 475 return RegisterNativesImpl(env); | 488 return RegisterNativesImpl(env); |
| 476 } | 489 } |
| 477 | 490 |
| 478 } // namespace banners | 491 } // namespace banners |
| OLD | NEW |