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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 vector_as_array(rgba_bitmap_data.get()))); | 135 vector_as_array(rgba_bitmap_data.get()))); |
136 sk_bitmap.unlockPixels(); | 136 sk_bitmap.unlockPixels(); |
137 | 137 |
138 notification_bitmap->data = rgba_bitmap_data.Pass(); | 138 notification_bitmap->data = rgba_bitmap_data.Pass(); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 bool NotificationConversionHelper::NotificationBitmapToGfxImage( | 142 bool NotificationConversionHelper::NotificationBitmapToGfxImage( |
143 float max_scale, | 143 float max_scale, |
144 const gfx::Size& target_size_dips, | 144 const gfx::Size& target_size_dips, |
145 extensions::api::notifications::NotificationBitmap* notification_bitmap, | 145 const extensions::api::notifications::NotificationBitmap& |
| 146 notification_bitmap, |
146 gfx::Image* return_image) { | 147 gfx::Image* return_image) { |
147 if (!notification_bitmap) | |
148 return false; | |
149 | 148 |
150 const int max_device_pixel_width = target_size_dips.width() * max_scale; | 149 const int max_device_pixel_width = target_size_dips.width() * max_scale; |
151 const int max_device_pixel_height = target_size_dips.height() * max_scale; | 150 const int max_device_pixel_height = target_size_dips.height() * max_scale; |
152 | 151 |
153 const int BYTES_PER_PIXEL = 4; | 152 const int BYTES_PER_PIXEL = 4; |
154 | 153 |
155 const int width = notification_bitmap->width; | 154 const int width = notification_bitmap.width; |
156 const int height = notification_bitmap->height; | 155 const int height = notification_bitmap.height; |
157 | 156 |
158 if (width < 0 || height < 0 || width > max_device_pixel_width || | 157 if (width < 0 || height < 0 || width > max_device_pixel_width || |
159 height > max_device_pixel_height) | 158 height > max_device_pixel_height) |
160 return false; | 159 return false; |
161 | 160 |
162 // Ensure we have rgba data. | 161 // Ensure we have rgba data. |
163 std::vector<char>* rgba_data = notification_bitmap->data.get(); | 162 std::vector<char>* rgba_data = notification_bitmap.data.get(); |
164 if (!rgba_data) | 163 if (!rgba_data) |
165 return false; | 164 return false; |
166 | 165 |
167 const size_t rgba_data_length = rgba_data->size(); | 166 const size_t rgba_data_length = rgba_data->size(); |
168 const size_t rgba_area = width * height; | 167 const size_t rgba_area = width * height; |
169 | 168 |
170 if (rgba_data_length != rgba_area * BYTES_PER_PIXEL) | 169 if (rgba_data_length != rgba_area * BYTES_PER_PIXEL) |
171 return false; | 170 return false; |
172 | 171 |
173 SkBitmap bitmap; | 172 SkBitmap bitmap; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return "image"; | 207 return "image"; |
209 case message_center::NOTIFICATION_TYPE_MULTIPLE: | 208 case message_center::NOTIFICATION_TYPE_MULTIPLE: |
210 return "list"; | 209 return "list"; |
211 case message_center::NOTIFICATION_TYPE_PROGRESS: | 210 case message_center::NOTIFICATION_TYPE_PROGRESS: |
212 return "progress"; | 211 return "progress"; |
213 default: | 212 default: |
214 NOTREACHED(); | 213 NOTREACHED(); |
215 return ""; | 214 return ""; |
216 } | 215 } |
217 } | 216 } |
OLD | NEW |