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 19a66268f94affee63d9e018bc4824bb2edf9606..c346c4f45bca79966cdd98e8101d365f8c6a5266 100644 |
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc |
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc |
@@ -21,6 +21,7 @@ |
#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/render_view_host.h" |
#include "googleurl/src/gurl.h" |
+#include "ui/message_center/message_center_util.h" |
namespace extensions { |
@@ -141,117 +142,112 @@ NotificationsApiFunction::NotificationsApiFunction() { |
NotificationsApiFunction::~NotificationsApiFunction() { |
} |
-// If older notification runtime is used, MessageCenter is not built. |
-// Use simpler bridge then, ignoring all options. |
-#if !defined (ENABLE_MESSAGE_CENTER) |
void NotificationsApiFunction::CreateNotification( |
const std::string& id, |
api::notifications::NotificationOptions* options) { |
- message_center::NotificationType type = |
- MapApiTemplateTypeToType(options->type); |
- GURL icon_url(UTF8ToUTF16(options->icon_url)); |
- string16 title(UTF8ToUTF16(options->title)); |
- string16 message(UTF8ToUTF16(options->message)); |
- |
- // Ignore options if running on the old notification runtime. |
- scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); |
- |
- NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( |
- this, |
- profile(), |
- extension_->id(), |
- id)); // ownership is passed to Notification |
- Notification notification(type, extension_->url(), icon_url, title, message, |
- WebKit::WebTextDirectionDefault, |
- UTF8ToUTF16(extension_->name()), |
- UTF8ToUTF16(api_delegate->id()), |
- optional_fields.get(), api_delegate); |
- |
- g_browser_process->notification_ui_manager()->Add(notification, profile()); |
-} |
-#else // defined(ENABLE_MESSAGE_CENTER) |
-void NotificationsApiFunction::CreateNotification( |
- const std::string& id, |
- api::notifications::NotificationOptions* options) { |
- message_center::NotificationType type = |
- MapApiTemplateTypeToType(options->type); |
- GURL icon_url(UTF8ToUTF16(options->icon_url)); |
- string16 title(UTF8ToUTF16(options->title)); |
- string16 message(UTF8ToUTF16(options->message)); |
- |
- scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); |
- |
- // For all notification types. |
- if (options->priority.get()) |
- optional_fields->SetInteger(message_center::kPriorityKey, |
- *options->priority); |
- if (options->event_time.get()) |
- optional_fields->SetDouble(message_center::kTimestampKey, |
- *options->event_time); |
- if (options->buttons.get()) { |
- if (options->buttons->size() > 0) { |
- linked_ptr<api::notifications::NotificationButton> button = |
- (*options->buttons)[0]; |
- optional_fields->SetString(message_center::kButtonOneTitleKey, |
- UTF8ToUTF16(button->title)); |
- if (button->icon_url.get()) |
- optional_fields->SetString(message_center::kButtonOneIconUrlKey, |
- UTF8ToUTF16(*button->icon_url)); |
- } |
- if (options->buttons->size() > 1) { |
- linked_ptr<api::notifications::NotificationButton> button = |
- (*options->buttons)[1]; |
- optional_fields->SetString(message_center::kButtonTwoTitleKey, |
- UTF8ToUTF16(button->title)); |
- if (button->icon_url.get()) |
- optional_fields->SetString(message_center::kButtonTwoIconUrlKey, |
- UTF8ToUTF16(*button->icon_url)); |
+ // If older notification runtime is used, use simpler bridge. |
+ if (message_center::IsRichNotificationEnabled()) { |
dewittj
2013/05/08 18:53:01
need a "!" in the conditional?
Dmitry Titov
2013/05/08 23:03:26
oops. Done. Tested that Galore works :-)
|
+ message_center::NotificationType type = |
+ MapApiTemplateTypeToType(options->type); |
+ GURL icon_url(UTF8ToUTF16(options->icon_url)); |
+ string16 title(UTF8ToUTF16(options->title)); |
+ string16 message(UTF8ToUTF16(options->message)); |
+ |
+ // Ignore options if running on the old notification runtime. |
+ scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); |
+ |
+ NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( |
+ this, |
+ profile(), |
+ extension_->id(), |
+ id)); // ownership is passed to Notification |
+ Notification notification(type, extension_->url(), icon_url, title, message, |
+ WebKit::WebTextDirectionDefault, |
+ UTF8ToUTF16(extension_->name()), |
+ UTF8ToUTF16(api_delegate->id()), |
+ optional_fields.get(), api_delegate); |
+ |
+ g_browser_process->notification_ui_manager()->Add(notification, profile()); |
dewittj
2013/05/08 18:53:01
put a return here to buy one level of indentation
Dmitry Titov
2013/05/08 23:03:26
Done.
|
+ } else { |
+ message_center::NotificationType type = |
+ MapApiTemplateTypeToType(options->type); |
+ GURL icon_url(UTF8ToUTF16(options->icon_url)); |
+ string16 title(UTF8ToUTF16(options->title)); |
+ string16 message(UTF8ToUTF16(options->message)); |
+ |
+ scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); |
+ |
+ // For all notification types. |
+ if (options->priority.get()) |
+ optional_fields->SetInteger(message_center::kPriorityKey, |
+ *options->priority); |
+ if (options->event_time.get()) |
+ optional_fields->SetDouble(message_center::kTimestampKey, |
+ *options->event_time); |
+ if (options->buttons.get()) { |
+ if (options->buttons->size() > 0) { |
+ linked_ptr<api::notifications::NotificationButton> button = |
+ (*options->buttons)[0]; |
+ optional_fields->SetString(message_center::kButtonOneTitleKey, |
+ UTF8ToUTF16(button->title)); |
+ if (button->icon_url.get()) |
+ optional_fields->SetString(message_center::kButtonOneIconUrlKey, |
+ UTF8ToUTF16(*button->icon_url)); |
+ } |
+ if (options->buttons->size() > 1) { |
+ linked_ptr<api::notifications::NotificationButton> button = |
+ (*options->buttons)[1]; |
+ optional_fields->SetString(message_center::kButtonTwoTitleKey, |
+ UTF8ToUTF16(button->title)); |
+ if (button->icon_url.get()) |
+ optional_fields->SetString(message_center::kButtonTwoIconUrlKey, |
+ UTF8ToUTF16(*button->icon_url)); |
+ } |
} |
- } |
- if (options->expanded_message.get()) |
- optional_fields->SetString(message_center::kExpandedMessageKey, |
- UTF8ToUTF16(*options->expanded_message)); |
- |
- // For image notifications (type == 'image'). |
- // TODO(dharcourt): Fail if (type == 'image' && !options->image_url.get()) |
- // TODO(dharcourt): Fail if (type != 'image' && options->image_url.get()) |
- if (options->image_url.get()) |
- optional_fields->SetString(message_center::kImageUrlKey, |
- UTF8ToUTF16(*options->image_url)); |
- |
- // For list notifications (type == 'multiple'). |
- // TODO(dharcourt): Fail if (type == 'multiple' && !options->items.get()) |
- // TODO(dharcourt): Fail if (type != 'multiple' && options->items.get()) |
- if (options->items.get()) { |
- base::ListValue* items = new base::ListValue(); |
- std::vector< |
- linked_ptr< |
- api::notifications::NotificationItem> >::iterator i; |
- for (i = options->items->begin(); i != options->items->end(); ++i) { |
- base::DictionaryValue* item = new base::DictionaryValue(); |
- item->SetString(message_center::kItemTitleKey, |
- UTF8ToUTF16(i->get()->title)); |
- item->SetString(message_center::kItemMessageKey, |
- UTF8ToUTF16(i->get()->message)); |
- items->Append(item); |
+ if (options->expanded_message.get()) |
+ optional_fields->SetString(message_center::kExpandedMessageKey, |
+ UTF8ToUTF16(*options->expanded_message)); |
+ |
+ // For image notifications (type == 'image'). |
+ // TODO(dharcourt): Fail if (type == 'image' && !options->image_url.get()) |
+ // TODO(dharcourt): Fail if (type != 'image' && options->image_url.get()) |
+ if (options->image_url.get()) |
+ optional_fields->SetString(message_center::kImageUrlKey, |
+ UTF8ToUTF16(*options->image_url)); |
+ |
+ // For list notifications (type == 'multiple'). |
+ // TODO(dharcourt): Fail if (type == 'multiple' && !options->items.get()) |
+ // TODO(dharcourt): Fail if (type != 'multiple' && options->items.get()) |
+ if (options->items.get()) { |
+ base::ListValue* items = new base::ListValue(); |
+ std::vector< |
+ linked_ptr< |
+ api::notifications::NotificationItem> >::iterator i; |
+ for (i = options->items->begin(); i != options->items->end(); ++i) { |
+ base::DictionaryValue* item = new base::DictionaryValue(); |
+ item->SetString(message_center::kItemTitleKey, |
+ UTF8ToUTF16(i->get()->title)); |
+ item->SetString(message_center::kItemMessageKey, |
+ UTF8ToUTF16(i->get()->message)); |
+ items->Append(item); |
+ } |
+ optional_fields->Set(message_center::kItemsKey, items); |
} |
- optional_fields->Set(message_center::kItemsKey, items); |
- } |
- NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( |
- this, |
- profile(), |
- extension_->id(), |
- id)); // ownership is passed to Notification |
- Notification notification(type, extension_->url(), icon_url, title, message, |
- WebKit::WebTextDirectionDefault, |
- UTF8ToUTF16(extension_->name()), |
- UTF8ToUTF16(api_delegate->id()), |
- optional_fields.get(), api_delegate); |
- |
- g_browser_process->notification_ui_manager()->Add(notification, profile()); |
+ NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( |
+ this, |
+ profile(), |
+ extension_->id(), |
+ id)); // ownership is passed to Notification |
+ Notification notification(type, extension_->url(), icon_url, title, message, |
+ WebKit::WebTextDirectionDefault, |
+ UTF8ToUTF16(extension_->name()), |
+ UTF8ToUTF16(api_delegate->id()), |
+ optional_fields.get(), api_delegate); |
+ |
+ g_browser_process->notification_ui_manager()->Add(notification, profile()); |
+ } |
} |
-#endif // !defined(ENABLE_MESSAGE_CENTER) |
bool NotificationsApiFunction::IsNotificationsApiEnabled() { |
DesktopNotificationService* service = |