| 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 | 8 |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 int64 service_worker_registration_id) { | 52 int64 service_worker_registration_id) { |
| 53 scoped_ptr<Pickle> pickle(new Pickle); | 53 scoped_ptr<Pickle> pickle(new Pickle); |
| 54 | 54 |
| 55 // content::PlatformNotificationData | 55 // content::PlatformNotificationData |
| 56 pickle->WriteString16(notification_data.title); | 56 pickle->WriteString16(notification_data.title); |
| 57 pickle->WriteInt(static_cast<int>(notification_data.direction)); | 57 pickle->WriteInt(static_cast<int>(notification_data.direction)); |
| 58 pickle->WriteString(notification_data.lang); | 58 pickle->WriteString(notification_data.lang); |
| 59 pickle->WriteString16(notification_data.body); | 59 pickle->WriteString16(notification_data.body); |
| 60 pickle->WriteString16(notification_data.tag); | 60 pickle->WriteString16(notification_data.tag); |
| 61 pickle->WriteString(notification_data.icon.spec()); | 61 pickle->WriteString(notification_data.icon.spec()); |
| 62 pickle->WriteBool(notification_data.silent); |
| 62 | 63 |
| 63 // The origin which is displaying the notification. | 64 // The origin which is displaying the notification. |
| 64 pickle->WriteString(origin.spec()); | 65 pickle->WriteString(origin.spec()); |
| 65 | 66 |
| 66 // The Service Worker registration this notification is associated with. | 67 // The Service Worker registration this notification is associated with. |
| 67 pickle->WriteInt64(service_worker_registration_id); | 68 pickle->WriteInt64(service_worker_registration_id); |
| 68 | 69 |
| 69 if (pickle->size() > kMaximumSerializedNotificationSizeBytes) | 70 if (pickle->size() > kMaximumSerializedNotificationSizeBytes) |
| 70 return nullptr; | 71 return nullptr; |
| 71 | 72 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 | 83 |
| 83 std::string icon_url, origin_url; | 84 std::string icon_url, origin_url; |
| 84 int direction_value; | 85 int direction_value; |
| 85 | 86 |
| 86 // Unpack content::PlatformNotificationData. | 87 // Unpack content::PlatformNotificationData. |
| 87 if (!iterator.ReadString16(¬ification_data->title) || | 88 if (!iterator.ReadString16(¬ification_data->title) || |
| 88 !iterator.ReadInt(&direction_value) || | 89 !iterator.ReadInt(&direction_value) || |
| 89 !iterator.ReadString(¬ification_data->lang) || | 90 !iterator.ReadString(¬ification_data->lang) || |
| 90 !iterator.ReadString16(¬ification_data->body) || | 91 !iterator.ReadString16(¬ification_data->body) || |
| 91 !iterator.ReadString16(¬ification_data->tag) || | 92 !iterator.ReadString16(¬ification_data->tag) || |
| 92 !iterator.ReadString(&icon_url)) { | 93 !iterator.ReadString(&icon_url) || |
| 94 !iterator.ReadBool(¬ification_data->silent)) { |
| 93 return false; | 95 return false; |
| 94 } | 96 } |
| 95 | 97 |
| 96 notification_data->direction = | 98 notification_data->direction = |
| 97 static_cast<content::PlatformNotificationData::NotificationDirection>( | 99 static_cast<content::PlatformNotificationData::NotificationDirection>( |
| 98 direction_value); | 100 direction_value); |
| 99 notification_data->icon = GURL(icon_url); | 101 notification_data->icon = GURL(icon_url); |
| 100 | 102 |
| 101 // Unpack the origin which displayed this notification. | 103 // Unpack the origin which displayed this notification. |
| 102 if (!iterator.ReadString(&origin_url)) | 104 if (!iterator.ReadString(&origin_url)) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 "Unable to serialize the notification, payload too large (max 1MB)."; | 268 "Unable to serialize the notification, payload too large (max 1MB)."; |
| 267 RemoveProfileNotification(profile_notification); | 269 RemoveProfileNotification(profile_notification); |
| 268 return; | 270 return; |
| 269 } | 271 } |
| 270 | 272 |
| 271 notification_data = base::android::ToJavaByteArray( | 273 notification_data = base::android::ToJavaByteArray( |
| 272 env, static_cast<const uint8*>(pickle->data()), pickle->size()); | 274 env, static_cast<const uint8*>(pickle->data()), pickle->size()); |
| 273 } | 275 } |
| 274 | 276 |
| 275 int platform_id = Java_NotificationUIManager_displayNotification( | 277 int platform_id = Java_NotificationUIManager_displayNotification( |
| 276 env, java_object_.obj(), tag.obj(), id.obj(), title.obj(), body.obj(), | 278 env, |
| 277 icon.obj(), origin.obj(), notification_data.obj()); | 279 java_object_.obj(), |
| 280 tag.obj(), |
| 281 id.obj(), |
| 282 title.obj(), |
| 283 body.obj(), |
| 284 icon.obj(), |
| 285 origin.obj(), |
| 286 notification.silent(), |
| 287 notification_data.obj()); |
| 278 | 288 |
| 279 RegeneratedNotificationInfo notification_info( | 289 RegeneratedNotificationInfo notification_info( |
| 280 notification.replace_id(), platform_id, | 290 notification.replace_id(), platform_id, |
| 281 notification.origin_url().GetOrigin().spec()); | 291 notification.origin_url().GetOrigin().spec()); |
| 282 regenerated_notification_infos_.insert(std::make_pair( | 292 regenerated_notification_infos_.insert(std::make_pair( |
| 283 profile_notification->notification().id(), notification_info)); | 293 profile_notification->notification().id(), notification_info)); |
| 284 | 294 |
| 285 notification.delegate()->Display(); | 295 notification.delegate()->Display(); |
| 286 } | 296 } |
| 287 | 297 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 465 |
| 456 ProfileNotification* NotificationUIManagerAndroid::FindProfileNotification( | 466 ProfileNotification* NotificationUIManagerAndroid::FindProfileNotification( |
| 457 const std::string& id) const { | 467 const std::string& id) const { |
| 458 auto iter = profile_notifications_.find(id); | 468 auto iter = profile_notifications_.find(id); |
| 459 if (iter == profile_notifications_.end()) | 469 if (iter == profile_notifications_.end()) |
| 460 return nullptr; | 470 return nullptr; |
| 461 | 471 |
| 462 return iter->second; | 472 return iter->second; |
| 463 } | 473 } |
| 464 | 474 |
| OLD | NEW |