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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 static int kIdealSplashImageSize = -1; | 29 static int kIdealSplashImageSize = -1; |
30 static int kMinimumSplashImageSize = -1; | 30 static int kMinimumSplashImageSize = -1; |
31 | 31 |
32 static int kDefaultRGBIconValue = 145; | 32 static int kDefaultRGBIconValue = 145; |
33 | 33 |
34 // 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 |
35 // and the splash screen image. | 35 // and the splash screen image. |
36 void GetHomescreenIconAndSplashImageSizes() { | 36 void GetHomescreenIconAndSplashImageSizes() { |
37 JNIEnv* env = base::android::AttachCurrentThread(); | 37 JNIEnv* env = base::android::AttachCurrentThread(); |
38 ScopedJavaLocalRef<jintArray> java_size_array = | 38 ScopedJavaLocalRef<jintArray> java_size_array = |
39 Java_ShortcutHelper_getHomescreenIconAndSplashImageSizes(env, | 39 Java_ShortcutHelper_getHomeScreenIconAndSplashImageSizes(env, |
40 base::android::GetApplicationContext()); | 40 base::android::GetApplicationContext()); |
41 std::vector<int> sizes; | 41 std::vector<int> sizes; |
42 base::android::JavaIntArrayToIntVector( | 42 base::android::JavaIntArrayToIntVector( |
43 env, java_size_array.obj(), &sizes); | 43 env, java_size_array.obj(), &sizes); |
44 | 44 |
45 // Check that the size returned is what is expected. | 45 // Check that the size returned is what is expected. |
46 DCHECK(sizes.size() == 4); | 46 DCHECK(sizes.size() == 4); |
47 | 47 |
48 // This ordering must be kept up to date with the Java ShortcutHelper. | 48 // This ordering must be kept up to date with the Java ShortcutHelper. |
49 kIdealHomescreenIconSize = sizes[0]; | 49 kIdealHomescreenIconSize = sizes[0]; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, | 163 SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, |
164 const GURL& url, | 164 const GURL& url, |
165 bool* is_generated) { | 165 bool* is_generated) { |
166 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 166 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
167 | 167 |
168 JNIEnv* env = base::android::AttachCurrentThread(); | 168 JNIEnv* env = base::android::AttachCurrentThread(); |
169 ScopedJavaLocalRef<jobject> result; | 169 ScopedJavaLocalRef<jobject> result; |
170 *is_generated = false; | 170 *is_generated = false; |
171 | 171 |
172 if (!bitmap.isNull()) { | 172 if (!bitmap.isNull()) { |
173 ScopedJavaLocalRef<jobject> java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); | |
174 if (Java_ShortcutHelper_isIconLargeEnoughForLauncher( | 173 if (Java_ShortcutHelper_isIconLargeEnoughForLauncher( |
175 env, base::android::GetApplicationContext(), java_bitmap.obj())) { | 174 env, base::android::GetApplicationContext(), bitmap.width(), |
176 result = Java_ShortcutHelper_modifyIconForLauncher( | 175 bitmap.height())) { |
| 176 ScopedJavaLocalRef<jobject> java_bitmap = |
| 177 gfx::ConvertToJavaBitmap(&bitmap); |
| 178 result = Java_ShortcutHelper_createHomeScreenIconFromWebIcon( |
177 env, base::android::GetApplicationContext(), java_bitmap.obj()); | 179 env, base::android::GetApplicationContext(), java_bitmap.obj()); |
178 } | 180 } |
179 } | 181 } |
180 | 182 |
181 if (result.is_null()) { | 183 if (result.is_null()) { |
182 ScopedJavaLocalRef<jstring> java_url = | 184 ScopedJavaLocalRef<jstring> java_url = |
183 base::android::ConvertUTF8ToJavaString(env, url.spec()); | 185 base::android::ConvertUTF8ToJavaString(env, url.spec()); |
184 SkColor mean_color = SkColorSetRGB( | 186 SkColor mean_color = SkColorSetRGB( |
185 kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue); | 187 kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue); |
186 | 188 |
187 if (!bitmap.isNull()) | 189 if (!bitmap.isNull()) |
188 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); | 190 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); |
189 | 191 |
190 *is_generated = true; | 192 *is_generated = true; |
191 result = Java_ShortcutHelper_generateLauncherIcon( | 193 result = Java_ShortcutHelper_generateHomeScreenIcon( |
192 env, base::android::GetApplicationContext(), java_url.obj(), | 194 env, base::android::GetApplicationContext(), java_url.obj(), |
193 SkColorGetR(mean_color), SkColorGetG(mean_color), | 195 SkColorGetR(mean_color), SkColorGetG(mean_color), |
194 SkColorGetB(mean_color)); | 196 SkColorGetB(mean_color)); |
195 } | 197 } |
196 | 198 |
197 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); | 199 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); |
198 } | 200 } |
199 | 201 |
200 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 202 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
201 return RegisterNativesImpl(env); | 203 return RegisterNativesImpl(env); |
202 } | 204 } |
OLD | NEW |