| 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 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
| 11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/strings/nullable_string16.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
| 18 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 19 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 19 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 20 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "content/public/common/persistent_notification_status.h" | 22 #include "content/public/common/persistent_notification_status.h" |
| 22 #include "content/public/common/platform_notification_data.h" | 23 #include "content/public/common/platform_notification_data.h" |
| 23 #include "jni/NotificationUIManager_jni.h" | 24 #include "jni/NotificationUIManager_jni.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "ui/gfx/android/java_bitmap.h" | 26 #include "ui/gfx/android/java_bitmap.h" |
| 26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 27 | 28 |
| 28 using base::android::AttachCurrentThread; | 29 using base::android::AttachCurrentThread; |
| 29 using base::android::ConvertJavaStringToUTF8; | 30 using base::android::ConvertJavaStringToUTF8; |
| 30 using base::android::ConvertUTF16ToJavaString; | 31 using base::android::ConvertUTF16ToJavaString; |
| 31 using base::android::ConvertUTF8ToJavaString; | 32 using base::android::ConvertUTF8ToJavaString; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 36 ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfNullableStrings( |
| 37 JNIEnv* env, |
| 38 const std::vector<base::NullableString16>& strings) { |
| 39 ScopedJavaLocalRef<jclass> string_clazz = |
| 40 base::android::GetClass(env, "java/lang/String"); |
| 41 jobjectArray array = |
| 42 env->NewObjectArray(strings.size(), string_clazz.obj(), nullptr); |
| 43 base::android::CheckException(env); |
| 44 |
| 45 for (size_t i = 0; i < strings.size(); ++i) { |
| 46 if (strings[i].is_null()) |
| 47 continue; |
| 48 env->SetObjectArrayElement( |
| 49 array, i, ConvertUTF16ToJavaString(env, strings[i].string()).obj()); |
| 50 } |
| 51 return ScopedJavaLocalRef<jobjectArray>(env, array); |
| 52 } |
| 53 |
| 35 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps( | 54 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps( |
| 36 const std::vector<message_center::ButtonInfo>& buttons) { | 55 const std::vector<message_center::ButtonInfo>& buttons) { |
| 37 std::vector<SkBitmap> skbitmaps; | 56 std::vector<SkBitmap> skbitmaps; |
| 38 for (const message_center::ButtonInfo& button : buttons) | 57 for (const message_center::ButtonInfo& button : buttons) |
| 39 skbitmaps.push_back(button.icon.AsBitmap()); | 58 skbitmaps.push_back(button.icon.AsBitmap()); |
| 40 | 59 |
| 41 JNIEnv* env = AttachCurrentThread(); | 60 JNIEnv* env = AttachCurrentThread(); |
| 42 ScopedJavaLocalRef<jclass> clazz = | 61 ScopedJavaLocalRef<jclass> clazz = |
| 43 base::android::GetClass(env, "android/graphics/Bitmap"); | 62 base::android::GetClass(env, "android/graphics/Bitmap"); |
| 44 jobjectArray array = env->NewObjectArray(skbitmaps.size(), clazz.obj(), | 63 jobjectArray array = env->NewObjectArray(skbitmaps.size(), clazz.obj(), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 ScopedJavaLocalRef<jobject> notification_icon; | 182 ScopedJavaLocalRef<jobject> notification_icon; |
| 164 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap(); | 183 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap(); |
| 165 if (!notification_icon_bitmap.drawsNothing()) | 184 if (!notification_icon_bitmap.drawsNothing()) |
| 166 notification_icon = gfx::ConvertToJavaBitmap(¬ification_icon_bitmap); | 185 notification_icon = gfx::ConvertToJavaBitmap(¬ification_icon_bitmap); |
| 167 | 186 |
| 168 ScopedJavaLocalRef<jobject> badge; | 187 ScopedJavaLocalRef<jobject> badge; |
| 169 SkBitmap badge_bitmap = notification.small_image().AsBitmap(); | 188 SkBitmap badge_bitmap = notification.small_image().AsBitmap(); |
| 170 if (!badge_bitmap.drawsNothing()) | 189 if (!badge_bitmap.drawsNothing()) |
| 171 badge = gfx::ConvertToJavaBitmap(&badge_bitmap); | 190 badge = gfx::ConvertToJavaBitmap(&badge_bitmap); |
| 172 | 191 |
| 192 std::vector<int> action_types_vector; |
| 173 std::vector<base::string16> action_titles_vector; | 193 std::vector<base::string16> action_titles_vector; |
| 174 for (const message_center::ButtonInfo& button : notification.buttons()) | 194 std::vector<base::NullableString16> action_placeholders_vector; |
| 195 for (const message_center::ButtonInfo& button : notification.buttons()) { |
| 196 action_types_vector.push_back(static_cast<int>(button.type)); |
| 175 action_titles_vector.push_back(button.title); | 197 action_titles_vector.push_back(button.title); |
| 198 action_placeholders_vector.push_back(button.placeholder); |
| 199 } |
| 200 |
| 201 ScopedJavaLocalRef<jintArray> action_types = |
| 202 base::android::ToJavaIntArray(env, action_types_vector); |
| 203 |
| 176 ScopedJavaLocalRef<jobjectArray> action_titles = | 204 ScopedJavaLocalRef<jobjectArray> action_titles = |
| 177 base::android::ToJavaArrayOfStrings(env, action_titles_vector); | 205 base::android::ToJavaArrayOfStrings(env, action_titles_vector); |
| 178 | 206 |
| 179 ScopedJavaLocalRef<jobjectArray> action_icons = | 207 ScopedJavaLocalRef<jobjectArray> action_icons = |
| 180 ConvertToJavaBitmaps(notification.buttons()); | 208 ConvertToJavaBitmaps(notification.buttons()); |
| 181 | 209 |
| 210 ScopedJavaLocalRef<jobjectArray> action_placeholders = |
| 211 ToJavaArrayOfNullableStrings(env, action_placeholders_vector); |
| 212 |
| 182 ScopedJavaLocalRef<jintArray> vibration_pattern = | 213 ScopedJavaLocalRef<jintArray> vibration_pattern = |
| 183 base::android::ToJavaIntArray(env, notification.vibration_pattern()); | 214 base::android::ToJavaIntArray(env, notification.vibration_pattern()); |
| 184 | 215 |
| 185 ScopedJavaLocalRef<jstring> profile_id = | 216 ScopedJavaLocalRef<jstring> profile_id = |
| 186 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value()); | 217 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value()); |
| 187 | 218 |
| 188 Java_NotificationUIManager_displayNotification( | 219 Java_NotificationUIManager_displayNotification( |
| 189 env, java_object_.obj(), persistent_notification_id, origin.obj(), | 220 env, java_object_.obj(), persistent_notification_id, origin.obj(), |
| 190 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(), | 221 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(), |
| 191 body.obj(), notification_icon.obj(), badge.obj(), vibration_pattern.obj(), | 222 body.obj(), notification_icon.obj(), badge.obj(), vibration_pattern.obj(), |
| 192 notification.timestamp().ToJavaTime(), notification.renotify(), | 223 notification.timestamp().ToJavaTime(), notification.renotify(), |
| 193 notification.silent(), action_titles.obj(), action_icons.obj()); | 224 notification.silent(), action_types.obj(), action_titles.obj(), |
| 225 action_icons.obj(), action_placeholders.obj()); |
| 194 | 226 |
| 195 regenerated_notification_infos_[persistent_notification_id] = | 227 regenerated_notification_infos_[persistent_notification_id] = |
| 196 std::make_pair(origin_url.spec(), notification.tag()); | 228 std::make_pair(origin_url.spec(), notification.tag()); |
| 197 | 229 |
| 198 notification.delegate()->Display(); | 230 notification.delegate()->Display(); |
| 199 } | 231 } |
| 200 | 232 |
| 201 bool NotificationUIManagerAndroid::Update(const Notification& notification, | 233 bool NotificationUIManagerAndroid::Update(const Notification& notification, |
| 202 Profile* profile) { | 234 Profile* profile) { |
| 203 NOTREACHED(); | 235 NOTREACHED(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return false; | 301 return false; |
| 270 } | 302 } |
| 271 | 303 |
| 272 void NotificationUIManagerAndroid::CancelAll() { | 304 void NotificationUIManagerAndroid::CancelAll() { |
| 273 NOTREACHED(); | 305 NOTREACHED(); |
| 274 } | 306 } |
| 275 | 307 |
| 276 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) { | 308 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) { |
| 277 return RegisterNativesImpl(env); | 309 return RegisterNativesImpl(env); |
| 278 } | 310 } |
| OLD | NEW |