| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/notifications/notification_database_data_conversions.h
" | 5 #include "content/browser/notifications/notification_database_data_conversions.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 notification_data->silent = payload.silent(); | 66 notification_data->silent = payload.silent(); |
| 67 notification_data->require_interaction = payload.require_interaction(); | 67 notification_data->require_interaction = payload.require_interaction(); |
| 68 | 68 |
| 69 if (payload.data().length()) { | 69 if (payload.data().length()) { |
| 70 notification_data->data.assign(payload.data().begin(), | 70 notification_data->data.assign(payload.data().begin(), |
| 71 payload.data().end()); | 71 payload.data().end()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 for (const auto& payload_action : payload.actions()) { | 74 for (const auto& payload_action : payload.actions()) { |
| 75 PlatformNotificationAction action; | 75 PlatformNotificationAction action; |
| 76 |
| 77 switch (payload_action.type()) { |
| 78 case NotificationDatabaseDataProto::NotificationAction::BUTTON: |
| 79 action.type = PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON; |
| 80 break; |
| 81 case NotificationDatabaseDataProto::NotificationAction::TEXT: |
| 82 action.type = PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT; |
| 83 break; |
| 84 default: |
| 85 NOTREACHED(); |
| 86 } |
| 87 |
| 76 action.action = payload_action.action(); | 88 action.action = payload_action.action(); |
| 77 action.title = base::UTF8ToUTF16(payload_action.title()); | 89 action.title = base::UTF8ToUTF16(payload_action.title()); |
| 78 action.icon = GURL(payload_action.icon()); | 90 action.icon = GURL(payload_action.icon()); |
| 91 if (payload_action.has_placeholder()) { |
| 92 action.placeholder = base::NullableString16( |
| 93 base::UTF8ToUTF16(payload_action.placeholder()), false); |
| 94 } |
| 79 notification_data->actions.push_back(action); | 95 notification_data->actions.push_back(action); |
| 80 } | 96 } |
| 81 | 97 |
| 82 return true; | 98 return true; |
| 83 } | 99 } |
| 84 | 100 |
| 85 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, | 101 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, |
| 86 std::string* output) { | 102 std::string* output) { |
| 87 DCHECK(output); | 103 DCHECK(output); |
| 88 | 104 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 payload->set_require_interaction(notification_data.require_interaction); | 139 payload->set_require_interaction(notification_data.require_interaction); |
| 124 | 140 |
| 125 if (notification_data.data.size()) { | 141 if (notification_data.data.size()) { |
| 126 payload->set_data(¬ification_data.data.front(), | 142 payload->set_data(¬ification_data.data.front(), |
| 127 notification_data.data.size()); | 143 notification_data.data.size()); |
| 128 } | 144 } |
| 129 | 145 |
| 130 for (const PlatformNotificationAction& action : notification_data.actions) { | 146 for (const PlatformNotificationAction& action : notification_data.actions) { |
| 131 NotificationDatabaseDataProto::NotificationAction* payload_action = | 147 NotificationDatabaseDataProto::NotificationAction* payload_action = |
| 132 payload->add_actions(); | 148 payload->add_actions(); |
| 149 |
| 150 switch (action.type) { |
| 151 case PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON: |
| 152 payload_action->set_type( |
| 153 NotificationDatabaseDataProto::NotificationAction::BUTTON); |
| 154 break; |
| 155 case PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT: |
| 156 payload_action->set_type( |
| 157 NotificationDatabaseDataProto::NotificationAction::TEXT); |
| 158 break; |
| 159 default: |
| 160 NOTREACHED() << "Unknown action type: " << action.type; |
| 161 } |
| 162 |
| 133 payload_action->set_action(action.action); | 163 payload_action->set_action(action.action); |
| 134 payload_action->set_title(base::UTF16ToUTF8(action.title)); | 164 payload_action->set_title(base::UTF16ToUTF8(action.title)); |
| 135 payload_action->set_icon(action.icon.spec()); | 165 payload_action->set_icon(action.icon.spec()); |
| 166 |
| 167 if (!action.placeholder.is_null()) { |
| 168 payload_action->set_placeholder( |
| 169 base::UTF16ToUTF8(action.placeholder.string())); |
| 170 } |
| 136 } | 171 } |
| 137 | 172 |
| 138 NotificationDatabaseDataProto message; | 173 NotificationDatabaseDataProto message; |
| 139 message.set_notification_id(input.notification_id); | 174 message.set_notification_id(input.notification_id); |
| 140 message.set_origin(input.origin.spec()); | 175 message.set_origin(input.origin.spec()); |
| 141 message.set_service_worker_registration_id( | 176 message.set_service_worker_registration_id( |
| 142 input.service_worker_registration_id); | 177 input.service_worker_registration_id); |
| 143 message.set_allocated_notification_data(payload.release()); | 178 message.set_allocated_notification_data(payload.release()); |
| 144 | 179 |
| 145 return message.SerializeToString(output); | 180 return message.SerializeToString(output); |
| 146 } | 181 } |
| 147 | 182 |
| 148 } // namespace content | 183 } // namespace content |
| OLD | NEW |