Chromium Code Reviews| Index: chrome/browser/extensions/api/notifications/notifications_api.cc |
| diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc |
| index 71fb9122a375d0082b8a09c53efa7e975eab4f38..bc1399a8e936802ea3f59a048fc5acd852da0fff 100644 |
| --- a/chrome/browser/extensions/api/notifications/notifications_api.cc |
| +++ b/chrome/browser/extensions/api/notifications/notifications_api.cc |
| @@ -183,10 +183,9 @@ bool NotificationsApiFunction::CreateNotification( |
| const base::string16 message(base::UTF8ToUTF16(*options->message)); |
| gfx::Image icon; |
| - if (!NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.icon_size, |
| - options->icon_bitmap.get(), |
| + if (options->icon_bitmap.get() && |
| + !NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), |
| &icon)) { |
| SetError(kUnableToDecodeIconError); |
| return false; |
| @@ -194,15 +193,12 @@ bool NotificationsApiFunction::CreateNotification( |
| // Then, handle any optional data that's been provided. |
| message_center::RichNotificationData optional_fields; |
| - if (options->app_icon_mask_url.get()) { |
| - if (!NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.app_icon_mask_size, |
| - options->app_icon_mask_bitmap.get(), |
| - &optional_fields.small_image)) { |
| + if (options->app_icon_mask_bitmap.get() && |
| + !NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.app_icon_mask_size, |
| + options->app_icon_mask_bitmap.get(), &optional_fields.small_image)) { |
| SetError(kUnableToDecodeIconError); |
| return false; |
| - } |
| } |
| if (options->priority.get()) |
| @@ -219,12 +215,12 @@ bool NotificationsApiFunction::CreateNotification( |
| for (size_t i = 0; i < number_of_buttons; i++) { |
| message_center::ButtonInfo info( |
| base::UTF8ToUTF16((*options->buttons)[i]->title)); |
| - NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.button_icon_size, |
| - (*options->buttons)[i]->icon_bitmap.get(), |
| - &info.icon); |
| - optional_fields.buttons.push_back(info); |
| + if ((*options->buttons)[i]->icon_bitmap.get()) { |
| + NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.button_icon_size, |
| + (*options->buttons)[i]->icon_bitmap.get(), &info.icon); |
| + optional_fields.buttons.push_back(info); |
| + } |
| } |
| } |
| @@ -233,15 +229,15 @@ bool NotificationsApiFunction::CreateNotification( |
| base::UTF8ToUTF16(*options->context_message); |
| } |
| - bool has_image = NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.image_size, |
| - options->image_bitmap.get(), |
| - &optional_fields.image); |
| - // We should have an image if and only if the type is an image type. |
| - if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) { |
| - SetError(kExtraImageProvided); |
| - return false; |
| + if (options->image_bitmap.get()) { |
| + bool has_image = NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.image_size, options->image_bitmap.get(), |
| + &optional_fields.image); |
| + // We should have an image if and only if the type is an image type. |
| + if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) { |
| + SetError(kExtraImageProvided); |
| + return false; |
| + } |
| } |
| // We should have list items if and only if the type is a multiple type. |
| @@ -315,20 +311,25 @@ bool NotificationsApiFunction::UpdateNotification( |
| if (options->message) |
| notification->set_message(base::UTF8ToUTF16(*options->message)); |
| - // TODO(dewittj): Return error if this fails. |
| - if (options->icon_bitmap) { |
| + if (options->icon_bitmap.get()) { |
|
dewittj
2015/05/22 16:42:23
icon is required, we need to set an error if there
Deepak
2015/05/23 14:03:40
When I return error code on failing of this if (op
|
| gfx::Image icon; |
| - NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); |
| + if (!NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), |
| + &icon)) { |
| + SetError(kUnableToDecodeIconError); |
| + return false; |
| + } |
| notification->set_icon(icon); |
| } |
| - gfx::Image app_icon_mask; |
| - if (NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.app_icon_mask_size, |
| - options->app_icon_mask_bitmap.get(), |
| - &app_icon_mask)) { |
| + if (options->app_icon_mask_bitmap.get()) { |
| + gfx::Image app_icon_mask; |
| + if (!NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.app_icon_mask_size, |
| + options->app_icon_mask_bitmap.get(), &app_icon_mask)) { |
| + SetError(kUnableToDecodeIconError); |
| + return false; |
| + } |
| notification->set_small_image(app_icon_mask); |
| } |
| @@ -347,12 +348,12 @@ bool NotificationsApiFunction::UpdateNotification( |
| for (size_t i = 0; i < number_of_buttons; i++) { |
| message_center::ButtonInfo button( |
| base::UTF8ToUTF16((*options->buttons)[i]->title)); |
| - NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.button_icon_size, |
| - (*options->buttons)[i]->icon_bitmap.get(), |
| - &button.icon); |
| - buttons.push_back(button); |
| + if ((*options->buttons)[i]->icon_bitmap.get()) { |
| + NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.button_icon_size, |
| + (*options->buttons)[i]->icon_bitmap.get(), &button.icon); |
| + buttons.push_back(button); |
| + } |
| } |
| notification->set_buttons(buttons); |
| } |
| @@ -362,13 +363,15 @@ bool NotificationsApiFunction::UpdateNotification( |
| base::UTF8ToUTF16(*options->context_message)); |
| } |
| - gfx::Image image; |
| - bool has_image = NotificationConversionHelper::NotificationBitmapToGfxImage( |
| - image_scale, |
| - bitmap_sizes.image_size, |
| - options->image_bitmap.get(), |
| - &image); |
| - if (has_image) { |
| + if (options->image_bitmap.get()) { |
|
dewittj
2015/05/22 16:42:23
If the type is 'image', then an image bitmap is re
Deepak
2015/05/23 14:03:40
Done.
|
| + gfx::Image image; |
| + bool has_image = NotificationConversionHelper::NotificationBitmapToGfxImage( |
| + image_scale, bitmap_sizes.image_size, options->image_bitmap.get(), |
| + &image); |
| + if (!has_image) { |
| + SetError(kUnableToDecodeIconError); |
| + return false; |
| + } |
| // We should have an image if and only if the type is an image type. |
| if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) { |
| SetError(kExtraImageProvided); |