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

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

Issue 942103003: Handle notification preferences intent from gear icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass tag. Created 5 years, 10 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 "base/android/jni_array.h" 7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return; 224 return;
225 225
226 ProfileNotification* profile_notification = 226 ProfileNotification* profile_notification =
227 new ProfileNotification(profile, notification); 227 new ProfileNotification(profile, notification);
228 228
229 // Takes ownership of |profile_notification|. 229 // Takes ownership of |profile_notification|.
230 AddProfileNotification(profile_notification); 230 AddProfileNotification(profile_notification);
231 231
232 JNIEnv* env = AttachCurrentThread(); 232 JNIEnv* env = AttachCurrentThread();
233 233
234 ScopedJavaLocalRef<jstring> tag = ConvertUTF16ToJavaString(
235 env, profile_notification->notification().replace_id());
234 ScopedJavaLocalRef<jstring> id = ConvertUTF8ToJavaString( 236 ScopedJavaLocalRef<jstring> id = ConvertUTF8ToJavaString(
235 env, profile_notification->notification().id()); 237 env, profile_notification->notification().id());
236 ScopedJavaLocalRef<jstring> title = ConvertUTF16ToJavaString( 238 ScopedJavaLocalRef<jstring> title = ConvertUTF16ToJavaString(
237 env, notification.title()); 239 env, notification.title());
238 ScopedJavaLocalRef<jstring> body = ConvertUTF16ToJavaString( 240 ScopedJavaLocalRef<jstring> body = ConvertUTF16ToJavaString(
239 env, notification.message()); 241 env, notification.message());
240 ScopedJavaLocalRef<jstring> origin = ConvertUTF8ToJavaString( 242 ScopedJavaLocalRef<jstring> origin = ConvertUTF8ToJavaString(
241 env, notification.origin_url().GetOrigin().spec()); 243 env, notification.origin_url().GetOrigin().spec());
242 244
243 ScopedJavaLocalRef<jobject> icon; 245 ScopedJavaLocalRef<jobject> icon;
(...skipping 16 matching lines...) Expand all
260 "Unable to serialize the notification, payload too large (max 1MB)."; 262 "Unable to serialize the notification, payload too large (max 1MB).";
261 RemoveProfileNotification(profile_notification); 263 RemoveProfileNotification(profile_notification);
262 return; 264 return;
263 } 265 }
264 266
265 notification_data = base::android::ToJavaByteArray( 267 notification_data = base::android::ToJavaByteArray(
266 env, static_cast<const uint8*>(pickle->data()), pickle->size()); 268 env, static_cast<const uint8*>(pickle->data()), pickle->size());
267 } 269 }
268 270
269 int platform_id = Java_NotificationUIManager_displayNotification( 271 int platform_id = Java_NotificationUIManager_displayNotification(
270 env, java_object_.obj(), id.obj(), title.obj(), body.obj(), icon.obj(), 272 env, java_object_.obj(), tag.obj(), id.obj(), title.obj(), body.obj(),
271 origin.obj(), notification_data.obj()); 273 icon.obj(), origin.obj(), notification_data.obj());
272 274
273 std::string notification_id = profile_notification->notification().id(); 275 std::string notification_id = profile_notification->notification().id();
274 platform_notifications_[notification_id] = platform_id; 276 platform_notifications_[notification_id] = platform_id;
275 277
276 notification.delegate()->Display(); 278 notification.delegate()->Display();
277 } 279 }
278 280
279 bool NotificationUIManagerAndroid::Update(const Notification& notification, 281 bool NotificationUIManagerAndroid::Update(const Notification& notification,
280 Profile* profile) { 282 Profile* profile) {
281 const base::string16& replace_id = notification.replace_id(); 283 const base::string16& replace_id = notification.replace_id();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 408
407 void NotificationUIManagerAndroid::PlatformCloseNotification( 409 void NotificationUIManagerAndroid::PlatformCloseNotification(
408 const std::string& notification_id) { 410 const std::string& notification_id) {
409 auto iterator = platform_notifications_.find(notification_id); 411 auto iterator = platform_notifications_.find(notification_id);
410 if (iterator == platform_notifications_.end()) 412 if (iterator == platform_notifications_.end())
411 return; 413 return;
412 414
413 int platform_id = iterator->second; 415 int platform_id = iterator->second;
414 platform_notifications_.erase(notification_id); 416 platform_notifications_.erase(notification_id);
415 417
416 Java_NotificationUIManager_closeNotification(AttachCurrentThread(), 418 ProfileNotification* profile_notification =
417 java_object_.obj(), 419 FindProfileNotification(notification_id);
418 platform_id); 420 if (!profile_notification)
421 return;
Peter Beverloo 2015/02/24 17:48:03 We don't add the notification to profile_notificat
Michael van Ouwerkerk 2015/02/25 18:12:45 Done.
422
423 JNIEnv* env = AttachCurrentThread();
424
425 ScopedJavaLocalRef<jstring> tag = ConvertUTF16ToJavaString(
426 env, profile_notification->notification().replace_id());
427 ScopedJavaLocalRef<jstring> origin = ConvertUTF8ToJavaString(
428 env, profile_notification->notification().origin_url().spec());
429
430 Java_NotificationUIManager_closeNotification(
431 env, java_object_.obj(), tag.obj(), platform_id, origin.obj());
419 } 432 }
420 433
421 void NotificationUIManagerAndroid::AddProfileNotification( 434 void NotificationUIManagerAndroid::AddProfileNotification(
422 ProfileNotification* profile_notification) { 435 ProfileNotification* profile_notification) {
423 std::string id = profile_notification->notification().id(); 436 std::string id = profile_notification->notification().id();
424 437
425 // Notification ids should be unique. 438 // Notification ids should be unique.
426 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); 439 DCHECK(profile_notifications_.find(id) == profile_notifications_.end());
427 440
428 profile_notifications_[id] = profile_notification; 441 profile_notifications_[id] = profile_notification;
(...skipping 10 matching lines...) Expand all
439 452
440 ProfileNotification* NotificationUIManagerAndroid::FindProfileNotification( 453 ProfileNotification* NotificationUIManagerAndroid::FindProfileNotification(
441 const std::string& id) const { 454 const std::string& id) const {
442 auto iter = profile_notifications_.find(id); 455 auto iter = profile_notifications_.find(id);
443 if (iter == profile_notifications_.end()) 456 if (iter == profile_notifications_.end())
444 return nullptr; 457 return nullptr;
445 458
446 return iter->second; 459 return iter->second;
447 } 460 }
448 461
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698