Chromium Code Reviews| Index: chrome/browser/extensions/api/notifications/notifications_api.cc |
| =================================================================== |
| --- chrome/browser/extensions/api/notifications/notifications_api.cc (revision 263011) |
| +++ chrome/browser/extensions/api/notifications/notifications_api.cc (working copy) |
| @@ -254,66 +254,64 @@ |
| // Then, handle any optional data that's been provided. |
| message_center::RichNotificationData optional_fields; |
| - if (message_center::IsRichNotificationEnabled()) { |
| - if (options->priority.get()) |
| - optional_fields.priority = *options->priority; |
| + if (options->priority.get()) |
| + optional_fields.priority = *options->priority; |
| - if (options->event_time.get()) |
| - optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); |
| + if (options->event_time.get()) |
| + optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); |
| - if (options->buttons.get()) { |
| - // Currently we allow up to 2 buttons. |
| - size_t number_of_buttons = options->buttons->size(); |
| - number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; |
| + if (options->buttons.get()) { |
| + // Currently we allow up to 2 buttons. |
| + size_t number_of_buttons = options->buttons->size(); |
| + number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; |
| - for (size_t i = 0; i < number_of_buttons; i++) { |
| - message_center::ButtonInfo info( |
| - base::UTF8ToUTF16((*options->buttons)[i]->title)); |
| - NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), |
| - &info.icon); |
| - optional_fields.buttons.push_back(info); |
| - } |
| + for (size_t i = 0; i < number_of_buttons; i++) { |
| + message_center::ButtonInfo info( |
| + base::UTF8ToUTF16((*options->buttons)[i]->title)); |
| + NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), |
| + &info.icon); |
| + optional_fields.buttons.push_back(info); |
| } |
| + } |
| - if (options->context_message) { |
| - optional_fields.context_message = |
| - base::UTF8ToUTF16(*options->context_message); |
| - } |
| + if (options->context_message) { |
| + optional_fields.context_message = |
| + base::UTF8ToUTF16(*options->context_message); |
| + } |
| - bool has_image = NotificationBitmapToGfxImage(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)) |
| - return false; |
| + bool has_image = NotificationBitmapToGfxImage(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)) |
| + return false; |
| - // We should have list items if and only if the type is a multiple type. |
| - bool has_list_items = options->items.get() && options->items->size() > 0; |
| - if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE)) |
| - return false; |
| + // We should have list items if and only if the type is a multiple type. |
| + bool has_list_items = options->items.get() && options->items->size() > 0; |
| + if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE)) |
| + return false; |
| - if (options->progress.get() != NULL) { |
| - // We should have progress if and only if the type is a progress type. |
| - if (type != message_center::NOTIFICATION_TYPE_PROGRESS) { |
| - SetError(kUnexpectedProgressValueForNonProgressType); |
| - return false; |
| - } |
| - optional_fields.progress = *options->progress; |
| - // Progress value should range from 0 to 100. |
| - if (optional_fields.progress < 0 || optional_fields.progress > 100) { |
| - SetError(kInvalidProgressValue); |
| - return false; |
| - } |
| + if (options->progress.get() != NULL) { |
| + // We should have progress if and only if the type is a progress type. |
| + if (type != message_center::NOTIFICATION_TYPE_PROGRESS) { |
| + SetError(kUnexpectedProgressValueForNonProgressType); |
| + return false; |
| } |
| + optional_fields.progress = *options->progress; |
| + // Progress value should range from 0 to 100. |
| + if (optional_fields.progress < 0 || optional_fields.progress > 100) { |
| + SetError(kInvalidProgressValue); |
| + return false; |
| + } |
| + } |
| - if (has_list_items) { |
| - using api::notifications::NotificationItem; |
| - std::vector<linked_ptr<NotificationItem> >::iterator i; |
| - for (i = options->items->begin(); i != options->items->end(); ++i) { |
| - message_center::NotificationItem item( |
| - base::UTF8ToUTF16(i->get()->title), |
| - base::UTF8ToUTF16(i->get()->message)); |
| - optional_fields.items.push_back(item); |
| - } |
| + if (has_list_items) { |
| + using api::notifications::NotificationItem; |
| + std::vector<linked_ptr<NotificationItem> >::iterator i; |
| + for (i = options->items->begin(); i != options->items->end(); ++i) { |
| + message_center::NotificationItem item( |
| + base::UTF8ToUTF16(i->get()->title), |
| + base::UTF8ToUTF16(i->get()->message)); |
| + optional_fields.items.push_back(item); |
| } |
| } |
| @@ -360,73 +358,71 @@ |
| notification->set_icon(icon); |
| } |
| - if (message_center::IsRichNotificationEnabled()) { |
| - if (options->priority) |
| - notification->set_priority(*options->priority); |
| + if (options->priority) |
| + notification->set_priority(*options->priority); |
| - if (options->event_time) |
| - notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); |
| + if (options->event_time) |
| + notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); |
| - if (options->buttons) { |
| - // Currently we allow up to 2 buttons. |
| - size_t number_of_buttons = options->buttons->size(); |
| - number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; |
| + if (options->buttons) { |
| + // Currently we allow up to 2 buttons. |
| + size_t number_of_buttons = options->buttons->size(); |
| + number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; |
| - std::vector<message_center::ButtonInfo> buttons; |
| - for (size_t i = 0; i < number_of_buttons; i++) { |
| - message_center::ButtonInfo button( |
| - base::UTF8ToUTF16((*options->buttons)[i]->title)); |
| - NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), |
| - &button.icon); |
| - buttons.push_back(button); |
| - } |
| - notification->set_buttons(buttons); |
| + std::vector<message_center::ButtonInfo> buttons; |
| + for (size_t i = 0; i < number_of_buttons; i++) { |
| + message_center::ButtonInfo button( |
| + base::UTF8ToUTF16((*options->buttons)[i]->title)); |
| + NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), |
| + &button.icon); |
| + buttons.push_back(button); |
| } |
| + notification->set_buttons(buttons); |
| + } |
| - if (options->context_message) { |
| - notification->set_context_message( |
| - base::UTF8ToUTF16(*options->context_message)); |
| - } |
| + if (options->context_message) { |
| + notification->set_context_message( |
| + base::UTF8ToUTF16(*options->context_message)); |
| + } |
| - gfx::Image image; |
| - if (NotificationBitmapToGfxImage(options->image_bitmap.get(), &image)) { |
| - // We should have an image if and only if the type is an image type. |
| - if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) |
| - return false; |
| - notification->set_image(image); |
| - } |
| + gfx::Image image; |
| + if (NotificationBitmapToGfxImage(options->image_bitmap.get(), &image)) { |
| + // We should have an image if and only if the type is an image type. |
| + if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) |
| + return false; |
| + notification->set_image(image); |
| + } |
| - if (options->progress) { |
| - // We should have progress if and only if the type is a progress type. |
| - if (notification->type() != message_center::NOTIFICATION_TYPE_PROGRESS) { |
| - SetError(kUnexpectedProgressValueForNonProgressType); |
| - return false; |
| - } |
| - int progress = *options->progress; |
| - // Progress value should range from 0 to 100. |
| - if (progress < 0 || progress > 100) { |
| - SetError(kInvalidProgressValue); |
| - return false; |
| - } |
| - notification->set_progress(progress); |
| + if (options->progress) { |
| + // We should have progress if and only if the type is a progress type. |
| + if (notification->type() != message_center::NOTIFICATION_TYPE_PROGRESS) { |
| + SetError(kUnexpectedProgressValueForNonProgressType); |
| + return false; |
| } |
| + int progress = *options->progress; |
| + // Progress value should range from 0 to 100. |
| + if (progress < 0 || progress > 100) { |
| + SetError(kInvalidProgressValue); |
| + return false; |
| + } |
| + notification->set_progress(progress); |
| + } |
| - if (options->items.get() && options->items->size() > 0) { |
| - // We should have list items if and only if the type is a multiple type. |
| - if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE) |
| - return false; |
| + if (options->items.get() && options->items->size() > 0) { |
| + // We should have list items if and only if the type is a multiple type. |
| + if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE) |
| + return false; |
| - std::vector<message_center::NotificationItem> items; |
| - using api::notifications::NotificationItem; |
| - std::vector<linked_ptr<NotificationItem> >::iterator i; |
| - for (i = options->items->begin(); i != options->items->end(); ++i) { |
| - message_center::NotificationItem item( |
| - base::UTF8ToUTF16(i->get()->title), |
| - base::UTF8ToUTF16(i->get()->message)); |
| - items.push_back(item); |
| - } |
| - notification->set_items(items); |
| + std::vector<message_center::NotificationItem> items; |
| + using api::notifications::NotificationItem; |
| + std::vector<linked_ptr<NotificationItem> >::iterator i; |
| + for (i = options->items->begin(); i != options->items->end(); ++i) { |
| + message_center::NotificationItem item( |
| + base::UTF8ToUTF16(i->get()->title), |
| + base::UTF8ToUTF16(i->get()->message)); |
| + items.push_back(item); |
| } |
| + notification->set_items(items); |
|
stevenjb
2014/04/10 17:32:03
It looks like the diff was just butchered and only
jam
2014/04/10 20:10:00
correct
I can verify that locally with a decent d
|
| } |
| // Then override if it's already set. |