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

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

Issue 2206493002: Update WebAPK if homescreen icon changed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_updater_images0' into webapk_updater_images2 Created 4 years, 4 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
Index: chrome/browser/android/shortcut_helper.cc
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc
index 7efff3a02ecbed13dbdc82ed3021318b38e59a08..9f6ddddc807d3143db0570740099b9540f070ef5 100644
--- a/chrome/browser/android/shortcut_helper.cc
+++ b/chrome/browser/android/shortcut_helper.cc
@@ -19,7 +19,9 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "jni/ShortcutHelper_jni.h"
+#include "third_party/smhasher/src/MurmurHash2.h"
#include "ui/gfx/android/java_bitmap.h"
+#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/color_analysis.h"
#include "url/gurl.h"
@@ -34,6 +36,16 @@ static int kMinimumSplashImageSize = -1;
static int kDefaultRGBIconValue = 145;
+// The seed to use for the murmur2 hash.
+const uint32_t kMurmur2HashSeed = 0;
+
+// Computes a murmur2 hash of |bitmap|'s PNG encoded bytes.
+uint64_t ComputeBitmapHash(const SkBitmap& bitmap) {
+ std::vector<unsigned char> png_bytes;
+ gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_bytes);
+ return MurmurHash64B(&png_bytes.front(), png_bytes.size(), kMurmur2HashSeed);
+}
+
// Retrieves and caches the ideal and minimum sizes of the Home screen icon
// and the splash screen image.
void GetHomescreenIconAndSplashImageSizes() {
@@ -217,6 +229,24 @@ int ShortcutHelper::GetMinimumSplashImageSizeInDp() {
}
// static
+void ShortcutHelper::OnFetchedHomescreenImage(
+ const base::android::ScopedJavaGlobalRef<jobject> java_callback,
+ const SkBitmap& image) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ ScopedJavaLocalRef<jobject> java_bitmap;
+ uint64_t murmur2_hash = 0;
+ if (image.getSize()) {
+ java_bitmap = gfx::ConvertToJavaBitmap(&image);
+ // TODO(pkotwicz): Get hash of untransformed icon's bytes (with no
+ // encoding/decoding).
+ murmur2_hash = ComputeBitmapHash(image);
+ }
+ Java_ShortcutHelper_onFetchedHomescreenImage(
+ env, java_bitmap.obj(), murmur2_hash, java_callback.obj());
+}
+
+// static
void ShortcutHelper::FetchSplashScreenImage(
content::WebContents* web_contents,
const GURL& image_url,
@@ -296,6 +326,29 @@ bool ShortcutHelper::IsWebApkInstalled(const GURL& url) {
return Java_ShortcutHelper_isWebApkInstalled(env, java_url.obj());
}
+/**
+ * Called by Java to fetch the image at |java_icon_url| and scale it so that it
+ * can be used on the homscreen.
+ */
+void FetchHomescreenImage(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jobject>& java_web_contents,
+ const JavaParamRef<jstring>& java_image_url,
+ const JavaParamRef<jobject>& java_callback) {
+ content::WebContents* web_contents =
+ content::WebContents::FromJavaWebContents(java_web_contents);
+ GURL image_url = GURL(ConvertJavaStringToUTF8(env, java_image_url));
+ base::android::ScopedJavaGlobalRef<jobject> java_global_callback(
+ env, java_callback);
+
+ ManifestIconDownloader::Download(
+ web_contents, image_url, ShortcutHelper::GetIdealHomescreenIconSizeInDp(),
+ ShortcutHelper::GetMinimumHomescreenIconSizeInDp(),
+ base::Bind(&ShortcutHelper::OnFetchedHomescreenImage,
+ java_global_callback));
+}
+
// Callback used by Java when the shortcut has been created.
// |splash_image_callback| is a pointer to a base::Closure allocated in
// AddShortcutInBackgroundWithSkBitmap, so reinterpret_cast it back and run it.

Powered by Google App Engine
This is Rietveld 408576698