[WebAPKs]: Reduce the parameters of ShortcutHelper::AddToLauncherWithSkBitmap()
This CL removes the |webapp_id| and |splash_image_callback| parameters from
ShortcutHelper::AddToLauncherWithSkBitmap(). This CL adds the needed
information to ShortcutInfo so that AddToLauncherWithSkBitmap() can create
the callback itself.
The goal of this CL is to enable
AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished() to call
ShortcutHelper::AddToLauncherWithSkBitmap() in a subsequent CL.
BUG=696132
Review-Url: https://codereview.chromium.org/2724723002
Cr-Commit-Position: refs/heads/master@{#454080}
diff --git a/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc b/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc
index a91efcc..1e10173 100644
--- a/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc
+++ b/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc
@@ -6,7 +6,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
-#include "base/guid.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/timer/elapsed_timer.h"
@@ -295,12 +294,8 @@
AppBannerSettingsHelper::RecordBannerInstallEvent(
web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
- if (weak_manager_) {
- const std::string& uid = base::GenerateGUID();
- ShortcutHelper::AddToLauncherWithSkBitmap(
- web_contents->GetBrowserContext(), *shortcut_info_, uid,
- *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid));
- }
+ ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_,
+ *icon_.get());
SendBannerAccepted();
return true;
@@ -354,8 +349,7 @@
WebApkInstaller::FinishCallback callback =
base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
weak_ptr_factory_.GetWeakPtr());
- ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
- *shortcut_info_,
+ ShortcutHelper::InstallWebApkWithSkBitmap(web_contents, *shortcut_info_,
*icon_.get(), callback);
SendBannerAccepted();
diff --git a/chrome/browser/android/banners/app_banner_manager_android.cc b/chrome/browser/android/banners/app_banner_manager_android.cc
index 866e583..a6d0f74c 100644
--- a/chrome/browser/android/banners/app_banner_manager_android.cc
+++ b/chrome/browser/android/banners/app_banner_manager_android.cc
@@ -47,6 +47,16 @@
shortcut_info->best_primary_icon_url = icon_url;
shortcut_info->UpdateSource(ShortcutInfo::SOURCE_APP_BANNER);
}
+
+ shortcut_info->ideal_splash_image_size_in_px =
+ ShortcutHelper::GetIdealSplashImageSizeInPx();
+ shortcut_info->minimum_splash_image_size_in_px =
+ ShortcutHelper::GetMinimumSplashImageSizeInPx();
+ shortcut_info->splash_image_url = ManifestIconSelector::FindBestMatchingIcon(
+ manifest.icons, shortcut_info->ideal_splash_image_size_in_px,
+ shortcut_info->minimum_splash_image_size_in_px,
+ content::Manifest::Icon::IconPurpose::ANY);
+
return shortcut_info;
}
@@ -67,25 +77,6 @@
java_banner_manager_.Reset();
}
-base::Closure AppBannerManagerAndroid::FetchWebappSplashScreenImageCallback(
- const std::string& webapp_id) {
- content::WebContents* contents = web_contents();
- DCHECK(contents);
-
- int ideal_splash_image_size_in_px =
- ShortcutHelper::GetIdealSplashImageSizeInPx();
- int minimum_splash_image_size_in_px =
- ShortcutHelper::GetMinimumSplashImageSizeInPx();
- GURL image_url = ManifestIconSelector::FindBestMatchingIcon(
- manifest_.icons, ideal_splash_image_size_in_px,
- minimum_splash_image_size_in_px,
- content::Manifest::Icon::IconPurpose::ANY);
-
- return base::Bind(&ShortcutHelper::FetchSplashScreenImage, contents,
- image_url, ideal_splash_image_size_in_px,
- minimum_splash_image_size_in_px, webapp_id);
-}
-
const base::android::ScopedJavaGlobalRef<jobject>&
AppBannerManagerAndroid::GetJavaBannerManager() const {
return java_banner_manager_;
diff --git a/chrome/browser/android/banners/app_banner_manager_android.h b/chrome/browser/android/banners/app_banner_manager_android.h
index 92f8ce0..4fcdeef 100644
--- a/chrome/browser/android/banners/app_banner_manager_android.h
+++ b/chrome/browser/android/banners/app_banner_manager_android.h
@@ -56,11 +56,6 @@
// AppBannerManager overrides.
void RequestAppBanner(const GURL& validated_url, bool is_debug_mode) override;
- // Returns a callback which fetches the splash screen image and stores it in
- // a WebappDataStorage.
- base::Closure FetchWebappSplashScreenImageCallback(
- const std::string& webapp_id) override;
-
// Registers native methods.
static bool Register(JNIEnv* env);
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc
index c3e60da4..5e28acd 100644
--- a/chrome/browser/android/shortcut_helper.cc
+++ b/chrome/browser/android/shortcut_helper.cc
@@ -12,7 +12,7 @@
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "base/callback.h"
-#include "base/command_line.h"
+#include "base/guid.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -133,14 +133,17 @@
// static
void ShortcutHelper::AddToLauncherWithSkBitmap(
- content::BrowserContext* browser_context,
+ content::WebContents* web_contents,
const ShortcutInfo& info,
- const std::string& webapp_id,
- const SkBitmap& icon_bitmap,
- const base::Closure& splash_image_callback) {
+ const SkBitmap& icon_bitmap) {
+ std::string webapp_id = base::GenerateGUID();
if (info.display == blink::WebDisplayModeStandalone ||
info.display == blink::WebDisplayModeFullscreen) {
- AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback);
+ AddWebappWithSkBitmap(
+ info, webapp_id, icon_bitmap,
+ base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents,
+ info.splash_image_url, info.ideal_splash_image_size_in_px,
+ info.minimum_splash_image_size_in_px, webapp_id));
GooglePlayInstallState state =
ChromeWebApkHost::GetGooglePlayInstallState();
if (state != GooglePlayInstallState::SUPPORTED)
@@ -152,11 +155,11 @@
// static
void ShortcutHelper::InstallWebApkWithSkBitmap(
- content::BrowserContext* browser_context,
+ content::WebContents* web_contents,
const ShortcutInfo& info,
const SkBitmap& icon_bitmap,
const WebApkInstaller::FinishCallback& callback) {
- WebApkInstallService::Get(browser_context)
+ WebApkInstallService::Get(web_contents->GetBrowserContext())
->InstallAsync(info, icon_bitmap, callback);
// Don't record metric for users who install WebAPKs via "unsigned sources"
// flow.
diff --git a/chrome/browser/android/shortcut_helper.h b/chrome/browser/android/shortcut_helper.h
index 7a30fd3..d352f97 100644
--- a/chrome/browser/android/shortcut_helper.h
+++ b/chrome/browser/android/shortcut_helper.h
@@ -18,9 +18,8 @@
#include "third_party/skia/include/core/SkBitmap.h"
namespace content {
-class BrowserContext;
class WebContents;
-} // namespace content
+}
// ShortcutHelper is the C++ counterpart of org.chromium.chrome.browser's
// ShortcutHelper in Java.
@@ -36,16 +35,13 @@
// added depends on the properties in |info|. Calls one of
// InstallWebApkInBackgroundWithSkBitmap, AddWebappInBackgroundWithSkBitmap,
// or AddShortcutInBackgroundWithSkBitmap.
- static void AddToLauncherWithSkBitmap(
- content::BrowserContext* browser_context,
- const ShortcutInfo& info,
- const std::string& webapp_id,
- const SkBitmap& icon_bitmap,
- const base::Closure& splash_image_callback);
+ static void AddToLauncherWithSkBitmap(content::WebContents* web_contents,
+ const ShortcutInfo& info,
+ const SkBitmap& icon_bitmap);
// Installs WebAPK and adds shortcut to the launcher.
static void InstallWebApkWithSkBitmap(
- content::BrowserContext* browser_context,
+ content::WebContents* web_conetnts,
const ShortcutInfo& info,
const SkBitmap& icon_bitmap,
const WebApkInstaller::FinishCallback& callback);
diff --git a/chrome/browser/android/shortcut_info.cc b/chrome/browser/android/shortcut_info.cc
index 817d877..9d2d1c4 100644
--- a/chrome/browser/android/shortcut_info.cc
+++ b/chrome/browser/android/shortcut_info.cc
@@ -10,7 +10,9 @@
orientation(blink::WebScreenOrientationLockDefault),
source(SOURCE_ADD_TO_HOMESCREEN_SHORTCUT),
theme_color(content::Manifest::kInvalidOrMissingColor),
- background_color(content::Manifest::kInvalidOrMissingColor) {}
+ background_color(content::Manifest::kInvalidOrMissingColor),
+ ideal_splash_image_size_in_px(0),
+ minimum_splash_image_size_in_px(0) {}
ShortcutInfo::ShortcutInfo(const ShortcutInfo& other) = default;
diff --git a/chrome/browser/android/shortcut_info.h b/chrome/browser/android/shortcut_info.h
index 8c6a25f3..93657b4 100644
--- a/chrome/browser/android/shortcut_info.h
+++ b/chrome/browser/android/shortcut_info.h
@@ -56,6 +56,9 @@
Source source;
int64_t theme_color;
int64_t background_color;
+ int ideal_splash_image_size_in_px;
+ int minimum_splash_image_size_in_px;
+ GURL splash_image_url;
GURL best_primary_icon_url;
GURL best_badge_icon_url;
std::vector<std::string> icon_urls;
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
index 2dea7aa..76564cf3 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
@@ -7,7 +7,6 @@
#include <vector>
#include "base/bind.h"
-#include "base/callback.h"
#include "base/location.h"
#include "base/strings/string16.h"
#include "base/task_runner_util.h"
@@ -100,13 +99,6 @@
Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
}
-base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback(
- const std::string& webapp_id) {
- return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(),
- splash_screen_url_, ideal_splash_image_size_in_px_,
- minimum_splash_image_size_in_px_, webapp_id);
-}
-
void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo(
const WebApplicationInfo& received_web_app_info) {
is_waiting_for_web_application_info_ = false;
@@ -244,10 +236,13 @@
}
// Save the splash screen URL for the later download.
- splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon(
+ shortcut_info_.splash_image_url = ManifestIconSelector::FindBestMatchingIcon(
data.manifest.icons, ideal_splash_image_size_in_px_,
minimum_splash_image_size_in_px_,
content::Manifest::Icon::IconPurpose::ANY);
+ shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_;
+ shortcut_info_.minimum_splash_image_size_in_px =
+ minimum_splash_image_size_in_px_;
weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title);
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h
index ee209ab..73baecd3 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h
@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_
#define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_
-#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/task/cancelable_task_tracker.h"
@@ -82,10 +81,6 @@
bool check_webapk_compatible,
Observer* observer);
- // Returns a callback which fetches the splash screen image to be stored for
- // the webapp with the specified |id|.
- base::Closure FetchSplashScreenImageCallback(const std::string& id);
-
// IPC message received when the initialization is finished.
void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info);
@@ -136,7 +131,6 @@
SkBitmap badge_icon_;
SkBitmap primary_icon_;
ShortcutInfo shortcut_info_;
- GURL splash_screen_url_;
base::CancelableTaskTracker favicon_task_tracker_;
base::Timer data_timeout_timer_;
diff --git a/chrome/browser/android/webapps/add_to_homescreen_manager.cc b/chrome/browser/android/webapps/add_to_homescreen_manager.cc
index 45b0459e..d3eac8c 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_manager.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_manager.cc
@@ -6,7 +6,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
-#include "base/guid.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
@@ -117,11 +116,7 @@
return;
RecordAddToHomescreen();
-
- const std::string& uid = base::GenerateGUID();
- ShortcutHelper::AddToLauncherWithSkBitmap(
- web_contents->GetBrowserContext(), info, uid, icon,
- data_fetcher_->FetchSplashScreenImageCallback(uid));
+ ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, info, icon);
// Fire the appinstalled event.
blink::mojom::InstallationServicePtr installation_service;