| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "ui/gfx/android/java_bitmap.h" | 28 #include "ui/gfx/android/java_bitmap.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 | 30 |
| 31 using base::android::ConvertJavaStringToUTF8; | 31 using base::android::ConvertJavaStringToUTF8; |
| 32 using base::android::ConvertJavaStringToUTF16; | 32 using base::android::ConvertJavaStringToUTF16; |
| 33 using base::android::ConvertUTF8ToJavaString; | 33 using base::android::ConvertUTF8ToJavaString; |
| 34 using base::android::ConvertUTF16ToJavaString; | 34 using base::android::ConvertUTF16ToJavaString; |
| 35 using base::android::JavaParamRef; | 35 using base::android::JavaParamRef; |
| 36 using base::android::ScopedJavaLocalRef; | 36 using base::android::ScopedJavaLocalRef; |
| 37 | 37 |
| 38 namespace { | |
| 39 | |
| 40 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) { | |
| 41 return !info || info->url.is_empty(); | |
| 42 } | |
| 43 | |
| 44 } // anonymous namespace | |
| 45 | |
| 46 namespace banners { | 38 namespace banners { |
| 47 | 39 |
| 48 // static | 40 // static |
| 49 bool AppBannerInfoBarDelegateAndroid::Create( | 41 bool AppBannerInfoBarDelegateAndroid::Create( |
| 50 content::WebContents* web_contents, | 42 content::WebContents* web_contents, |
| 51 base::WeakPtr<AppBannerManager> weak_manager, | 43 base::WeakPtr<AppBannerManager> weak_manager, |
| 52 const base::string16& app_title, | 44 const base::string16& app_title, |
| 53 std::unique_ptr<ShortcutInfo> shortcut_info, | 45 std::unique_ptr<ShortcutInfo> shortcut_info, |
| 54 const SkBitmap& primary_icon, | 46 const SkBitmap& primary_icon, |
| 55 const SkBitmap& badge_icon, | 47 const SkBitmap& badge_icon, |
| 56 int event_request_id, | 48 int event_request_id, |
| 57 bool is_webapk, | 49 bool is_webapk, |
| 58 webapk::InstallSource webapk_install_source) { | 50 webapk::InstallSource webapk_install_source) { |
| 51 DCHECK(shortcut_info); |
| 59 const GURL url = shortcut_info->url; | 52 const GURL url = shortcut_info->url; |
| 53 if (url.is_empty()) |
| 54 return false; |
| 55 |
| 60 auto infobar_delegate = | 56 auto infobar_delegate = |
| 61 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( | 57 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( |
| 62 weak_manager, app_title, std::move(shortcut_info), primary_icon, | 58 weak_manager, app_title, std::move(shortcut_info), primary_icon, |
| 63 badge_icon, event_request_id, is_webapk, webapk_install_source)); | 59 badge_icon, event_request_id, is_webapk, webapk_install_source)); |
| 64 auto* raw_delegate = infobar_delegate.get(); | 60 auto* raw_delegate = infobar_delegate.get(); |
| 65 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( | 61 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( |
| 66 std::move(infobar_delegate), url, is_webapk); | 62 std::move(infobar_delegate), url, is_webapk); |
| 67 if (!InfoBarService::FromWebContents(web_contents) | 63 if (!InfoBarService::FromWebContents(web_contents) |
| 68 ->AddInfoBar(std::move(infobar))) | 64 ->AddInfoBar(std::move(infobar))) |
| 69 return false; | 65 return false; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 app_title_(app_title), | 214 app_title_(app_title), |
| 219 shortcut_info_(std::move(shortcut_info)), | 215 shortcut_info_(std::move(shortcut_info)), |
| 220 primary_icon_(primary_icon), | 216 primary_icon_(primary_icon), |
| 221 badge_icon_(badge_icon), | 217 badge_icon_(badge_icon), |
| 222 event_request_id_(event_request_id), | 218 event_request_id_(event_request_id), |
| 223 has_user_interaction_(false), | 219 has_user_interaction_(false), |
| 224 is_webapk_(is_webapk), | 220 is_webapk_(is_webapk), |
| 225 install_state_(INSTALL_NOT_STARTED), | 221 install_state_(INSTALL_NOT_STARTED), |
| 226 webapk_install_source_(webapk_install_source), | 222 webapk_install_source_(webapk_install_source), |
| 227 weak_ptr_factory_(this) { | 223 weak_ptr_factory_(this) { |
| 228 DCHECK(!IsInfoEmpty(shortcut_info_)); | |
| 229 CreateJavaDelegate(); | 224 CreateJavaDelegate(); |
| 230 } | 225 } |
| 231 | 226 |
| 232 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 227 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 233 const base::string16& app_title, | 228 const base::string16& app_title, |
| 234 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 229 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 235 const SkBitmap& icon, | 230 const SkBitmap& icon, |
| 236 const std::string& native_app_package, | 231 const std::string& native_app_package, |
| 237 const std::string& referrer, | 232 const std::string& referrer, |
| 238 int event_request_id) | 233 int event_request_id) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); | 268 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); |
| 274 else | 269 else |
| 275 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); | 270 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); |
| 276 | 271 |
| 277 SendBannerAccepted(); | 272 SendBannerAccepted(); |
| 278 return was_opened; | 273 return was_opened; |
| 279 } | 274 } |
| 280 | 275 |
| 281 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( | 276 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( |
| 282 content::WebContents* web_contents) { | 277 content::WebContents* web_contents) { |
| 283 if (IsInfoEmpty(shortcut_info_)) | |
| 284 return true; | |
| 285 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 278 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 286 | 279 |
| 287 AppBannerSettingsHelper::RecordBannerInstallEvent( | 280 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 288 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 281 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
| 289 | 282 |
| 290 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, | 283 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, |
| 291 primary_icon_); | 284 primary_icon_); |
| 292 | 285 |
| 293 SendBannerAccepted(); | 286 SendBannerAccepted(); |
| 294 return true; | 287 return true; |
| 295 } | 288 } |
| 296 | 289 |
| 297 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | 290 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
| 298 content::WebContents* web_contents) { | 291 content::WebContents* web_contents) { |
| 299 if (IsInfoEmpty(shortcut_info_)) | |
| 300 return true; | |
| 301 | |
| 302 JNIEnv* env = base::android::AttachCurrentThread(); | 292 JNIEnv* env = base::android::AttachCurrentThread(); |
| 303 | 293 |
| 304 // If the WebAPK is installed and the "Open" button is clicked, open the | 294 // If the WebAPK is installed and the "Open" button is clicked, open the |
| 305 // WebAPK. Do not send a BannerAccepted message. | 295 // WebAPK. Do not send a BannerAccepted message. |
| 306 if (install_state_ == INSTALLED) { | 296 if (install_state_ == INSTALLED) { |
| 307 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); | 297 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); |
| 308 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 298 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
| 309 return true; | 299 return true; |
| 310 } | 300 } |
| 311 | 301 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 456 |
| 467 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 457 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 468 return true; | 458 return true; |
| 469 } | 459 } |
| 470 | 460 |
| 471 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 461 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 472 return RegisterNativesImpl(env); | 462 return RegisterNativesImpl(env); |
| 473 } | 463 } |
| 474 | 464 |
| 475 } // namespace banners | 465 } // namespace banners |
| OLD | NEW |