OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/notifications/notification_ui_manager_android.h" | 5 #include "chrome/browser/notifications/notification_ui_manager_android.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> |
8 | 9 |
9 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
10 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 18 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
18 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 19 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "content/public/common/persistent_notification_status.h" | 21 #include "content/public/common/persistent_notification_status.h" |
21 #include "content/public/common/platform_notification_data.h" | 22 #include "content/public/common/platform_notification_data.h" |
22 #include "jni/NotificationUIManager_jni.h" | 23 #include "jni/NotificationUIManager_jni.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" |
23 #include "ui/gfx/android/java_bitmap.h" | 25 #include "ui/gfx/android/java_bitmap.h" |
24 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
25 | 27 |
26 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
27 using base::android::ConvertJavaStringToUTF8; | 29 using base::android::ConvertJavaStringToUTF8; |
28 using base::android::ConvertUTF16ToJavaString; | 30 using base::android::ConvertUTF16ToJavaString; |
29 using base::android::ConvertUTF8ToJavaString; | 31 using base::android::ConvertUTF8ToJavaString; |
30 | 32 |
| 33 namespace { |
| 34 |
| 35 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps( |
| 36 const std::vector<message_center::ButtonInfo>& buttons) { |
| 37 std::vector<SkBitmap> skbitmaps; |
| 38 for (const message_center::ButtonInfo& button : buttons) |
| 39 skbitmaps.push_back(button.icon.AsBitmap()); |
| 40 |
| 41 JNIEnv* env = AttachCurrentThread(); |
| 42 ScopedJavaLocalRef<jclass> clazz = |
| 43 base::android::GetClass(env, "android/graphics/Bitmap"); |
| 44 jobjectArray array = env->NewObjectArray(skbitmaps.size(), clazz.obj(), |
| 45 nullptr /* initialElement */); |
| 46 base::android::CheckException(env); |
| 47 |
| 48 for (size_t i = 0; i < skbitmaps.size(); ++i) { |
| 49 if (!skbitmaps[i].drawsNothing()) { |
| 50 env->SetObjectArrayElement( |
| 51 array, i, gfx::ConvertToJavaBitmap(&(skbitmaps[i])).obj()); |
| 52 } |
| 53 } |
| 54 |
| 55 return ScopedJavaLocalRef<jobjectArray>(env, array); |
| 56 } |
| 57 |
| 58 } // namespace |
| 59 |
31 // Called by the Java side when a notification event has been received, but the | 60 // Called by the Java side when a notification event has been received, but the |
32 // NotificationUIManager has not been initialized yet. Enforce initialization of | 61 // NotificationUIManager has not been initialized yet. Enforce initialization of |
33 // the class. | 62 // the class. |
34 static void InitializeNotificationUIManager(JNIEnv* env, | 63 static void InitializeNotificationUIManager(JNIEnv* env, |
35 const JavaParamRef<jclass>& clazz) { | 64 const JavaParamRef<jclass>& clazz) { |
36 g_browser_process->notification_ui_manager(); | 65 g_browser_process->notification_ui_manager(); |
37 } | 66 } |
38 | 67 |
39 // static | 68 // static |
40 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { | 69 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 153 |
125 ScopedJavaLocalRef<jstring> origin = ConvertUTF8ToJavaString( | 154 ScopedJavaLocalRef<jstring> origin = ConvertUTF8ToJavaString( |
126 env, origin_url.spec()); | 155 env, origin_url.spec()); |
127 ScopedJavaLocalRef<jstring> tag = | 156 ScopedJavaLocalRef<jstring> tag = |
128 ConvertUTF8ToJavaString(env, notification.tag()); | 157 ConvertUTF8ToJavaString(env, notification.tag()); |
129 ScopedJavaLocalRef<jstring> title = ConvertUTF16ToJavaString( | 158 ScopedJavaLocalRef<jstring> title = ConvertUTF16ToJavaString( |
130 env, notification.title()); | 159 env, notification.title()); |
131 ScopedJavaLocalRef<jstring> body = ConvertUTF16ToJavaString( | 160 ScopedJavaLocalRef<jstring> body = ConvertUTF16ToJavaString( |
132 env, notification.message()); | 161 env, notification.message()); |
133 | 162 |
134 ScopedJavaLocalRef<jobject> icon; | 163 ScopedJavaLocalRef<jobject> notification_icon; |
135 | 164 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap(); |
136 SkBitmap icon_bitmap = notification.icon().AsBitmap(); | 165 if (!notification_icon_bitmap.drawsNothing()) |
137 if (!icon_bitmap.isNull()) | 166 notification_icon = gfx::ConvertToJavaBitmap(¬ification_icon_bitmap); |
138 icon = gfx::ConvertToJavaBitmap(&icon_bitmap); | |
139 | 167 |
140 std::vector<base::string16> action_titles_vector; | 168 std::vector<base::string16> action_titles_vector; |
141 for (const message_center::ButtonInfo& button : notification.buttons()) | 169 for (const message_center::ButtonInfo& button : notification.buttons()) |
142 action_titles_vector.push_back(button.title); | 170 action_titles_vector.push_back(button.title); |
143 ScopedJavaLocalRef<jobjectArray> action_titles = | 171 ScopedJavaLocalRef<jobjectArray> action_titles = |
144 base::android::ToJavaArrayOfStrings(env, action_titles_vector); | 172 base::android::ToJavaArrayOfStrings(env, action_titles_vector); |
145 | 173 |
| 174 ScopedJavaLocalRef<jobjectArray> action_icons = |
| 175 ConvertToJavaBitmaps(notification.buttons()); |
| 176 |
146 ScopedJavaLocalRef<jintArray> vibration_pattern = | 177 ScopedJavaLocalRef<jintArray> vibration_pattern = |
147 base::android::ToJavaIntArray(env, notification.vibration_pattern()); | 178 base::android::ToJavaIntArray(env, notification.vibration_pattern()); |
148 | 179 |
149 ScopedJavaLocalRef<jstring> profile_id = | 180 ScopedJavaLocalRef<jstring> profile_id = |
150 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value()); | 181 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value()); |
151 | 182 |
152 Java_NotificationUIManager_displayNotification( | 183 Java_NotificationUIManager_displayNotification( |
153 env, java_object_.obj(), persistent_notification_id, origin.obj(), | 184 env, java_object_.obj(), persistent_notification_id, origin.obj(), |
154 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(), | 185 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(), |
155 body.obj(), icon.obj(), vibration_pattern.obj(), | 186 body.obj(), notification_icon.obj(), vibration_pattern.obj(), |
156 notification.timestamp().ToJavaTime(), notification.silent(), | 187 notification.timestamp().ToJavaTime(), notification.silent(), |
157 action_titles.obj()); | 188 action_titles.obj(), action_icons.obj()); |
158 | 189 |
159 regenerated_notification_infos_[persistent_notification_id] = | 190 regenerated_notification_infos_[persistent_notification_id] = |
160 std::make_pair(origin_url.spec(), notification.tag()); | 191 std::make_pair(origin_url.spec(), notification.tag()); |
161 | 192 |
162 notification.delegate()->Display(); | 193 notification.delegate()->Display(); |
163 } | 194 } |
164 | 195 |
165 bool NotificationUIManagerAndroid::Update(const Notification& notification, | 196 bool NotificationUIManagerAndroid::Update(const Notification& notification, |
166 Profile* profile) { | 197 Profile* profile) { |
167 NOTREACHED(); | 198 NOTREACHED(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 return false; | 264 return false; |
234 } | 265 } |
235 | 266 |
236 void NotificationUIManagerAndroid::CancelAll() { | 267 void NotificationUIManagerAndroid::CancelAll() { |
237 NOTREACHED(); | 268 NOTREACHED(); |
238 } | 269 } |
239 | 270 |
240 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) { | 271 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) { |
241 return RegisterNativesImpl(env); | 272 return RegisterNativesImpl(env); |
242 } | 273 } |
OLD | NEW |