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 de75b8a9bbe9c38311932b53b6fff658e2de592d..7219d3f3f8c21d308f06012c6507f4ba7f729bfb 100644 |
| --- a/chrome/browser/android/shortcut_helper.cc |
| +++ b/chrome/browser/android/shortcut_helper.cc |
| @@ -17,6 +17,7 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "jni/ShortcutHelper_jni.h" |
| #include "ui/gfx/android/java_bitmap.h" |
| +#include "ui/gfx/color_analysis.h" |
| #include "url/gurl.h" |
| using content::Manifest; |
| @@ -28,6 +29,8 @@ static int kMinimumHomescreenIconSize = -1; |
| static int kIdealSplashImageSize = -1; |
| static int kMinimumSplashImageSize = -1; |
| +static int kDefaultRGBIconValue = 145; |
| + |
| // Retrieves and caches the ideal and minimum sizes of the Home screen icon |
| // and the splash screen image. |
| void GetHomescreenIconAndSplashImageSizes() { |
| @@ -91,7 +94,8 @@ void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
| info.orientation, |
| info.source, |
| info.theme_color, |
| - info.background_color); |
| + info.background_color, |
| + info.generated_icon); |
| } |
| int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
| @@ -155,6 +159,44 @@ void ShortcutHelper::StoreWebappData( |
| java_splash_image.obj()); |
| } |
| +// static |
| +SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, |
| + const GURL& url, |
| + bool* generated) { |
|
gone
2015/10/21 23:35:57
is_generated
mlamouri (slow - plz ping)
2015/10/22 14:37:06
Done.
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + ScopedJavaLocalRef<jobject> result; |
| + *generated = false; |
| + |
| + if (!bitmap.isNull()) { |
| + ScopedJavaLocalRef<jobject> java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); |
| + if (Java_ShortcutHelper_isIconLargeEnoughForLauncher( |
| + env, base::android::GetApplicationContext(), java_bitmap.obj())) { |
| + result = Java_ShortcutHelper_modifyIconForLauncher( |
| + env, base::android::GetApplicationContext(), java_bitmap.obj()); |
| + } |
| + } |
| + |
| + if (result.is_null()) { |
| + ScopedJavaLocalRef<jstring> java_url = |
| + base::android::ConvertUTF8ToJavaString(env, url.spec()); |
| + SkColor mean_color = SkColorSetRGB( |
| + kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue); |
| + |
| + if (!bitmap.isNull()) |
| + mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); |
| + |
| + *generated = true; |
| + result = Java_ShortcutHelper_generateLauncherIcon( |
| + env, base::android::GetApplicationContext(), java_url.obj(), |
| + SkColorGetR(mean_color), SkColorGetG(mean_color), |
| + SkColorGetB(mean_color)); |
| + } |
| + |
| + return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); |
| +} |
| + |
| bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| return RegisterNativesImpl(env); |
| } |