Chromium Code Reviews| Index: chrome/browser/android/shortcut_helper.cc |
| diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc |
| index cead81b0d9f22a05e0c5ef072dfd7b067508c017..2371a56bac589576b4f6e5607df2aa6b76550055 100644 |
| --- a/chrome/browser/android/shortcut_helper.cc |
| +++ b/chrome/browser/android/shortcut_helper.cc |
| @@ -7,6 +7,7 @@ |
| #include <jni.h> |
| #include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| #include "base/android/jni_string.h" |
| #include "base/basictypes.h" |
| #include "base/strings/string16.h" |
| @@ -20,6 +21,31 @@ |
| using content::Manifest; |
| +namespace { |
| +static int kIdealIconSize = -1; |
| +static int kMinimumIconSize = -1; |
| +static int kIdealSplashImageSize = -1; |
| +static int kMinimumSplashImageSize = -1; |
| + |
| +// Retrieves and caches the ideal and minimum sizes of the home screen icon |
|
gone
2015/09/14 23:03:32
"launcher" or "Home screen"
Lalit Maganti
2015/09/15 16:59:03
Done.
|
| +// and the splash screen image. |
| +void GetIconAndSplashImageSizes() { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + ScopedJavaLocalRef<jintArray> java_size_array = |
| + Java_ShortcutHelper_getIconAndSplashImageSizes(env, |
| + base::android::GetApplicationContext()); |
| + std::vector<int> size_vector; |
| + base::android::JavaIntArrayToIntVector( |
| + env, java_size_array.obj(), &size_vector); |
| + |
| + // This ordering must be kept up to date with the Java ShortcutHelper. |
|
gone
2015/09/14 23:03:32
Assert that the array size is correct to loosely e
Lalit Maganti
2015/09/15 16:59:03
Done.
|
| + kIdealIconSize = size_vector[0]; |
| + kMinimumIconSize = size_vector[1]; |
| + kIdealSplashImageSize = size_vector[2]; |
| + kMinimumSplashImageSize = size_vector[3]; |
| +} |
| +} // namespace |
| + |
| // static |
| void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
| const ShortcutInfo& info, |
| @@ -59,11 +85,36 @@ void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
| info.background_color); |
| } |
| +int ShortcutHelper::GetIdealSplashImageSizeInDp() { |
| + if (kIdealIconSize == -1) |
| + GetIconAndSplashImageSizes(); |
| + return kIdealIconSize; |
| +} |
| + |
| +int ShortcutHelper::GetMinimumSplashImageSizeInDp() { |
| + if (kMinimumIconSize == -1) |
| + GetIconAndSplashImageSizes(); |
| + return kMinimumIconSize; |
| +} |
| + |
| +int ShortcutHelper::GetIdealIconSizeInDp() { |
| + if (kIdealSplashImageSize == -1) |
| + GetIconAndSplashImageSizes(); |
| + return kIdealSplashImageSize; |
| +} |
| + |
| +int ShortcutHelper::GetMinimumIconSizeInDp() { |
| + if (kMinimumSplashImageSize == -1) |
| + GetIconAndSplashImageSizes(); |
| + return kMinimumSplashImageSize; |
| +} |
| + |
| // static |
| void ShortcutHelper::FetchSplashScreenImage( |
| content::WebContents* web_contents, |
| const GURL& image_url, |
| const int ideal_splash_image_size_in_dp, |
| + const int minimum_splash_image_size_in_dp, |
| const std::string& webapp_id) { |
| // This is a fire and forget task. It is not vital for the splash screen image |
| // to be downloaded so if the downloader returns false there is no fallback. |
| @@ -71,6 +122,7 @@ void ShortcutHelper::FetchSplashScreenImage( |
| web_contents, |
| image_url, |
| ideal_splash_image_size_in_dp, |
| + minimum_splash_image_size_in_dp, |
| base::Bind(&ShortcutHelper::StoreWebappData, webapp_id)); |
| } |