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_manager_android.h" | 5 #include "chrome/browser/android/banners/app_banner_manager_android.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 using base::android::JavaParamRef; | 32 using base::android::JavaParamRef; |
| 33 using base::android::ScopedJavaLocalRef; | 33 using base::android::ScopedJavaLocalRef; |
| 34 | 34 |
| 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerAndroid); | 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerAndroid); |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 std::unique_ptr<ShortcutInfo> CreateShortcutInfo( | 39 std::unique_ptr<ShortcutInfo> CreateShortcutInfo( |
| 40 const GURL& manifest_url, | 40 const GURL& manifest_url, |
| 41 const content::Manifest& manifest, | 41 const content::Manifest& manifest, |
| 42 const GURL& icon_url) { | 42 const GURL& icon_url, |
| 43 const GURL& splash_image_url, | |
| 44 int ideal_splash_image_size_in_px, | |
| 45 int minimum_splash_image_size_in_px) { | |
| 43 auto shortcut_info = base::MakeUnique<ShortcutInfo>(GURL()); | 46 auto shortcut_info = base::MakeUnique<ShortcutInfo>(GURL()); |
| 44 if (!manifest.IsEmpty()) { | 47 if (!manifest.IsEmpty()) { |
| 45 shortcut_info->UpdateFromManifest(manifest); | 48 shortcut_info->UpdateFromManifest(manifest); |
| 46 shortcut_info->manifest_url = manifest_url; | 49 shortcut_info->manifest_url = manifest_url; |
| 47 shortcut_info->best_primary_icon_url = icon_url; | 50 shortcut_info->best_primary_icon_url = icon_url; |
| 48 shortcut_info->UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); | 51 shortcut_info->UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); |
| 49 } | 52 } |
| 53 shortcut_info->splash_image_url = splash_image_url; | |
| 54 shortcut_info->ideal_splash_image_size_in_px = ideal_splash_image_size_in_px; | |
| 55 shortcut_info->minimum_splash_image_size_in_px = | |
| 56 minimum_splash_image_size_in_px; | |
| 50 return shortcut_info; | 57 return shortcut_info; |
| 51 } | 58 } |
| 52 | 59 |
| 53 } // anonymous namespace | 60 } // anonymous namespace |
| 54 | 61 |
| 55 namespace banners { | 62 namespace banners { |
| 56 | 63 |
| 57 AppBannerManagerAndroid::AppBannerManagerAndroid( | 64 AppBannerManagerAndroid::AppBannerManagerAndroid( |
| 58 content::WebContents* web_contents) | 65 content::WebContents* web_contents) |
| 59 : AppBannerManager(web_contents) { | 66 : AppBannerManager(web_contents) { |
| 60 can_install_webapk_ = ChromeWebApkHost::CanInstallWebApk(); | 67 can_install_webapk_ = ChromeWebApkHost::CanInstallWebApk(); |
| 61 CreateJavaBannerManager(); | 68 CreateJavaBannerManager(); |
| 62 } | 69 } |
| 63 | 70 |
| 64 AppBannerManagerAndroid::~AppBannerManagerAndroid() { | 71 AppBannerManagerAndroid::~AppBannerManagerAndroid() { |
| 65 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
| 66 Java_AppBannerManager_destroy(env, java_banner_manager_); | 73 Java_AppBannerManager_destroy(env, java_banner_manager_); |
| 67 java_banner_manager_.Reset(); | 74 java_banner_manager_.Reset(); |
| 68 } | 75 } |
| 69 | 76 |
| 70 base::Closure AppBannerManagerAndroid::FetchWebappSplashScreenImageCallback( | |
| 71 const std::string& webapp_id) { | |
| 72 content::WebContents* contents = web_contents(); | |
| 73 DCHECK(contents); | |
| 74 | |
| 75 int ideal_splash_image_size_in_px = | |
| 76 ShortcutHelper::GetIdealSplashImageSizeInPx(); | |
| 77 int minimum_splash_image_size_in_px = | |
| 78 ShortcutHelper::GetMinimumSplashImageSizeInPx(); | |
| 79 GURL image_url = ManifestIconSelector::FindBestMatchingIcon( | |
| 80 manifest_.icons, ideal_splash_image_size_in_px, | |
| 81 minimum_splash_image_size_in_px, | |
| 82 content::Manifest::Icon::IconPurpose::ANY); | |
| 83 | |
| 84 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, contents, | |
| 85 image_url, ideal_splash_image_size_in_px, | |
| 86 minimum_splash_image_size_in_px, webapp_id); | |
| 87 } | |
| 88 | |
| 89 const base::android::ScopedJavaGlobalRef<jobject>& | 77 const base::android::ScopedJavaGlobalRef<jobject>& |
| 90 AppBannerManagerAndroid::GetJavaBannerManager() const { | 78 AppBannerManagerAndroid::GetJavaBannerManager() const { |
| 91 return java_banner_manager_; | 79 return java_banner_manager_; |
| 92 } | 80 } |
| 93 | 81 |
| 94 bool AppBannerManagerAndroid::IsActiveForTesting( | 82 bool AppBannerManagerAndroid::IsActiveForTesting( |
| 95 JNIEnv* env, | 83 JNIEnv* env, |
| 96 const JavaParamRef<jobject>& obj) { | 84 const JavaParamRef<jobject>& obj) { |
| 97 return is_active(); | 85 return is_active(); |
| 98 } | 86 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 AppBannerManager::ResetCurrentPageData(); | 219 AppBannerManager::ResetCurrentPageData(); |
| 232 native_app_data_.Reset(); | 220 native_app_data_.Reset(); |
| 233 native_app_package_ = ""; | 221 native_app_package_ = ""; |
| 234 } | 222 } |
| 235 | 223 |
| 236 void AppBannerManagerAndroid::ShowBanner() { | 224 void AppBannerManagerAndroid::ShowBanner() { |
| 237 content::WebContents* contents = web_contents(); | 225 content::WebContents* contents = web_contents(); |
| 238 DCHECK(contents); | 226 DCHECK(contents); |
| 239 | 227 |
| 240 if (native_app_data_.is_null()) { | 228 if (native_app_data_.is_null()) { |
| 229 int ideal_splash_image_size_in_px = | |
| 230 ShortcutHelper::GetIdealSplashImageSizeInPx(); | |
| 231 int minimum_splash_image_size_in_px = | |
| 232 ShortcutHelper::GetMinimumSplashImageSizeInPx(); | |
|
dominickn
2017/03/01 02:29:39
Can you move all of this into CreateShortcutInfo?
| |
| 233 GURL splash_image_url = ManifestIconSelector::FindBestMatchingIcon( | |
| 234 manifest_.icons, ideal_splash_image_size_in_px, | |
| 235 minimum_splash_image_size_in_px, | |
| 236 content::Manifest::Icon::IconPurpose::ANY); | |
| 237 | |
| 241 // TODO(zpeng): Add badge to WebAPK installation flow. | 238 // TODO(zpeng): Add badge to WebAPK installation flow. |
| 239 std::unique_ptr<ShortcutInfo> shortcut_info = CreateShortcutInfo( | |
| 240 manifest_url_, manifest_, primary_icon_url_, splash_image_url, | |
| 241 ideal_splash_image_size_in_px, minimum_splash_image_size_in_px); | |
| 242 | |
| 242 if (AppBannerInfoBarDelegateAndroid::Create( | 243 if (AppBannerInfoBarDelegateAndroid::Create( |
| 243 contents, GetWeakPtr(), app_title_, | 244 contents, GetWeakPtr(), app_title_, std::move(shortcut_info), |
| 244 CreateShortcutInfo(manifest_url_, manifest_, primary_icon_url_), | |
| 245 std::move(primary_icon_), event_request_id(), | 245 std::move(primary_icon_), event_request_id(), |
| 246 webapk::INSTALL_SOURCE_BANNER)) { | 246 webapk::INSTALL_SOURCE_BANNER)) { |
| 247 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 247 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 248 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 248 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 249 ReportStatus(contents, SHOWING_WEB_APP_BANNER); | 249 ReportStatus(contents, SHOWING_WEB_APP_BANNER); |
| 250 } else { | 250 } else { |
| 251 ReportStatus(contents, FAILED_TO_CREATE_BANNER); | 251 ReportStatus(contents, FAILED_TO_CREATE_BANNER); |
| 252 } | 252 } |
| 253 } else { | 253 } else { |
| 254 if (AppBannerInfoBarDelegateAndroid::Create( | 254 if (AppBannerInfoBarDelegateAndroid::Create( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 } | 365 } |
| 366 | 366 |
| 367 // static | 367 // static |
| 368 void SetTotalEngagementToTrigger(JNIEnv* env, | 368 void SetTotalEngagementToTrigger(JNIEnv* env, |
| 369 const JavaParamRef<jclass>& clazz, | 369 const JavaParamRef<jclass>& clazz, |
| 370 jdouble engagement) { | 370 jdouble engagement) { |
| 371 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); | 371 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); |
| 372 } | 372 } |
| 373 | 373 |
| 374 } // namespace banners | 374 } // namespace banners |
| OLD | NEW |