| 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/webapps/add_to_homescreen_manager.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_manager.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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 void AddToHomescreenManager::Start(content::WebContents* web_contents) { | 90 void AddToHomescreenManager::Start(content::WebContents* web_contents) { |
| 91 bool check_webapk_compatible = false; | 91 bool check_webapk_compatible = false; |
| 92 if (ChromeWebApkHost::CanInstallWebApk() && | 92 if (ChromeWebApkHost::CanInstallWebApk() && |
| 93 InstallableManager::IsContentSecure(web_contents)) { | 93 InstallableManager::IsContentSecure(web_contents)) { |
| 94 check_webapk_compatible = true; | 94 check_webapk_compatible = true; |
| 95 } else { | 95 } else { |
| 96 ShowDialog(); | 96 ShowDialog(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 data_fetcher_ = new AddToHomescreenDataFetcher( | 99 data_fetcher_ = base::MakeUnique<AddToHomescreenDataFetcher>( |
| 100 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), | 100 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), |
| 101 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), | 101 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), |
| 102 ShortcutHelper::GetIdealSplashImageSizeInPx(), | 102 ShortcutHelper::GetIdealSplashImageSizeInPx(), |
| 103 ShortcutHelper::GetMinimumSplashImageSizeInPx(), | 103 ShortcutHelper::GetMinimumSplashImageSizeInPx(), |
| 104 ShortcutHelper::GetIdealBadgeIconSizeInPx(), kDataTimeoutInMilliseconds, | 104 ShortcutHelper::GetIdealBadgeIconSizeInPx(), kDataTimeoutInMilliseconds, |
| 105 check_webapk_compatible, this); | 105 check_webapk_compatible, this); |
| 106 } | 106 } |
| 107 | 107 |
| 108 AddToHomescreenManager::~AddToHomescreenManager() { | 108 AddToHomescreenManager::~AddToHomescreenManager() {} |
| 109 if (data_fetcher_) { | |
| 110 data_fetcher_->set_weak_observer(nullptr); | |
| 111 data_fetcher_ = nullptr; | |
| 112 } | |
| 113 } | |
| 114 | 109 |
| 115 void AddToHomescreenManager::ShowDialog() { | 110 void AddToHomescreenManager::ShowDialog() { |
| 116 JNIEnv* env = base::android::AttachCurrentThread(); | 111 JNIEnv* env = base::android::AttachCurrentThread(); |
| 117 Java_AddToHomescreenManager_showDialog(env, java_ref_); | 112 Java_AddToHomescreenManager_showDialog(env, java_ref_); |
| 118 } | 113 } |
| 119 | 114 |
| 120 void AddToHomescreenManager::RecordAddToHomescreen() { | 115 void AddToHomescreenManager::RecordAddToHomescreen() { |
| 121 // Record that the shortcut has been added, so no banners will be shown | 116 // Record that the shortcut has been added, so no banners will be shown |
| 122 // for this app. | 117 // for this app. |
| 123 content::WebContents* web_contents = data_fetcher_->web_contents(); | 118 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 const SkBitmap& badge_icon) { | 176 const SkBitmap& badge_icon) { |
| 182 content::WebContents* web_contents = data_fetcher_->web_contents(); | 177 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| 183 banners::AppBannerManagerAndroid* app_banner_manager = | 178 banners::AppBannerManagerAndroid* app_banner_manager = |
| 184 banners::AppBannerManagerAndroid::FromWebContents(web_contents); | 179 banners::AppBannerManagerAndroid::FromWebContents(web_contents); |
| 185 banners::AppBannerInfoBarDelegateAndroid::Create( | 180 banners::AppBannerInfoBarDelegateAndroid::Create( |
| 186 web_contents, app_banner_manager->GetWeakPtr(), | 181 web_contents, app_banner_manager->GetWeakPtr(), |
| 187 base::MakeUnique<ShortcutInfo>(info), primary_icon, badge_icon, | 182 base::MakeUnique<ShortcutInfo>(info), primary_icon, badge_icon, |
| 188 -1 /* event_request_id */, true /* is_webapk */, | 183 -1 /* event_request_id */, true /* is_webapk */, |
| 189 webapk::INSTALL_SOURCE_MENU); | 184 webapk::INSTALL_SOURCE_MENU); |
| 190 } | 185 } |
| 191 | |
| 192 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( | |
| 193 const SkBitmap& bitmap, | |
| 194 const GURL& url, | |
| 195 bool* is_generated) { | |
| 196 base::ThreadRestrictions::AssertIOAllowed(); | |
| 197 | |
| 198 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, | |
| 199 is_generated); | |
| 200 } | |
| OLD | NEW |