| 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 13 matching lines...) Expand all Loading... |
| 24 #include "ui/gfx/android/java_bitmap.h" | 24 #include "ui/gfx/android/java_bitmap.h" |
| 25 #include "ui/gfx/color_analysis.h" | 25 #include "ui/gfx/color_analysis.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 using base::android::JavaParamRef; | 28 using base::android::JavaParamRef; |
| 29 using base::android::ScopedJavaLocalRef; | 29 using base::android::ScopedJavaLocalRef; |
| 30 using content::Manifest; | 30 using content::Manifest; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 static int kIdealHomescreenIconSize = -1; | 34 int g_ideal_homescreen_icon_size = -1; |
| 35 static int kMinimumHomescreenIconSize = -1; | 35 int g_minimum_homescreen_icon_size = -1; |
| 36 static int kIdealSplashImageSize = -1; | 36 int g_ideal_splash_image_size = -1; |
| 37 static int kMinimumSplashImageSize = -1; | 37 int g_minimum_splash_image_size = -1; |
| 38 int g_ideal_badge_icon_size = -1; |
| 38 | 39 |
| 39 static int kDefaultRGBIconValue = 145; | 40 int g_default_rgb_icon_value = 145; |
| 40 | 41 |
| 41 // Retrieves and caches the ideal and minimum sizes of the Home screen icon | 42 // Retrieves and caches the ideal and minimum sizes of the Home screen icon |
| 42 // and the splash screen image. | 43 // and the splash screen image. |
| 43 void GetHomescreenIconAndSplashImageSizes() { | 44 void GetHomescreenIconAndSplashImageSizes() { |
| 44 JNIEnv* env = base::android::AttachCurrentThread(); | 45 JNIEnv* env = base::android::AttachCurrentThread(); |
| 45 ScopedJavaLocalRef<jintArray> java_size_array = | 46 ScopedJavaLocalRef<jintArray> java_size_array = |
| 46 Java_ShortcutHelper_getHomeScreenIconAndSplashImageSizes(env); | 47 Java_ShortcutHelper_getHomeScreenIconAndSplashImageSizes(env); |
| 47 std::vector<int> sizes; | 48 std::vector<int> sizes; |
| 48 base::android::JavaIntArrayToIntVector( | 49 base::android::JavaIntArrayToIntVector( |
| 49 env, java_size_array.obj(), &sizes); | 50 env, java_size_array.obj(), &sizes); |
| 50 | 51 |
| 51 // Check that the size returned is what is expected. | 52 // Check that the size returned is what is expected. |
| 52 DCHECK(sizes.size() == 4); | 53 DCHECK(sizes.size() == 5); |
| 53 | 54 |
| 54 // This ordering must be kept up to date with the Java ShortcutHelper. | 55 // This ordering must be kept up to date with the Java ShortcutHelper. |
| 55 kIdealHomescreenIconSize = sizes[0]; | 56 g_ideal_homescreen_icon_size = sizes[0]; |
| 56 kMinimumHomescreenIconSize = sizes[1]; | 57 g_minimum_homescreen_icon_size = sizes[1]; |
| 57 kIdealSplashImageSize = sizes[2]; | 58 g_ideal_splash_image_size = sizes[2]; |
| 58 kMinimumSplashImageSize = sizes[3]; | 59 g_minimum_splash_image_size = sizes[3]; |
| 60 g_ideal_badge_icon_size = sizes[4]; |
| 59 | 61 |
| 60 // Try to ensure that the data returned is sane. | 62 // Try to ensure that the data returned is sane. |
| 61 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); | 63 DCHECK(g_minimum_homescreen_icon_size <= g_ideal_homescreen_icon_size); |
| 62 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); | 64 DCHECK(g_minimum_splash_image_size <= g_ideal_splash_image_size); |
| 63 } | 65 } |
| 64 | 66 |
| 65 } // anonymous namespace | 67 } // anonymous namespace |
| 66 | 68 |
| 67 // static | 69 // static |
| 68 void ShortcutHelper::AddToLauncherWithSkBitmap( | 70 void ShortcutHelper::AddToLauncherWithSkBitmap( |
| 69 content::BrowserContext* browser_context, | 71 content::BrowserContext* browser_context, |
| 70 const ShortcutInfo& info, | 72 const ShortcutInfo& info, |
| 71 const std::string& webapp_id, | 73 const std::string& webapp_id, |
| 72 const SkBitmap& icon_bitmap, | 74 const SkBitmap& icon_bitmap, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 Java_ShortcutHelper_addShortcut(env, java_url, java_user_title, java_bitmap, | 146 Java_ShortcutHelper_addShortcut(env, java_url, java_user_title, java_bitmap, |
| 145 info.source); | 147 info.source); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void ShortcutHelper::ShowWebApkInstallInProgressToast() { | 150 void ShortcutHelper::ShowWebApkInstallInProgressToast() { |
| 149 Java_ShortcutHelper_showWebApkInstallInProgressToast( | 151 Java_ShortcutHelper_showWebApkInstallInProgressToast( |
| 150 base::android::AttachCurrentThread()); | 152 base::android::AttachCurrentThread()); |
| 151 } | 153 } |
| 152 | 154 |
| 153 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() { | 155 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() { |
| 154 if (kIdealHomescreenIconSize == -1) | 156 if (g_ideal_homescreen_icon_size == -1) |
| 155 GetHomescreenIconAndSplashImageSizes(); | 157 GetHomescreenIconAndSplashImageSizes(); |
| 156 return kIdealHomescreenIconSize; | 158 return g_ideal_homescreen_icon_size; |
| 157 } | 159 } |
| 158 | 160 |
| 159 int ShortcutHelper::GetMinimumHomescreenIconSizeInPx() { | 161 int ShortcutHelper::GetMinimumHomescreenIconSizeInPx() { |
| 160 if (kMinimumHomescreenIconSize == -1) | 162 if (g_minimum_homescreen_icon_size == -1) |
| 161 GetHomescreenIconAndSplashImageSizes(); | 163 GetHomescreenIconAndSplashImageSizes(); |
| 162 return kMinimumHomescreenIconSize; | 164 return g_minimum_homescreen_icon_size; |
| 163 } | 165 } |
| 164 | 166 |
| 165 int ShortcutHelper::GetIdealSplashImageSizeInPx() { | 167 int ShortcutHelper::GetIdealSplashImageSizeInPx() { |
| 166 if (kIdealSplashImageSize == -1) | 168 if (g_ideal_splash_image_size == -1) |
| 167 GetHomescreenIconAndSplashImageSizes(); | 169 GetHomescreenIconAndSplashImageSizes(); |
| 168 return kIdealSplashImageSize; | 170 return g_ideal_splash_image_size; |
| 169 } | 171 } |
| 170 | 172 |
| 171 int ShortcutHelper::GetMinimumSplashImageSizeInPx() { | 173 int ShortcutHelper::GetMinimumSplashImageSizeInPx() { |
| 172 if (kMinimumSplashImageSize == -1) | 174 if (g_minimum_splash_image_size == -1) |
| 173 GetHomescreenIconAndSplashImageSizes(); | 175 GetHomescreenIconAndSplashImageSizes(); |
| 174 return kMinimumSplashImageSize; | 176 return g_minimum_splash_image_size; |
| 177 } |
| 178 |
| 179 int ShortcutHelper::GetIdealBadgeIconSizeInPx() { |
| 180 if (g_ideal_badge_icon_size == -1) |
| 181 GetHomescreenIconAndSplashImageSizes(); |
| 182 return g_ideal_badge_icon_size; |
| 175 } | 183 } |
| 176 | 184 |
| 177 // static | 185 // static |
| 178 void ShortcutHelper::FetchSplashScreenImage( | 186 void ShortcutHelper::FetchSplashScreenImage( |
| 179 content::WebContents* web_contents, | 187 content::WebContents* web_contents, |
| 180 const GURL& image_url, | 188 const GURL& image_url, |
| 181 const int ideal_splash_image_size_in_px, | 189 const int ideal_splash_image_size_in_px, |
| 182 const int minimum_splash_image_size_in_px, | 190 const int minimum_splash_image_size_in_px, |
| 183 const std::string& webapp_id) { | 191 const std::string& webapp_id) { |
| 184 // This is a fire and forget task. It is not vital for the splash screen image | 192 // This is a fire and forget task. It is not vital for the splash screen image |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 ScopedJavaLocalRef<jobject> java_bitmap = | 231 ScopedJavaLocalRef<jobject> java_bitmap = |
| 224 gfx::ConvertToJavaBitmap(&bitmap); | 232 gfx::ConvertToJavaBitmap(&bitmap); |
| 225 result = | 233 result = |
| 226 Java_ShortcutHelper_createHomeScreenIconFromWebIcon(env, java_bitmap); | 234 Java_ShortcutHelper_createHomeScreenIconFromWebIcon(env, java_bitmap); |
| 227 } | 235 } |
| 228 } | 236 } |
| 229 | 237 |
| 230 if (result.is_null()) { | 238 if (result.is_null()) { |
| 231 ScopedJavaLocalRef<jstring> java_url = | 239 ScopedJavaLocalRef<jstring> java_url = |
| 232 base::android::ConvertUTF8ToJavaString(env, url.spec()); | 240 base::android::ConvertUTF8ToJavaString(env, url.spec()); |
| 233 SkColor mean_color = SkColorSetRGB( | 241 SkColor mean_color = |
| 234 kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue); | 242 SkColorSetRGB(g_default_rgb_icon_value, g_default_rgb_icon_value, |
| 243 g_default_rgb_icon_value); |
| 235 | 244 |
| 236 if (!bitmap.isNull()) | 245 if (!bitmap.isNull()) |
| 237 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); | 246 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); |
| 238 | 247 |
| 239 *is_generated = true; | 248 *is_generated = true; |
| 240 result = Java_ShortcutHelper_generateHomeScreenIcon( | 249 result = Java_ShortcutHelper_generateHomeScreenIcon( |
| 241 env, java_url, SkColorGetR(mean_color), SkColorGetG(mean_color), | 250 env, java_url, SkColorGetR(mean_color), SkColorGetG(mean_color), |
| 242 SkColorGetB(mean_color)); | 251 SkColorGetB(mean_color)); |
| 243 } | 252 } |
| 244 | 253 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 DCHECK(jsplash_image_callback); | 304 DCHECK(jsplash_image_callback); |
| 296 base::Closure* splash_image_callback = | 305 base::Closure* splash_image_callback = |
| 297 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 306 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
| 298 splash_image_callback->Run(); | 307 splash_image_callback->Run(); |
| 299 delete splash_image_callback; | 308 delete splash_image_callback; |
| 300 } | 309 } |
| 301 | 310 |
| 302 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 311 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 303 return RegisterNativesImpl(env); | 312 return RegisterNativesImpl(env); |
| 304 } | 313 } |
| OLD | NEW |