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

Side by Side Diff: chrome/browser/notifications/notification_ui_manager_android.cc

Issue 1864053002: Implement Android UI of web notification inline replies Base URL: https://chromium.googlesource.com/chromium/src.git@inline_replies_ps1
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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>& v) {
Michael van Ouwerkerk 2016/04/06 13:27:35 s/v/strings/
Nina 2016/04/06 16:05:49 Copy pasting = These things happen. Fixed.
39 ScopedJavaLocalRef<jclass> string_clazz =
40 base::android::GetClass(env, "java/lang/String");
41 jobjectArray joa = env->NewObjectArray(v.size(), string_clazz.obj(), NULL);
Michael van Ouwerkerk 2016/04/06 13:27:35 nit: s/NULL/nullptr /* initialElement *//
Michael van Ouwerkerk 2016/04/06 13:27:35 nit: s/joa/array/
Nina 2016/04/06 16:05:49 Done.
42 jni_generator::CheckException(env);
Michael van Ouwerkerk 2016/04/06 13:27:35 use base::android::CheckException
Nina 2016/04/06 16:05:49 Done.
43
44 for (size_t i = 0; i < v.size(); ++i) {
45 if (v[i].is_null()) {
46 env->SetObjectArrayElement(joa, i, nullptr);
Michael van Ouwerkerk 2016/04/06 13:27:35 This is a no-op, they are all initialized with nul
Nina 2016/04/06 16:05:49 Removed.
47 } else {
48 ScopedJavaLocalRef<jstring> item =
49 ConvertUTF16ToJavaString(env, v[i].string());
Michael van Ouwerkerk 2016/04/06 13:27:35 nit: inline this in the SetObjectArrayElement call
Nina 2016/04/06 16:05:49 Done.
50 env->SetObjectArrayElement(joa, i, item.obj());
51 }
52 }
53 return ScopedJavaLocalRef<jobjectArray>(env, joa);
54 }
55
35 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps( 56 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps(
36 const std::vector<message_center::ButtonInfo>& buttons) { 57 const std::vector<message_center::ButtonInfo>& buttons) {
37 std::vector<SkBitmap> skbitmaps; 58 std::vector<SkBitmap> skbitmaps;
38 for (const message_center::ButtonInfo& button : buttons) 59 for (const message_center::ButtonInfo& button : buttons)
39 skbitmaps.push_back(button.icon.AsBitmap()); 60 skbitmaps.push_back(button.icon.AsBitmap());
40 61
41 JNIEnv* env = AttachCurrentThread(); 62 JNIEnv* env = AttachCurrentThread();
42 ScopedJavaLocalRef<jclass> clazz = 63 ScopedJavaLocalRef<jclass> clazz =
43 base::android::GetClass(env, "android/graphics/Bitmap"); 64 base::android::GetClass(env, "android/graphics/Bitmap");
44 jobjectArray array = env->NewObjectArray(skbitmaps.size(), clazz.obj(), 65 jobjectArray array = env->NewObjectArray(skbitmaps.size(), clazz.obj(),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ScopedJavaLocalRef<jobject> notification_icon; 184 ScopedJavaLocalRef<jobject> notification_icon;
164 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap(); 185 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap();
165 if (!notification_icon_bitmap.drawsNothing()) 186 if (!notification_icon_bitmap.drawsNothing())
166 notification_icon = gfx::ConvertToJavaBitmap(&notification_icon_bitmap); 187 notification_icon = gfx::ConvertToJavaBitmap(&notification_icon_bitmap);
167 188
168 ScopedJavaLocalRef<jobject> badge; 189 ScopedJavaLocalRef<jobject> badge;
169 SkBitmap badge_bitmap = notification.small_image().AsBitmap(); 190 SkBitmap badge_bitmap = notification.small_image().AsBitmap();
170 if (!badge_bitmap.drawsNothing()) 191 if (!badge_bitmap.drawsNothing())
171 badge = gfx::ConvertToJavaBitmap(&badge_bitmap); 192 badge = gfx::ConvertToJavaBitmap(&badge_bitmap);
172 193
194 std::vector<int> action_types_vector;
173 std::vector<base::string16> action_titles_vector; 195 std::vector<base::string16> action_titles_vector;
174 for (const message_center::ButtonInfo& button : notification.buttons()) 196 std::vector<base::NullableString16> action_placeholders_vector;
197 for (const message_center::ButtonInfo& button : notification.buttons()) {
198 action_types_vector.push_back(static_cast<int>(button.type));
175 action_titles_vector.push_back(button.title); 199 action_titles_vector.push_back(button.title);
200 action_placeholders_vector.push_back(button.placeholder);
201 }
202
203 ScopedJavaLocalRef<jintArray> action_types =
204 base::android::ToJavaIntArray(env, action_types_vector);
205
176 ScopedJavaLocalRef<jobjectArray> action_titles = 206 ScopedJavaLocalRef<jobjectArray> action_titles =
177 base::android::ToJavaArrayOfStrings(env, action_titles_vector); 207 base::android::ToJavaArrayOfStrings(env, action_titles_vector);
178 208
179 ScopedJavaLocalRef<jobjectArray> action_icons = 209 ScopedJavaLocalRef<jobjectArray> action_icons =
180 ConvertToJavaBitmaps(notification.buttons()); 210 ConvertToJavaBitmaps(notification.buttons());
181 211
212 ScopedJavaLocalRef<jobjectArray> action_placeholders =
213 ToJavaArrayOfNullableStrings(env, action_placeholders_vector);
214
182 ScopedJavaLocalRef<jintArray> vibration_pattern = 215 ScopedJavaLocalRef<jintArray> vibration_pattern =
183 base::android::ToJavaIntArray(env, notification.vibration_pattern()); 216 base::android::ToJavaIntArray(env, notification.vibration_pattern());
184 217
185 ScopedJavaLocalRef<jstring> profile_id = 218 ScopedJavaLocalRef<jstring> profile_id =
186 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value()); 219 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value());
187 220
188 Java_NotificationUIManager_displayNotification( 221 Java_NotificationUIManager_displayNotification(
189 env, java_object_.obj(), persistent_notification_id, origin.obj(), 222 env, java_object_.obj(), persistent_notification_id, origin.obj(),
190 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(), 223 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(),
191 body.obj(), notification_icon.obj(), badge.obj(), vibration_pattern.obj(), 224 body.obj(), notification_icon.obj(), badge.obj(), vibration_pattern.obj(),
192 notification.timestamp().ToJavaTime(), notification.renotify(), 225 notification.timestamp().ToJavaTime(), notification.renotify(),
193 notification.silent(), action_titles.obj(), action_icons.obj()); 226 notification.silent(), action_types.obj(), action_titles.obj(),
227 action_icons.obj(), action_placeholders.obj());
194 228
195 regenerated_notification_infos_[persistent_notification_id] = 229 regenerated_notification_infos_[persistent_notification_id] =
196 std::make_pair(origin_url.spec(), notification.tag()); 230 std::make_pair(origin_url.spec(), notification.tag());
197 231
198 notification.delegate()->Display(); 232 notification.delegate()->Display();
199 } 233 }
200 234
201 bool NotificationUIManagerAndroid::Update(const Notification& notification, 235 bool NotificationUIManagerAndroid::Update(const Notification& notification,
202 Profile* profile) { 236 Profile* profile) {
203 NOTREACHED(); 237 NOTREACHED();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 return false; 303 return false;
270 } 304 }
271 305
272 void NotificationUIManagerAndroid::CancelAll() { 306 void NotificationUIManagerAndroid::CancelAll() {
273 NOTREACHED(); 307 NOTREACHED();
274 } 308 }
275 309
276 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) { 310 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) {
277 return RegisterNativesImpl(env); 311 return RegisterNativesImpl(env);
278 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698