Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: chrome/browser/extensions/api/notification/notification_api.cc

Issue 12212037: Update notifications API after review. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge conflict resolved Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/notification/notification_api.cc
diff --git a/chrome/browser/extensions/api/notification/notification_api.cc b/chrome/browser/extensions/api/notification/notification_api.cc
index 65e788fe31e3eef5731759479e7849fc4ce5cd81..a0f465e10962ad5830529f18b7231ae26150ea25 100644
--- a/chrome/browser/extensions/api/notification/notification_api.cc
+++ b/chrome/browser/extensions/api/notification/notification_api.cc
@@ -17,7 +17,6 @@
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/common/extensions/extension.h"
#include "googleurl/src/gurl.h"
-#include "ui/notifications/notification_types.h"
namespace extensions {
@@ -117,11 +116,31 @@ NotificationApiFunction::NotificationApiFunction() {
NotificationApiFunction::~NotificationApiFunction() {
}
+ui::notifications::NotificationType
+NotificationApiFunction::MapApiTemplateTypeToType(
+ api::experimental_notification::TemplateType type) {
+ switch (type) {
+ case api::experimental_notification::TEMPLATE_TYPE_NONE:
+ case api::experimental_notification::TEMPLATE_TYPE_SIMPLE:
+ return ui::notifications::NOTIFICATION_TYPE_SIMPLE;
+ case api::experimental_notification::TEMPLATE_TYPE_BASIC:
+ return ui::notifications::NOTIFICATION_TYPE_BASE_FORMAT;
+ case api::experimental_notification::TEMPLATE_TYPE_IMAGE:
+ return ui::notifications::NOTIFICATION_TYPE_IMAGE;
+ case api::experimental_notification::TEMPLATE_TYPE_LIST:
+ return ui::notifications::NOTIFICATION_TYPE_MULTIPLE;
+ default:
+ // Gracefully handle newer application code that is running on an older
+ // runtime that doesn't recognize the requested template.
+ return ui::notifications::NOTIFICATION_TYPE_BASE_FORMAT;
+ }
+}
+
void NotificationApiFunction::CreateNotification(
const std::string& id,
api::experimental_notification::NotificationOptions* options) {
- ui::notifications::NotificationType type =
- ui::notifications::StringToNotificationType(options->type);
+ ui::notifications::NotificationType type = MapApiTemplateTypeToType(
+ options->template_type);
GURL icon_url(UTF8ToUTF16(options->icon_url));
string16 title(UTF8ToUTF16(options->title));
string16 message(UTF8ToUTF16(options->message));
@@ -132,27 +151,29 @@ void NotificationApiFunction::CreateNotification(
if (options->priority.get())
optional_fields->SetInteger(ui::notifications::kPriorityKey,
*options->priority);
- if (options->timestamp.get())
+ if (options->event_time.get())
optional_fields->SetString(ui::notifications::kTimestampKey,
- *options->timestamp);
- if (options->unread_count.get())
- optional_fields->SetInteger(ui::notifications::kUnreadCountKey,
- *options->unread_count);
- if (options->button_one_title.get())
- optional_fields->SetString(ui::notifications::kButtonOneTitleKey,
- UTF8ToUTF16(*options->button_one_title));
- if (options->button_one_icon_url.get())
- optional_fields->SetString(ui::notifications::kButtonOneIconUrlKey,
- UTF8ToUTF16(*options->button_one_icon_url));
- // TODO(dharcourt): Fail if:
- // (options->button_two_title.get() || options->button_two_icon_url.get()) &&
- // !(options->button_one_title.get() || options->button_one_icon_url.get())
- if (options->button_two_title.get())
- optional_fields->SetString(ui::notifications::kButtonTwoTitleKey,
- UTF8ToUTF16(*options->button_two_title));
- if (options->button_two_icon_url.get())
- optional_fields->SetString(ui::notifications::kButtonTwoIconUrlKey,
- UTF8ToUTF16(*options->button_two_icon_url));
+ *options->event_time);
+ if (options->buttons.get()) {
+ if (options->buttons->size() > 0) {
+ linked_ptr<api::experimental_notification::NotificationButton> button =
+ (*options->buttons)[0];
+ optional_fields->SetString(ui::notifications::kButtonOneTitleKey,
+ UTF8ToUTF16(button->title));
+ if (button->icon_url.get())
+ optional_fields->SetString(ui::notifications::kButtonOneIconUrlKey,
+ UTF8ToUTF16(*button->icon_url));
+ }
+ if (options->buttons->size() > 1) {
+ linked_ptr<api::experimental_notification::NotificationButton> button =
+ (*options->buttons)[1];
+ optional_fields->SetString(ui::notifications::kButtonTwoTitleKey,
+ UTF8ToUTF16(button->title));
+ if (button->icon_url.get())
+ optional_fields->SetString(ui::notifications::kButtonTwoIconUrlKey,
+ UTF8ToUTF16(*button->icon_url));
+ }
+ }
if (options->expanded_message.get())
optional_fields->SetString(ui::notifications::kExpandedMessageKey,
UTF8ToUTF16(*options->expanded_message));

Powered by Google App Engine
This is Rietveld 408576698