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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/notification/notification_api.h" 5 #include "chrome/browser/extensions/api/notification/notification_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/event_names.h" 11 #include "chrome/browser/extensions/event_names.h"
12 #include "chrome/browser/extensions/event_router.h" 12 #include "chrome/browser/extensions/event_router.h"
13 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h" 15 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "ui/notifications/notification_types.h"
19 18
20 namespace extensions { 19 namespace extensions {
21 20
22 namespace { 21 namespace {
23 22
24 const char kResultKey[] = "result"; 23 const char kResultKey[] = "result";
25 24
26 class NotificationApiDelegate : public NotificationDelegate { 25 class NotificationApiDelegate : public NotificationDelegate {
27 public: 26 public:
28 NotificationApiDelegate(ApiFunction* api_function, 27 NotificationApiDelegate(ApiFunction* api_function,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 }; 107 };
109 108
110 } // namespace 109 } // namespace
111 110
112 NotificationApiFunction::NotificationApiFunction() { 111 NotificationApiFunction::NotificationApiFunction() {
113 } 112 }
114 113
115 NotificationApiFunction::~NotificationApiFunction() { 114 NotificationApiFunction::~NotificationApiFunction() {
116 } 115 }
117 116
117 ui::notifications::NotificationType
118 NotificationApiFunction::MapApiTemplateTypeToType(
119 api::experimental_notification::TemplateType type) {
120 switch (type) {
121 case api::experimental_notification::TEMPLATE_TYPE_NONE:
122 case api::experimental_notification::TEMPLATE_TYPE_SIMPLE:
123 return ui::notifications::NOTIFICATION_TYPE_SIMPLE;
124 case api::experimental_notification::TEMPLATE_TYPE_BASIC:
125 return ui::notifications::NOTIFICATION_TYPE_BASE_FORMAT;
126 case api::experimental_notification::TEMPLATE_TYPE_IMAGE:
127 return ui::notifications::NOTIFICATION_TYPE_IMAGE;
128 case api::experimental_notification::TEMPLATE_TYPE_LIST:
129 return ui::notifications::NOTIFICATION_TYPE_MULTIPLE;
130 default:
131 // Gracefully handle newer application code that is running on an older
132 // runtime that doesn't recognize the requested template.
133 return ui::notifications::NOTIFICATION_TYPE_SIMPLE;
dharcourt 2013/02/06 21:34:20 Wouldn't NOTIFICATION_TYPE_BASIC be more appropria
134 }
135 }
136
118 void NotificationApiFunction::CreateNotification( 137 void NotificationApiFunction::CreateNotification(
119 const std::string& id, 138 const std::string& id,
120 api::experimental_notification::NotificationOptions* options) { 139 api::experimental_notification::NotificationOptions* options) {
121 ui::notifications::NotificationType type = 140 ui::notifications::NotificationType type = MapApiTemplateTypeToType(
122 ui::notifications::StringToNotificationType(options->type); 141 options->template_type);
123 GURL icon_url(UTF8ToUTF16(options->icon_url)); 142 GURL icon_url(UTF8ToUTF16(options->icon_url));
124 string16 title(UTF8ToUTF16(options->title)); 143 string16 title(UTF8ToUTF16(options->title));
125 string16 message(UTF8ToUTF16(options->message)); 144 string16 message(UTF8ToUTF16(options->message));
126 145
127 scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); 146 scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue());
128 147
129 // For all notification types. 148 // For all notification types.
130 if (options->priority.get()) 149 if (options->priority.get())
131 optional_fields->SetInteger(ui::notifications::kPriorityKey, 150 optional_fields->SetInteger(ui::notifications::kPriorityKey,
132 *options->priority); 151 *options->priority);
133 if (options->timestamp.get()) 152 if (options->event_time.get())
134 optional_fields->SetString(ui::notifications::kTimestampKey, 153 optional_fields->SetString(ui::notifications::kTimestampKey,
135 *options->timestamp); 154 *options->event_time);
136 if (options->unread_count.get()) 155 if (options->buttons.get()) {
137 optional_fields->SetInteger(ui::notifications::kUnreadCountKey, 156 if (options->buttons->size() > 0) {
138 *options->unread_count); 157 linked_ptr<api::experimental_notification::NotificationButton> button =
139 if (options->button_one_title.get()) 158 (*options->buttons)[0];
140 optional_fields->SetString(ui::notifications::kButtonOneTitleKey, 159 optional_fields->SetString(ui::notifications::kButtonOneTitleKey,
141 UTF8ToUTF16(*options->button_one_title)); 160 UTF8ToUTF16(button->title));
142 if (options->button_one_icon_url.get()) 161 if (button->icon_url.get())
143 optional_fields->SetString(ui::notifications::kButtonOneIconUrlKey, 162 optional_fields->SetString(ui::notifications::kButtonOneIconUrlKey,
144 UTF8ToUTF16(*options->button_one_icon_url)); 163 UTF8ToUTF16(*button->icon_url));
145 // TODO(dharcourt): Fail if: 164 }
146 // (options->button_two_title.get() || options->button_two_icon_url.get()) && 165 if (options->buttons->size() > 1) {
147 // !(options->button_one_title.get() || options->button_one_icon_url.get()) 166 linked_ptr<api::experimental_notification::NotificationButton> button =
148 if (options->button_two_title.get()) 167 (*options->buttons)[1];
149 optional_fields->SetString(ui::notifications::kButtonTwoTitleKey, 168 optional_fields->SetString(ui::notifications::kButtonTwoTitleKey,
150 UTF8ToUTF16(*options->button_two_title)); 169 UTF8ToUTF16(button->title));
151 if (options->button_two_icon_url.get()) 170 if (button->icon_url.get())
152 optional_fields->SetString(ui::notifications::kButtonTwoIconUrlKey, 171 optional_fields->SetString(ui::notifications::kButtonTwoIconUrlKey,
153 UTF8ToUTF16(*options->button_two_icon_url)); 172 UTF8ToUTF16(*button->icon_url));
173 }
174 }
154 if (options->expanded_message.get()) 175 if (options->expanded_message.get())
155 optional_fields->SetString(ui::notifications::kExpandedMessageKey, 176 optional_fields->SetString(ui::notifications::kExpandedMessageKey,
156 UTF8ToUTF16(*options->expanded_message)); 177 UTF8ToUTF16(*options->expanded_message));
157 178
158 // For image notifications (type == 'image'). 179 // For image notifications (type == 'image').
159 // TODO(dharcourt): Fail if (type == 'image' && !options->image_url.get()) 180 // TODO(dharcourt): Fail if (type == 'image' && !options->image_url.get())
160 // TODO(dharcourt): Fail if (type != 'image' && options->image_url.get()) 181 // TODO(dharcourt): Fail if (type != 'image' && options->image_url.get())
161 if (options->image_url.get()) 182 if (options->image_url.get())
162 optional_fields->SetString(ui::notifications::kImageUrlKey, 183 optional_fields->SetString(ui::notifications::kImageUrlKey,
163 UTF8ToUTF16(*options->image_url)); 184 UTF8ToUTF16(*options->image_url));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 CancelById(NotificationApiDelegate::CreateScopedIdentifier( 288 CancelById(NotificationApiDelegate::CreateScopedIdentifier(
268 extension_->id(), params_->notification_id)); 289 extension_->id(), params_->notification_id));
269 290
270 SetResult(Value::CreateBooleanValue(cancel_result)); 291 SetResult(Value::CreateBooleanValue(cancel_result));
271 SendResponse(true); 292 SendResponse(true);
272 293
273 return true; 294 return true;
274 } 295 }
275 296
276 } // namespace extensions 297 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698