| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shortcut_helper.h" | 5 #include "chrome/browser/android/shortcut_helper.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 15 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "jni/ShortcutHelper_jni.h" | 18 #include "jni/ShortcutHelper_jni.h" |
| 19 #include "ui/gfx/android/java_bitmap.h" | 19 #include "ui/gfx/android/java_bitmap.h" |
| 20 #include "ui/gfx/color_analysis.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 using content::Manifest; | 23 using content::Manifest; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 static int kIdealHomescreenIconSize = -1; | 27 static int kIdealHomescreenIconSize = -1; |
| 27 static int kMinimumHomescreenIconSize = -1; | 28 static int kMinimumHomescreenIconSize = -1; |
| 28 static int kIdealSplashImageSize = -1; | 29 static int kIdealSplashImageSize = -1; |
| 29 static int kMinimumSplashImageSize = -1; | 30 static int kMinimumSplashImageSize = -1; |
| 30 | 31 |
| 32 static int kDefaultRGBIconValue = 145; |
| 33 |
| 31 // Retrieves and caches the ideal and minimum sizes of the Home screen icon | 34 // Retrieves and caches the ideal and minimum sizes of the Home screen icon |
| 32 // and the splash screen image. | 35 // and the splash screen image. |
| 33 void GetHomescreenIconAndSplashImageSizes() { | 36 void GetHomescreenIconAndSplashImageSizes() { |
| 34 JNIEnv* env = base::android::AttachCurrentThread(); | 37 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 ScopedJavaLocalRef<jintArray> java_size_array = | 38 ScopedJavaLocalRef<jintArray> java_size_array = |
| 36 Java_ShortcutHelper_getHomescreenIconAndSplashImageSizes(env, | 39 Java_ShortcutHelper_getHomescreenIconAndSplashImageSizes(env, |
| 37 base::android::GetApplicationContext()); | 40 base::android::GetApplicationContext()); |
| 38 std::vector<int> sizes; | 41 std::vector<int> sizes; |
| 39 base::android::JavaIntArrayToIntVector( | 42 base::android::JavaIntArrayToIntVector( |
| 40 env, java_size_array.obj(), &sizes); | 43 env, java_size_array.obj(), &sizes); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 java_webapp_id.obj(), | 87 java_webapp_id.obj(), |
| 85 java_url.obj(), | 88 java_url.obj(), |
| 86 java_user_title.obj(), | 89 java_user_title.obj(), |
| 87 java_name.obj(), | 90 java_name.obj(), |
| 88 java_short_name.obj(), | 91 java_short_name.obj(), |
| 89 java_bitmap.obj(), | 92 java_bitmap.obj(), |
| 90 info.display == blink::WebDisplayModeStandalone, | 93 info.display == blink::WebDisplayModeStandalone, |
| 91 info.orientation, | 94 info.orientation, |
| 92 info.source, | 95 info.source, |
| 93 info.theme_color, | 96 info.theme_color, |
| 94 info.background_color); | 97 info.background_color, |
| 98 info.is_icon_generated); |
| 95 } | 99 } |
| 96 | 100 |
| 97 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 101 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
| 98 if (kIdealHomescreenIconSize == -1) | 102 if (kIdealHomescreenIconSize == -1) |
| 99 GetHomescreenIconAndSplashImageSizes(); | 103 GetHomescreenIconAndSplashImageSizes(); |
| 100 return kIdealHomescreenIconSize; | 104 return kIdealHomescreenIconSize; |
| 101 } | 105 } |
| 102 | 106 |
| 103 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 107 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { |
| 104 if (kMinimumHomescreenIconSize == -1) | 108 if (kMinimumHomescreenIconSize == -1) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 ScopedJavaLocalRef<jobject> java_splash_image = | 152 ScopedJavaLocalRef<jobject> java_splash_image = |
| 149 gfx::ConvertToJavaBitmap(&splash_image); | 153 gfx::ConvertToJavaBitmap(&splash_image); |
| 150 | 154 |
| 151 Java_ShortcutHelper_storeWebappData( | 155 Java_ShortcutHelper_storeWebappData( |
| 152 env, | 156 env, |
| 153 base::android::GetApplicationContext(), | 157 base::android::GetApplicationContext(), |
| 154 java_webapp_id.obj(), | 158 java_webapp_id.obj(), |
| 155 java_splash_image.obj()); | 159 java_splash_image.obj()); |
| 156 } | 160 } |
| 157 | 161 |
| 162 // static |
| 163 SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, |
| 164 const GURL& url, |
| 165 bool* is_generated) { |
| 166 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 167 |
| 168 JNIEnv* env = base::android::AttachCurrentThread(); |
| 169 ScopedJavaLocalRef<jobject> result; |
| 170 *is_generated = false; |
| 171 |
| 172 if (!bitmap.isNull()) { |
| 173 ScopedJavaLocalRef<jobject> java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); |
| 174 if (Java_ShortcutHelper_isIconLargeEnoughForLauncher( |
| 175 env, base::android::GetApplicationContext(), java_bitmap.obj())) { |
| 176 result = Java_ShortcutHelper_modifyIconForLauncher( |
| 177 env, base::android::GetApplicationContext(), java_bitmap.obj()); |
| 178 } |
| 179 } |
| 180 |
| 181 if (result.is_null()) { |
| 182 ScopedJavaLocalRef<jstring> java_url = |
| 183 base::android::ConvertUTF8ToJavaString(env, url.spec()); |
| 184 SkColor mean_color = SkColorSetRGB( |
| 185 kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue); |
| 186 |
| 187 if (!bitmap.isNull()) |
| 188 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); |
| 189 |
| 190 *is_generated = true; |
| 191 result = Java_ShortcutHelper_generateLauncherIcon( |
| 192 env, base::android::GetApplicationContext(), java_url.obj(), |
| 193 SkColorGetR(mean_color), SkColorGetG(mean_color), |
| 194 SkColorGetB(mean_color)); |
| 195 } |
| 196 |
| 197 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); |
| 198 } |
| 199 |
| 158 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 200 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 159 return RegisterNativesImpl(env); | 201 return RegisterNativesImpl(env); |
| 160 } | 202 } |
| OLD | NEW |