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/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } // anonymous namespace | 44 } // anonymous namespace |
45 | 45 |
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> primary_icon, |
| 55 std::unique_ptr<SkBitmap> badge_icon, |
55 int event_request_id, | 56 int event_request_id, |
56 webapk::InstallSource webapk_install_source) { | 57 webapk::InstallSource webapk_install_source) { |
57 bool is_webapk = ChromeWebApkHost::CanInstallWebApk(); | 58 bool is_webapk = ChromeWebApkHost::CanInstallWebApk(); |
58 const GURL url = shortcut_info->url; | 59 const GURL url = shortcut_info->url; |
59 auto infobar_delegate = | 60 auto infobar_delegate = |
60 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( | 61 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( |
61 weak_manager, app_title, std::move(shortcut_info), std::move(icon), | 62 weak_manager, app_title, std::move(shortcut_info), |
62 event_request_id, is_webapk, webapk_install_source)); | 63 std::move(primary_icon), std::move(badge_icon), event_request_id, |
| 64 is_webapk, webapk_install_source)); |
63 auto* raw_delegate = infobar_delegate.get(); | 65 auto* raw_delegate = infobar_delegate.get(); |
64 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( | 66 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( |
65 std::move(infobar_delegate), url, is_webapk); | 67 std::move(infobar_delegate), url, is_webapk); |
66 if (!InfoBarService::FromWebContents(web_contents) | 68 if (!InfoBarService::FromWebContents(web_contents) |
67 ->AddInfoBar(std::move(infobar))) | 69 ->AddInfoBar(std::move(infobar))) |
68 return false; | 70 return false; |
69 | 71 |
70 if (is_webapk) { | 72 if (is_webapk) { |
71 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { | 73 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { |
72 webapk::TrackInstallInfoBarShown( | 74 webapk::TrackInstallInfoBarShown( |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( | 203 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( |
202 env, java_delegate_, java_webapk_package_name); | 204 env, java_delegate_, java_webapk_package_name); |
203 UpdateInstallState(env, nullptr); | 205 UpdateInstallState(env, nullptr); |
204 install_state_ = INSTALLED; | 206 install_state_ = INSTALLED; |
205 } | 207 } |
206 | 208 |
207 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 209 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
208 base::WeakPtr<AppBannerManager> weak_manager, | 210 base::WeakPtr<AppBannerManager> weak_manager, |
209 const base::string16& app_title, | 211 const base::string16& app_title, |
210 std::unique_ptr<ShortcutInfo> shortcut_info, | 212 std::unique_ptr<ShortcutInfo> shortcut_info, |
211 std::unique_ptr<SkBitmap> icon, | 213 std::unique_ptr<SkBitmap> primary_icon, |
| 214 std::unique_ptr<SkBitmap> badge_icon, |
212 int event_request_id, | 215 int event_request_id, |
213 bool is_webapk, | 216 bool is_webapk, |
214 webapk::InstallSource webapk_install_source) | 217 webapk::InstallSource webapk_install_source) |
215 : weak_manager_(weak_manager), | 218 : weak_manager_(weak_manager), |
216 app_title_(app_title), | 219 app_title_(app_title), |
217 shortcut_info_(std::move(shortcut_info)), | 220 shortcut_info_(std::move(shortcut_info)), |
218 icon_(std::move(icon)), | 221 primary_icon_(std::move(primary_icon)), |
| 222 badge_icon_(std::move(badge_icon)), |
219 event_request_id_(event_request_id), | 223 event_request_id_(event_request_id), |
220 has_user_interaction_(false), | 224 has_user_interaction_(false), |
221 is_webapk_(is_webapk), | 225 is_webapk_(is_webapk), |
222 install_state_(INSTALL_NOT_STARTED), | 226 install_state_(INSTALL_NOT_STARTED), |
223 webapk_install_source_(webapk_install_source), | 227 webapk_install_source_(webapk_install_source), |
224 weak_ptr_factory_(this) { | 228 weak_ptr_factory_(this) { |
225 DCHECK(!IsInfoEmpty(shortcut_info_)); | 229 DCHECK(!IsInfoEmpty(shortcut_info_)); |
226 CreateJavaDelegate(); | 230 CreateJavaDelegate(); |
227 } | 231 } |
228 | 232 |
229 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 233 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
230 const base::string16& app_title, | 234 const base::string16& app_title, |
231 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 235 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
232 std::unique_ptr<SkBitmap> icon, | 236 std::unique_ptr<SkBitmap> icon, |
233 const std::string& native_app_package, | 237 const std::string& native_app_package, |
234 const std::string& referrer, | 238 const std::string& referrer, |
235 int event_request_id) | 239 int event_request_id) |
236 : app_title_(app_title), | 240 : app_title_(app_title), |
237 native_app_data_(native_app_data), | 241 native_app_data_(native_app_data), |
238 icon_(std::move(icon)), | 242 primary_icon_(std::move(icon)), |
239 native_app_package_(native_app_package), | 243 native_app_package_(native_app_package), |
240 referrer_(referrer), | 244 referrer_(referrer), |
241 event_request_id_(event_request_id), | 245 event_request_id_(event_request_id), |
242 has_user_interaction_(false), | 246 has_user_interaction_(false), |
243 weak_ptr_factory_(this) { | 247 weak_ptr_factory_(this) { |
244 DCHECK(!native_app_data_.is_null()); | 248 DCHECK(!native_app_data_.is_null()); |
245 CreateJavaDelegate(); | 249 CreateJavaDelegate(); |
246 } | 250 } |
247 | 251 |
248 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { | 252 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { |
(...skipping 29 matching lines...) Expand all Loading... |
278 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( | 282 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( |
279 content::WebContents* web_contents) { | 283 content::WebContents* web_contents) { |
280 if (IsInfoEmpty(shortcut_info_)) | 284 if (IsInfoEmpty(shortcut_info_)) |
281 return true; | 285 return true; |
282 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 286 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
283 | 287 |
284 AppBannerSettingsHelper::RecordBannerInstallEvent( | 288 AppBannerSettingsHelper::RecordBannerInstallEvent( |
285 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 289 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
286 | 290 |
287 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, | 291 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, |
288 *icon_.get()); | 292 *primary_icon_.get()); |
289 | 293 |
290 SendBannerAccepted(); | 294 SendBannerAccepted(); |
291 return true; | 295 return true; |
292 } | 296 } |
293 | 297 |
294 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | 298 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
295 content::WebContents* web_contents) { | 299 content::WebContents* web_contents) { |
296 if (IsInfoEmpty(shortcut_info_)) | 300 if (IsInfoEmpty(shortcut_info_)) |
297 return true; | 301 return true; |
298 | 302 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 AppBannerManager::GetCurrentTime()); | 334 AppBannerManager::GetCurrentTime()); |
331 } | 335 } |
332 | 336 |
333 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 337 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
334 env, java_delegate_, true); | 338 env, java_delegate_, true); |
335 UpdateInstallState(env, nullptr); | 339 UpdateInstallState(env, nullptr); |
336 WebApkInstallService::FinishCallback callback = | 340 WebApkInstallService::FinishCallback callback = |
337 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 341 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
338 weak_ptr_factory_.GetWeakPtr()); | 342 weak_ptr_factory_.GetWeakPtr()); |
339 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents, *shortcut_info_, | 343 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents, *shortcut_info_, |
340 *icon_.get(), callback); | 344 *primary_icon_.get(), |
| 345 *badge_icon_.get(), callback); |
| 346 |
341 SendBannerAccepted(); | 347 SendBannerAccepted(); |
342 | 348 |
343 // Prevent the infobar from disappearing, because the infobar will show | 349 // Prevent the infobar from disappearing, because the infobar will show |
344 // "Adding" during the installation process. | 350 // "Adding" during the installation process. |
345 return false; | 351 return false; |
346 } | 352 } |
347 | 353 |
348 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { | 354 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { |
349 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; | 355 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; |
350 } | 356 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 return; | 388 return; |
383 | 389 |
384 // If the install didn't definitely fail, we don't add a shortcut. This could | 390 // If the install didn't definitely fail, we don't add a shortcut. This could |
385 // happen if Play was busy with another install and this one is still queued | 391 // happen if Play was busy with another install and this one is still queued |
386 // (and hence might succeed in the future). | 392 // (and hence might succeed in the future). |
387 if (result == WebApkInstallResult::FAILURE) { | 393 if (result == WebApkInstallResult::FAILURE) { |
388 content::WebContents* web_contents = | 394 content::WebContents* web_contents = |
389 InfoBarService::WebContentsFromInfoBar(infobar()); | 395 InfoBarService::WebContentsFromInfoBar(infobar()); |
390 // Add webapp shortcut to the homescreen. | 396 // Add webapp shortcut to the homescreen. |
391 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, | 397 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, |
392 *icon_.get()); | 398 *primary_icon_.get()); |
393 } | 399 } |
394 | 400 |
395 infobar()->RemoveSelf(); | 401 infobar()->RemoveSelf(); |
396 } | 402 } |
397 | 403 |
398 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( | 404 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( |
399 InstallState install_state) { | 405 InstallState install_state) { |
400 if (install_state == INSTALL_NOT_STARTED) { | 406 if (install_state == INSTALL_NOT_STARTED) { |
401 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); | 407 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); |
402 } else if (install_state == INSTALLING) { | 408 } else if (install_state == INSTALLING) { |
403 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); | 409 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); |
404 } else if (install_state == INSTALLED) { | 410 } else if (install_state == INSTALLED) { |
405 // If WebAPK is installed from this banner, TrackInstallEvent() is called in | 411 // If WebAPK is installed from this banner, TrackInstallEvent() is called in |
406 // OnWebApkInstallFinished(). | 412 // OnWebApkInstallFinished(). |
407 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); | 413 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); |
408 } | 414 } |
409 } | 415 } |
410 | 416 |
411 infobars::InfoBarDelegate::InfoBarIdentifier | 417 infobars::InfoBarDelegate::InfoBarIdentifier |
412 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { | 418 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { |
413 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; | 419 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; |
414 } | 420 } |
415 | 421 |
416 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { | 422 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { |
417 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); | 423 return gfx::Image::CreateFrom1xBitmap(*primary_icon_.get()); |
418 } | 424 } |
419 | 425 |
420 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { | 426 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { |
421 has_user_interaction_ = true; | 427 has_user_interaction_ = true; |
422 | 428 |
423 content::WebContents* web_contents = | 429 content::WebContents* web_contents = |
424 InfoBarService::WebContentsFromInfoBar(infobar()); | 430 InfoBarService::WebContentsFromInfoBar(infobar()); |
425 | 431 |
426 if (weak_manager_ && TriggeredFromBanner()) | 432 if (weak_manager_ && TriggeredFromBanner()) |
427 weak_manager_->SendBannerDismissed(event_request_id_); | 433 weak_manager_->SendBannerDismissed(event_request_id_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 474 |
469 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 475 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
470 return true; | 476 return true; |
471 } | 477 } |
472 | 478 |
473 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 479 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
474 return RegisterNativesImpl(env); | 480 return RegisterNativesImpl(env); |
475 } | 481 } |
476 | 482 |
477 } // namespace banners | 483 } // namespace banners |
OLD | NEW |