Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2606)

Unified Diff: chrome/browser/android/shortcut_helper.cc

Issue 1420743002: Web app: set a flag on the Intent if the icon was generated by Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@splashscreen-even-more-tests
Patch Set: review comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/shortcut_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c39462a32ef556f9aa02ce89660df20018ab7429 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.is_icon_generated);
}
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* is_generated) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> result;
+ *is_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);
+
+ *is_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);
}
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/shortcut_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698