OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/large_icon_bridge.h" | 5 #include "chrome/browser/android/large_icon_bridge.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_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/gfx/codec/png_codec.h" | 23 #include "ui/gfx/codec/png_codec.h" |
24 | 24 |
25 using base::android::JavaParamRef; | 25 using base::android::JavaParamRef; |
26 using base::android::ScopedJavaGlobalRef; | 26 using base::android::ScopedJavaGlobalRef; |
27 using base::android::ScopedJavaLocalRef; | 27 using base::android::ScopedJavaLocalRef; |
28 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
29 using base::android::ConvertJavaStringToUTF16; | 29 using base::android::ConvertJavaStringToUTF16; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const SkColor kDefaultBackgroundColor = SkColorSetRGB(0x78, 0x78, 0x78); | |
34 | |
35 void OnLargeIconAvailable( | 33 void OnLargeIconAvailable( |
36 ScopedJavaGlobalRef<jobject>* j_callback, | 34 ScopedJavaGlobalRef<jobject>* j_callback, |
37 const favicon_base::LargeIconResult& result) { | 35 const favicon_base::LargeIconResult& result) { |
38 JNIEnv* env = AttachCurrentThread(); | 36 JNIEnv* env = AttachCurrentThread(); |
39 | 37 |
40 // Convert the result to a Java Bitmap. | 38 // Convert the result to a Java Bitmap. |
41 SkBitmap bitmap; | 39 SkBitmap bitmap; |
42 ScopedJavaLocalRef<jobject> j_bitmap; | 40 ScopedJavaLocalRef<jobject> j_bitmap; |
43 if (result.bitmap.is_valid()) { | 41 if (result.bitmap.is_valid()) { |
44 gfx::PNGCodec::Decode(result.bitmap.bitmap_data->front(), | 42 gfx::PNGCodec::Decode(result.bitmap.bitmap_data->front(), |
45 result.bitmap.bitmap_data->size(), | 43 result.bitmap.bitmap_data->size(), |
46 &bitmap); | 44 &bitmap); |
47 if (!bitmap.isNull()) | 45 if (!bitmap.isNull()) |
48 j_bitmap = gfx::ConvertToJavaBitmap(&bitmap); | 46 j_bitmap = gfx::ConvertToJavaBitmap(&bitmap); |
49 } | 47 } |
50 | 48 |
51 jint background_color = kDefaultBackgroundColor; | 49 favicon_base::FallbackIconStyle fallback; |
52 if (result.fallback_icon_style) | 50 if (result.fallback_icon_style) |
53 background_color = result.fallback_icon_style->background_color; | 51 fallback = *result.fallback_icon_style; |
54 | 52 |
55 Java_LargeIconCallback_onLargeIconAvailable(env, j_callback->obj(), j_bitmap, | 53 Java_LargeIconCallback_onLargeIconAvailable( |
56 background_color); | 54 env, j_callback->obj(), j_bitmap, fallback.background_color, |
| 55 fallback.is_default_background_color); |
57 } | 56 } |
58 | 57 |
59 } // namespace | 58 } // namespace |
60 | 59 |
61 static jlong Init(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 60 static jlong Init(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
62 return reinterpret_cast<intptr_t>(new LargeIconBridge()); | 61 return reinterpret_cast<intptr_t>(new LargeIconBridge()); |
63 } | 62 } |
64 | 63 |
65 LargeIconBridge::LargeIconBridge() { | 64 LargeIconBridge::LargeIconBridge() { |
66 } | 65 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 callback_runner, | 101 callback_runner, |
103 &cancelable_task_tracker_); | 102 &cancelable_task_tracker_); |
104 | 103 |
105 return true; | 104 return true; |
106 } | 105 } |
107 | 106 |
108 // static | 107 // static |
109 bool LargeIconBridge::RegisterLargeIconBridge(JNIEnv* env) { | 108 bool LargeIconBridge::RegisterLargeIconBridge(JNIEnv* env) { |
110 return RegisterNativesImpl(env); | 109 return RegisterNativesImpl(env); |
111 } | 110 } |
OLD | NEW |