Chromium Code Reviews| Index: chrome/browser/android/shortcut_helper.cc |
| diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc |
| index 7ab56020584b889955e925293c0723aaf604679e..4e358b4b11ab439325b44846258cf890e7e0b073 100644 |
| --- a/chrome/browser/android/shortcut_helper.cc |
| +++ b/chrome/browser/android/shortcut_helper.cc |
| @@ -20,7 +20,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" |
| @@ -37,6 +39,16 @@ static int kMinimumSplashImageSize = -1; |
| static int kDefaultRGBIconValue = 145; |
| +// The seed to use for the murmur2 hash. |
| +const uint32_t kMurmur2HashSeed = 0; |
|
dominickn
2016/08/15 05:27:35
Should this be uint64_t? I guess the seed is 0 so
|
| + |
| +// 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() { |
| @@ -202,6 +214,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, |
| @@ -293,6 +323,29 @@ GURL ShortcutHelper::GetScopeFromURL(const GURL& url) { |
| return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url)); |
| } |
| +/** |
| + * Called by Java to fetch the image at |java_icon_url| and scale it so that it |
| + * can be used on the homscreen. |
|
dominickn
2016/08/15 05:27:35
Nit: Use //, not Java-style comment strings
Nit:
|
| + */ |
| +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. |