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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } // anonymous namespace | 45 } // anonymous namespace |
46 | 46 |
47 namespace banners { | 47 namespace banners { |
48 | 48 |
49 // static | 49 // static |
50 bool AppBannerInfoBarDelegateAndroid::Create( | 50 bool AppBannerInfoBarDelegateAndroid::Create( |
51 content::WebContents* web_contents, | 51 content::WebContents* web_contents, |
52 base::WeakPtr<AppBannerManager> weak_manager, | 52 base::WeakPtr<AppBannerManager> weak_manager, |
53 const base::string16& app_title, | 53 const base::string16& app_title, |
54 std::unique_ptr<ShortcutInfo> shortcut_info, | 54 std::unique_ptr<ShortcutInfo> shortcut_info, |
55 std::unique_ptr<SkBitmap> icon, | 55 std::unique_ptr<SkBitmap> primary_icon, |
| 56 std::unique_ptr<SkBitmap> badge_icon, |
56 int event_request_id, | 57 int event_request_id, |
57 webapk::InstallSource webapk_install_source) { | 58 webapk::InstallSource webapk_install_source) { |
58 bool is_webapk = ChromeWebApkHost::CanInstallWebApk(); | 59 bool is_webapk = ChromeWebApkHost::CanInstallWebApk(); |
59 std::string webapk_package_name = ""; | 60 std::string webapk_package_name = ""; |
60 const GURL& url = shortcut_info->url; | 61 const GURL& url = shortcut_info->url; |
61 if (is_webapk) | 62 if (is_webapk) |
62 webapk_package_name = ShortcutHelper::QueryWebApkPackage(url); | 63 webapk_package_name = ShortcutHelper::QueryWebApkPackage(url); |
63 bool is_webapk_already_installed = !webapk_package_name.empty(); | 64 bool is_webapk_already_installed = !webapk_package_name.empty(); |
64 auto infobar_delegate = | 65 auto infobar_delegate = |
65 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( | 66 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( |
66 weak_manager, app_title, std::move(shortcut_info), std::move(icon), | 67 weak_manager, app_title, std::move(shortcut_info), |
67 event_request_id, is_webapk, is_webapk_already_installed, | 68 std::move(primary_icon), std::move(badge_icon), event_request_id, |
68 webapk_install_source)); | 69 is_webapk, is_webapk_already_installed, webapk_install_source)); |
69 auto raw_delegate = infobar_delegate.get(); | 70 auto raw_delegate = infobar_delegate.get(); |
70 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( | 71 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( |
71 std::move(infobar_delegate), url, is_webapk); | 72 std::move(infobar_delegate), url, is_webapk); |
72 if (!InfoBarService::FromWebContents(web_contents) | 73 if (!InfoBarService::FromWebContents(web_contents) |
73 ->AddInfoBar(std::move(infobar))) | 74 ->AddInfoBar(std::move(infobar))) |
74 return false; | 75 return false; |
75 | 76 |
76 if (is_webapk) { | 77 if (is_webapk) { |
77 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { | 78 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { |
78 webapk::TrackInstallInfoBarShown( | 79 webapk::TrackInstallInfoBarShown( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( | 211 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( |
211 env, java_delegate_, java_webapk_package_name); | 212 env, java_delegate_, java_webapk_package_name); |
212 UpdateInstallState(env, nullptr); | 213 UpdateInstallState(env, nullptr); |
213 install_state_ = INSTALLED; | 214 install_state_ = INSTALLED; |
214 } | 215 } |
215 | 216 |
216 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 217 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
217 base::WeakPtr<AppBannerManager> weak_manager, | 218 base::WeakPtr<AppBannerManager> weak_manager, |
218 const base::string16& app_title, | 219 const base::string16& app_title, |
219 std::unique_ptr<ShortcutInfo> shortcut_info, | 220 std::unique_ptr<ShortcutInfo> shortcut_info, |
220 std::unique_ptr<SkBitmap> icon, | 221 std::unique_ptr<SkBitmap> primary_icon, |
| 222 std::unique_ptr<SkBitmap> badge_icon, |
221 int event_request_id, | 223 int event_request_id, |
222 bool is_webapk, | 224 bool is_webapk, |
223 bool is_webapk_already_installed, | 225 bool is_webapk_already_installed, |
224 webapk::InstallSource webapk_install_source) | 226 webapk::InstallSource webapk_install_source) |
225 : weak_manager_(weak_manager), | 227 : weak_manager_(weak_manager), |
226 app_title_(app_title), | 228 app_title_(app_title), |
227 shortcut_info_(std::move(shortcut_info)), | 229 shortcut_info_(std::move(shortcut_info)), |
228 icon_(std::move(icon)), | 230 primary_icon_(std::move(primary_icon)), |
| 231 badge_icon_(std::move(badge_icon)), |
229 event_request_id_(event_request_id), | 232 event_request_id_(event_request_id), |
230 has_user_interaction_(false), | 233 has_user_interaction_(false), |
231 is_webapk_(is_webapk), | 234 is_webapk_(is_webapk), |
232 is_webapk_already_installed_(is_webapk_already_installed), | 235 is_webapk_already_installed_(is_webapk_already_installed), |
233 install_state_(INSTALL_NOT_STARTED), | 236 install_state_(INSTALL_NOT_STARTED), |
234 webapk_install_source_(webapk_install_source), | 237 webapk_install_source_(webapk_install_source), |
235 weak_ptr_factory_(this) { | 238 weak_ptr_factory_(this) { |
236 DCHECK(!IsInfoEmpty(shortcut_info_)); | 239 DCHECK(!IsInfoEmpty(shortcut_info_)); |
237 CreateJavaDelegate(); | 240 CreateJavaDelegate(); |
238 } | 241 } |
239 | 242 |
240 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 243 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
241 const base::string16& app_title, | 244 const base::string16& app_title, |
242 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 245 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
243 std::unique_ptr<SkBitmap> icon, | 246 std::unique_ptr<SkBitmap> icon, |
244 const std::string& native_app_package, | 247 const std::string& native_app_package, |
245 const std::string& referrer, | 248 const std::string& referrer, |
246 int event_request_id) | 249 int event_request_id) |
247 : app_title_(app_title), | 250 : app_title_(app_title), |
248 native_app_data_(native_app_data), | 251 native_app_data_(native_app_data), |
249 icon_(std::move(icon)), | 252 primary_icon_(std::move(icon)), |
250 native_app_package_(native_app_package), | 253 native_app_package_(native_app_package), |
251 referrer_(referrer), | 254 referrer_(referrer), |
252 event_request_id_(event_request_id), | 255 event_request_id_(event_request_id), |
253 has_user_interaction_(false), | 256 has_user_interaction_(false), |
254 weak_ptr_factory_(this) { | 257 weak_ptr_factory_(this) { |
255 DCHECK(!native_app_data_.is_null()); | 258 DCHECK(!native_app_data_.is_null()); |
256 CreateJavaDelegate(); | 259 CreateJavaDelegate(); |
257 } | 260 } |
258 | 261 |
259 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { | 262 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 return true; | 295 return true; |
293 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 296 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
294 | 297 |
295 AppBannerSettingsHelper::RecordBannerInstallEvent( | 298 AppBannerSettingsHelper::RecordBannerInstallEvent( |
296 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 299 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
297 | 300 |
298 if (weak_manager_) { | 301 if (weak_manager_) { |
299 const std::string& uid = base::GenerateGUID(); | 302 const std::string& uid = base::GenerateGUID(); |
300 ShortcutHelper::AddToLauncherWithSkBitmap( | 303 ShortcutHelper::AddToLauncherWithSkBitmap( |
301 web_contents->GetBrowserContext(), *shortcut_info_, uid, | 304 web_contents->GetBrowserContext(), *shortcut_info_, uid, |
302 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid)); | 305 *primary_icon_.get(), |
| 306 weak_manager_->FetchWebappSplashScreenImageCallback(uid)); |
303 } | 307 } |
304 | 308 |
305 SendBannerAccepted(); | 309 SendBannerAccepted(); |
306 return true; | 310 return true; |
307 } | 311 } |
308 | 312 |
309 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | 313 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
310 content::WebContents* web_contents) { | 314 content::WebContents* web_contents) { |
311 if (IsInfoEmpty(shortcut_info_)) | 315 if (IsInfoEmpty(shortcut_info_)) |
312 return true; | 316 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 351 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
348 AppBannerManager::GetCurrentTime()); | 352 AppBannerManager::GetCurrentTime()); |
349 } | 353 } |
350 | 354 |
351 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 355 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
352 env, java_delegate_, true); | 356 env, java_delegate_, true); |
353 UpdateInstallState(env, nullptr); | 357 UpdateInstallState(env, nullptr); |
354 WebApkInstaller::FinishCallback callback = | 358 WebApkInstaller::FinishCallback callback = |
355 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 359 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
356 weak_ptr_factory_.GetWeakPtr()); | 360 weak_ptr_factory_.GetWeakPtr()); |
357 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), | 361 ShortcutHelper::InstallWebApkWithSkBitmap( |
358 *shortcut_info_, | 362 web_contents->GetBrowserContext(), *shortcut_info_, *primary_icon_.get(), |
359 *icon_.get(), callback); | 363 *badge_icon_.get(), callback); |
360 SendBannerAccepted(); | 364 SendBannerAccepted(); |
361 | 365 |
362 // Prevent the infobar from disappearing, because the infobar will show | 366 // Prevent the infobar from disappearing, because the infobar will show |
363 // "Adding" during the installation process. | 367 // "Adding" during the installation process. |
364 return false; | 368 return false; |
365 } | 369 } |
366 | 370 |
367 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { | 371 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { |
368 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; | 372 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; |
369 } | 373 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); | 416 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); |
413 } | 417 } |
414 } | 418 } |
415 | 419 |
416 infobars::InfoBarDelegate::InfoBarIdentifier | 420 infobars::InfoBarDelegate::InfoBarIdentifier |
417 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { | 421 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { |
418 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; | 422 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; |
419 } | 423 } |
420 | 424 |
421 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { | 425 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { |
422 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); | 426 return gfx::Image::CreateFrom1xBitmap(*primary_icon_.get()); |
423 } | 427 } |
424 | 428 |
425 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { | 429 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { |
426 has_user_interaction_ = true; | 430 has_user_interaction_ = true; |
427 | 431 |
428 content::WebContents* web_contents = | 432 content::WebContents* web_contents = |
429 InfoBarService::WebContentsFromInfoBar(infobar()); | 433 InfoBarService::WebContentsFromInfoBar(infobar()); |
430 | 434 |
431 if (weak_manager_ && TriggeredFromBanner()) | 435 if (weak_manager_ && TriggeredFromBanner()) |
432 weak_manager_->SendBannerDismissed(event_request_id_); | 436 weak_manager_->SendBannerDismissed(event_request_id_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 477 |
474 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 478 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
475 return true; | 479 return true; |
476 } | 480 } |
477 | 481 |
478 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 482 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
479 return RegisterNativesImpl(env); | 483 return RegisterNativesImpl(env); |
480 } | 484 } |
481 | 485 |
482 } // namespace banners | 486 } // namespace banners |
OLD | NEW |