| 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/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // via OnDataAvailable(); | 72 // via OnDataAvailable(); |
| 73 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->primary_icon()); | 73 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->primary_icon()); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void AddToHomescreenManager::Start(content::WebContents* web_contents) { | 77 void AddToHomescreenManager::Start(content::WebContents* web_contents) { |
| 78 bool check_webapk_compatible = false; | 78 bool check_webapk_compatible = false; |
| 79 if (ChromeWebApkHost::AreWebApkEnabled() && | 79 if (ChromeWebApkHost::AreWebApkEnabled() && |
| 80 InstallableManager::IsContentSecure(web_contents)) { | 80 InstallableManager::IsContentSecure(web_contents)) { |
| 81 check_webapk_compatible = true; | 81 check_webapk_compatible = true; |
| 82 } else { | 82 if (ChromeWebApkHost::CanUseGooglePlayToInstallWebApk()) { |
| 83 // It is possible that the Google Play Install API isn't available when |
| 84 // Google Play install is enabled. In that case, we fallback to classic |
| 85 // add-to-homescreen shortcut flow. |
| 86 ChromeWebApkHost::CanUseGooglePlayInstallApiCallback callback |
| 87 = base::Bind(&AddToHomescreenManager::OnCanUseGooglePlayInstallApi, |
| 88 base::Unretained(this), |
| 89 web_contents, check_webapk_compatible); |
| 90 ChromeWebApkHost::CanUseGooglePlayInstallApi(callback); |
| 91 return; |
| 92 } |
| 93 } |
| 94 |
| 95 StartImpl(web_contents, check_webapk_compatible, true); |
| 96 } |
| 97 |
| 98 void AddToHomescreenManager::StartImpl(content::WebContents* web_contents, |
| 99 bool check_webapk_compatible, |
| 100 bool can_use_webapk_install_flow) { |
| 101 if (!check_webapk_compatible) |
| 83 ShowDialog(); | 102 ShowDialog(); |
| 84 } | |
| 85 | 103 |
| 86 data_fetcher_ = new AddToHomescreenDataFetcher( | 104 data_fetcher_ = new AddToHomescreenDataFetcher( |
| 87 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), | 105 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), |
| 88 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), | 106 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), |
| 89 ShortcutHelper::GetIdealSplashImageSizeInPx(), | 107 ShortcutHelper::GetIdealSplashImageSizeInPx(), |
| 90 ShortcutHelper::GetMinimumSplashImageSizeInPx(), | 108 ShortcutHelper::GetMinimumSplashImageSizeInPx(), |
| 91 ShortcutHelper::GetIdealBadgeIconSizeInPx(), | 109 ShortcutHelper::GetIdealBadgeIconSizeInPx(), |
| 92 check_webapk_compatible, this); | 110 check_webapk_compatible, can_use_webapk_install_flow, this); |
| 93 } | 111 } |
| 94 | 112 |
| 95 AddToHomescreenManager::~AddToHomescreenManager() { | 113 AddToHomescreenManager::~AddToHomescreenManager() { |
| 96 if (data_fetcher_) { | 114 if (data_fetcher_) { |
| 97 data_fetcher_->set_weak_observer(nullptr); | 115 data_fetcher_->set_weak_observer(nullptr); |
| 98 data_fetcher_ = nullptr; | 116 data_fetcher_ = nullptr; |
| 99 } | 117 } |
| 100 } | 118 } |
| 101 | 119 |
| 120 void AddToHomescreenManager::OnCanUseGooglePlayInstallApi( |
| 121 content::WebContents* web_contents, |
| 122 bool check_webapk_compatible, |
| 123 bool isAvailable) { |
| 124 StartImpl(web_contents, check_webapk_compatible, isAvailable); |
| 125 } |
| 126 |
| 102 void AddToHomescreenManager::ShowDialog() { | 127 void AddToHomescreenManager::ShowDialog() { |
| 103 JNIEnv* env = base::android::AttachCurrentThread(); | 128 JNIEnv* env = base::android::AttachCurrentThread(); |
| 104 Java_AddToHomescreenManager_showDialog(env, java_ref_); | 129 Java_AddToHomescreenManager_showDialog(env, java_ref_); |
| 105 } | 130 } |
| 106 | 131 |
| 107 void AddToHomescreenManager::AddShortcut(const ShortcutInfo& info, | 132 void AddToHomescreenManager::AddShortcut(const ShortcutInfo& info, |
| 108 const SkBitmap& icon) { | 133 const SkBitmap& icon) { |
| 109 DCHECK(add_shortcut_pending_); | 134 DCHECK(add_shortcut_pending_); |
| 110 if (!add_shortcut_pending_) | 135 if (!add_shortcut_pending_) |
| 111 return; | 136 return; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 212 |
| 188 if (add_shortcut_pending_) | 213 if (add_shortcut_pending_) |
| 189 AddShortcut(info, primary_icon); | 214 AddShortcut(info, primary_icon); |
| 190 } | 215 } |
| 191 | 216 |
| 192 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info, | 217 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info, |
| 193 const SkBitmap& icon) { | 218 const SkBitmap& icon) { |
| 194 banners::AppBannerInfoBarDelegateAndroid::Create( | 219 banners::AppBannerInfoBarDelegateAndroid::Create( |
| 195 data_fetcher_->web_contents(), nullptr, info.user_title, | 220 data_fetcher_->web_contents(), nullptr, info.user_title, |
| 196 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), | 221 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), |
| 197 -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU); | 222 -1 /* event_request_id */, true /* can_use_webapk_install_flow */, |
| 223 webapk::INSTALL_SOURCE_MENU); |
| 198 } | 224 } |
| 199 | 225 |
| 200 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( | 226 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |
| 201 const SkBitmap& bitmap, | 227 const SkBitmap& bitmap, |
| 202 const GURL& url, | 228 const GURL& url, |
| 203 bool* is_generated) { | 229 bool* is_generated) { |
| 204 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 230 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 205 | 231 |
| 206 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, | 232 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, |
| 207 is_generated); | 233 is_generated); |
| 208 } | 234 } |
| OLD | NEW |