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