Chromium Code Reviews| 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 } else { | |
| 95 action.placeholder = base::NullableString16(); | |
|
Peter Beverloo
2016/04/06 17:22:00
nit: this should be done implicitly by the constru
Nina
2016/04/07 10:59:09
Indeed! Removed.
| |
| 96 } | |
| 79 notification_data->actions.push_back(action); | 97 notification_data->actions.push_back(action); |
| 80 } | 98 } |
| 81 | 99 |
| 82 return true; | 100 return true; |
| 83 } | 101 } |
| 84 | 102 |
| 85 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, | 103 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, |
| 86 std::string* output) { | 104 std::string* output) { |
| 87 DCHECK(output); | 105 DCHECK(output); |
| 88 | 106 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 payload->set_require_interaction(notification_data.require_interaction); | 141 payload->set_require_interaction(notification_data.require_interaction); |
| 124 | 142 |
| 125 if (notification_data.data.size()) { | 143 if (notification_data.data.size()) { |
| 126 payload->set_data(¬ification_data.data.front(), | 144 payload->set_data(¬ification_data.data.front(), |
| 127 notification_data.data.size()); | 145 notification_data.data.size()); |
| 128 } | 146 } |
| 129 | 147 |
| 130 for (const PlatformNotificationAction& action : notification_data.actions) { | 148 for (const PlatformNotificationAction& action : notification_data.actions) { |
| 131 NotificationDatabaseDataProto::NotificationAction* payload_action = | 149 NotificationDatabaseDataProto::NotificationAction* payload_action = |
| 132 payload->add_actions(); | 150 payload->add_actions(); |
| 151 | |
| 152 switch (action.type) { | |
| 153 case PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON: | |
| 154 payload_action->set_type( | |
| 155 NotificationDatabaseDataProto::NotificationAction::BUTTON); | |
| 156 break; | |
| 157 case PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT: | |
| 158 payload_action->set_type( | |
| 159 NotificationDatabaseDataProto::NotificationAction::TEXT); | |
| 160 break; | |
| 161 default: | |
| 162 NOTREACHED() << "Unknown action type: " << action.type; | |
| 163 } | |
| 164 | |
| 133 payload_action->set_action(action.action); | 165 payload_action->set_action(action.action); |
| 134 payload_action->set_title(base::UTF16ToUTF8(action.title)); | 166 payload_action->set_title(base::UTF16ToUTF8(action.title)); |
| 135 payload_action->set_icon(action.icon.spec()); | 167 payload_action->set_icon(action.icon.spec()); |
| 168 | |
| 169 if (!action.placeholder.is_null()) { | |
| 170 payload_action->set_placeholder( | |
| 171 base::UTF16ToUTF8(action.placeholder.string())); | |
| 172 } | |
| 136 } | 173 } |
| 137 | 174 |
| 138 NotificationDatabaseDataProto message; | 175 NotificationDatabaseDataProto message; |
| 139 message.set_notification_id(input.notification_id); | 176 message.set_notification_id(input.notification_id); |
| 140 message.set_origin(input.origin.spec()); | 177 message.set_origin(input.origin.spec()); |
| 141 message.set_service_worker_registration_id( | 178 message.set_service_worker_registration_id( |
| 142 input.service_worker_registration_id); | 179 input.service_worker_registration_id); |
| 143 message.set_allocated_notification_data(payload.release()); | 180 message.set_allocated_notification_data(payload.release()); |
| 144 | 181 |
| 145 return message.SerializeToString(output); | 182 return message.SerializeToString(output); |
| 146 } | 183 } |
| 147 | 184 |
| 148 } // namespace content | 185 } // namespace content |
| OLD | NEW |