| 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_conversion_helper.h" | 5 #include "chrome/browser/notifications/notification_conversion_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 options->is_clickable.reset(new bool(rich_data->clickable)); | 55 options->is_clickable.reset(new bool(rich_data->clickable)); |
| 56 | 56 |
| 57 options->event_time.reset(new double(rich_data->timestamp.ToDoubleT())); | 57 options->event_time.reset(new double(rich_data->timestamp.ToDoubleT())); |
| 58 | 58 |
| 59 if (!rich_data->context_message.empty()) | 59 if (!rich_data->context_message.empty()) |
| 60 options->context_message.reset( | 60 options->context_message.reset( |
| 61 new std::string(base::UTF16ToUTF8(rich_data->context_message))); | 61 new std::string(base::UTF16ToUTF8(rich_data->context_message))); |
| 62 | 62 |
| 63 if (!rich_data->buttons.empty()) { | 63 if (!rich_data->buttons.empty()) { |
| 64 scoped_ptr<std::vector< | 64 options->buttons.reset( |
| 65 linked_ptr<extensions::api::notifications::NotificationButton> > > | 65 new std::vector<extensions::api::notifications::NotificationButton>()); |
| 66 button_list(new std::vector< | 66 for (const message_center::ButtonInfo& button_info : rich_data->buttons) { |
| 67 linked_ptr<extensions::api::notifications::NotificationButton> >); | 67 extensions::api::notifications::NotificationButton button; |
| 68 for (size_t i = 0; i < rich_data->buttons.size(); i++) { | 68 button.title = base::UTF16ToUTF8(button_info.title); |
| 69 linked_ptr<extensions::api::notifications::NotificationButton> button( | |
| 70 new extensions::api::notifications::NotificationButton); | |
| 71 button->title = base::UTF16ToUTF8(rich_data->buttons[i].title); | |
| 72 | 69 |
| 73 if (!rich_data->buttons[i].icon.IsEmpty()) { | 70 if (!button_info.icon.IsEmpty()) { |
| 74 scoped_ptr<extensions::api::notifications::NotificationBitmap> icon( | 71 scoped_ptr<extensions::api::notifications::NotificationBitmap> icon( |
| 75 new extensions::api::notifications::NotificationBitmap()); | 72 new extensions::api::notifications::NotificationBitmap()); |
| 76 GfxImageToNotificationBitmap(&rich_data->buttons[i].icon, icon.get()); | 73 GfxImageToNotificationBitmap(&button_info.icon, icon.get()); |
| 77 button->icon_bitmap = std::move(icon); | 74 button.icon_bitmap = std::move(icon); |
| 78 } | 75 } |
| 79 button_list->push_back(button); | 76 options->buttons->push_back(std::move(button)); |
| 80 } | 77 } |
| 81 options->buttons = std::move(button_list); | |
| 82 } | 78 } |
| 83 | 79 |
| 84 // Only image type notifications should have images. | 80 // Only image type notifications should have images. |
| 85 if (type == "image" && !rich_data->image.IsEmpty()) { | 81 if (type == "image" && !rich_data->image.IsEmpty()) { |
| 86 scoped_ptr<extensions::api::notifications::NotificationBitmap> image( | 82 scoped_ptr<extensions::api::notifications::NotificationBitmap> image( |
| 87 new extensions::api::notifications::NotificationBitmap()); | 83 new extensions::api::notifications::NotificationBitmap()); |
| 88 GfxImageToNotificationBitmap(¬ification.image(), image.get()); | 84 GfxImageToNotificationBitmap(¬ification.image(), image.get()); |
| 89 options->image_bitmap = std::move(image); | 85 options->image_bitmap = std::move(image); |
| 90 } else if (type != "image" && !rich_data->image.IsEmpty()) { | 86 } else if (type != "image" && !rich_data->image.IsEmpty()) { |
| 91 DVLOG(1) << "Only image type notifications should have images."; | 87 DVLOG(1) << "Only image type notifications should have images."; |
| 92 } | 88 } |
| 93 | 89 |
| 94 // Only progress type notifications should have progress bars. | 90 // Only progress type notifications should have progress bars. |
| 95 if (type == "progress") | 91 if (type == "progress") |
| 96 options->progress.reset(new int(rich_data->progress)); | 92 options->progress.reset(new int(rich_data->progress)); |
| 97 else if (rich_data->progress != 0) | 93 else if (rich_data->progress != 0) |
| 98 DVLOG(1) << "Only progress type notifications should have progress."; | 94 DVLOG(1) << "Only progress type notifications should have progress."; |
| 99 | 95 |
| 100 // Only list type notifications should have lists. | 96 // Only list type notifications should have lists. |
| 101 if (type == "list" && !rich_data->items.empty()) { | 97 if (type == "list" && !rich_data->items.empty()) { |
| 102 scoped_ptr<std::vector< | 98 options->items.reset( |
| 103 linked_ptr<extensions::api::notifications::NotificationItem> > > | 99 new std::vector<extensions::api::notifications::NotificationItem>()); |
| 104 list(new std::vector< | 100 for (const message_center::NotificationItem& item : rich_data->items) { |
| 105 linked_ptr<extensions::api::notifications::NotificationItem> >); | 101 extensions::api::notifications::NotificationItem api_item; |
| 106 for (size_t j = 0; j < rich_data->items.size(); j++) { | 102 api_item.title = base::UTF16ToUTF8(item.title); |
| 107 linked_ptr<extensions::api::notifications::NotificationItem> item( | 103 api_item.message = base::UTF16ToUTF8(item.message); |
| 108 new extensions::api::notifications::NotificationItem); | 104 options->items->push_back(std::move(api_item)); |
| 109 item->title = base::UTF16ToUTF8(rich_data->items[j].title); | |
| 110 item->message = base::UTF16ToUTF8(rich_data->items[j].message); | |
| 111 list->push_back(item); | |
| 112 } | 105 } |
| 113 options->items = std::move(list); | |
| 114 } else if (type != "list" && !rich_data->items.empty()) { | 106 } else if (type != "list" && !rich_data->items.empty()) { |
| 115 DVLOG(1) << "Only list type notifications should have lists."; | 107 DVLOG(1) << "Only list type notifications should have lists."; |
| 116 } | 108 } |
| 117 } | 109 } |
| 118 | 110 |
| 119 void NotificationConversionHelper::GfxImageToNotificationBitmap( | 111 void NotificationConversionHelper::GfxImageToNotificationBitmap( |
| 120 const gfx::Image* gfx_image, | 112 const gfx::Image* gfx_image, |
| 121 extensions::api::notifications::NotificationBitmap* notification_bitmap) { | 113 extensions::api::notifications::NotificationBitmap* notification_bitmap) { |
| 122 SkBitmap sk_bitmap = gfx_image->AsBitmap(); | 114 SkBitmap sk_bitmap = gfx_image->AsBitmap(); |
| 123 sk_bitmap.lockPixels(); | 115 sk_bitmap.lockPixels(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return "image"; | 200 return "image"; |
| 209 case message_center::NOTIFICATION_TYPE_MULTIPLE: | 201 case message_center::NOTIFICATION_TYPE_MULTIPLE: |
| 210 return "list"; | 202 return "list"; |
| 211 case message_center::NOTIFICATION_TYPE_PROGRESS: | 203 case message_center::NOTIFICATION_TYPE_PROGRESS: |
| 212 return "progress"; | 204 return "progress"; |
| 213 default: | 205 default: |
| 214 NOTREACHED(); | 206 NOTREACHED(); |
| 215 return ""; | 207 return ""; |
| 216 } | 208 } |
| 217 } | 209 } |
| OLD | NEW |