| 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 | |
| 150 const int max_device_pixel_width = target_size_dips.width() * max_scale; | 148 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; | 149 const int max_device_pixel_height = target_size_dips.height() * max_scale; |
| 152 | 150 |
| 153 const int BYTES_PER_PIXEL = 4; | 151 const int BYTES_PER_PIXEL = 4; |
| 154 | 152 |
| 155 const int width = notification_bitmap->width; | 153 const int width = notification_bitmap.width; |
| 156 const int height = notification_bitmap->height; | 154 const int height = notification_bitmap.height; |
| 157 | 155 |
| 158 if (width < 0 || height < 0 || width > max_device_pixel_width || | 156 if (width < 0 || height < 0 || width > max_device_pixel_width || |
| 159 height > max_device_pixel_height) | 157 height > max_device_pixel_height) |
| 160 return false; | 158 return false; |
| 161 | 159 |
| 162 // Ensure we have rgba data. | 160 // Ensure we have rgba data. |
| 163 std::vector<char>* rgba_data = notification_bitmap->data.get(); | 161 std::vector<char>* rgba_data = notification_bitmap.data.get(); |
| 164 if (!rgba_data) | 162 if (!rgba_data) |
| 165 return false; | 163 return false; |
| 166 | 164 |
| 167 const size_t rgba_data_length = rgba_data->size(); | 165 const size_t rgba_data_length = rgba_data->size(); |
| 168 const size_t rgba_area = width * height; | 166 const size_t rgba_area = width * height; |
| 169 | 167 |
| 170 if (rgba_data_length != rgba_area * BYTES_PER_PIXEL) | 168 if (rgba_data_length != rgba_area * BYTES_PER_PIXEL) |
| 171 return false; | 169 return false; |
| 172 | 170 |
| 173 SkBitmap bitmap; | 171 SkBitmap bitmap; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return "image"; | 206 return "image"; |
| 209 case message_center::NOTIFICATION_TYPE_MULTIPLE: | 207 case message_center::NOTIFICATION_TYPE_MULTIPLE: |
| 210 return "list"; | 208 return "list"; |
| 211 case message_center::NOTIFICATION_TYPE_PROGRESS: | 209 case message_center::NOTIFICATION_TYPE_PROGRESS: |
| 212 return "progress"; | 210 return "progress"; |
| 213 default: | 211 default: |
| 214 NOTREACHED(); | 212 NOTREACHED(); |
| 215 return ""; | 213 return ""; |
| 216 } | 214 } |
| 217 } | 215 } |
| OLD | NEW |