OLD | NEW |
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/notifications/notifications_api.h" | 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/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" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Ignore options if running on the old notification runtime. | 146 // Ignore options if running on the old notification runtime. |
147 scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); | 147 scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); |
148 | 148 |
149 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( | 149 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( |
150 this, | 150 this, |
151 profile(), | 151 profile(), |
152 extension_->id(), | 152 extension_->id(), |
153 id)); // ownership is passed to Notification | 153 id)); // ownership is passed to Notification |
154 Notification notification(type, extension_->url(), icon_url, title, message, | 154 Notification notification(type, extension_->url(), icon_url, title, message, |
155 WebKit::WebTextDirectionDefault, | 155 WebKit::WebTextDirectionDefault, |
156 string16(), UTF8ToUTF16(api_delegate->id()), | 156 UTF8ToUTF16(extension_->name()), |
| 157 UTF8ToUTF16(api_delegate->id()), |
157 optional_fields.get(), api_delegate); | 158 optional_fields.get(), api_delegate); |
158 | 159 |
159 g_browser_process->notification_ui_manager()->Add(notification, profile()); | 160 g_browser_process->notification_ui_manager()->Add(notification, profile()); |
160 } | 161 } |
161 #else // defined(ENABLE_MESSAGE_CENTER) | 162 #else // defined(ENABLE_MESSAGE_CENTER) |
162 void NotificationsApiFunction::CreateNotification( | 163 void NotificationsApiFunction::CreateNotification( |
163 const std::string& id, | 164 const std::string& id, |
164 api::notifications::NotificationOptions* options) { | 165 api::notifications::NotificationOptions* options) { |
165 message_center::NotificationType type = | 166 message_center::NotificationType type = |
166 MapApiTemplateTypeToType(options->type); | 167 MapApiTemplateTypeToType(options->type); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 optional_fields->Set(message_center::kItemsKey, items); | 228 optional_fields->Set(message_center::kItemsKey, items); |
228 } | 229 } |
229 | 230 |
230 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( | 231 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( |
231 this, | 232 this, |
232 profile(), | 233 profile(), |
233 extension_->id(), | 234 extension_->id(), |
234 id)); // ownership is passed to Notification | 235 id)); // ownership is passed to Notification |
235 Notification notification(type, extension_->url(), icon_url, title, message, | 236 Notification notification(type, extension_->url(), icon_url, title, message, |
236 WebKit::WebTextDirectionDefault, | 237 WebKit::WebTextDirectionDefault, |
237 string16(), UTF8ToUTF16(api_delegate->id()), | 238 UTF8ToUTF16(extension_->name()), |
| 239 UTF8ToUTF16(api_delegate->id()), |
238 optional_fields.get(), api_delegate); | 240 optional_fields.get(), api_delegate); |
239 | 241 |
240 g_browser_process->notification_ui_manager()->Add(notification, profile()); | 242 g_browser_process->notification_ui_manager()->Add(notification, profile()); |
241 } | 243 } |
242 #endif // !defined(ENABLE_MESSAGE_CENTER) | 244 #endif // !defined(ENABLE_MESSAGE_CENTER) |
243 | 245 |
244 bool NotificationsApiFunction::IsNotificationsApiEnabled() { | 246 bool NotificationsApiFunction::IsNotificationsApiEnabled() { |
245 DesktopNotificationService* service = | 247 DesktopNotificationService* service = |
246 DesktopNotificationServiceFactory::GetForProfile(profile()); | 248 DesktopNotificationServiceFactory::GetForProfile(profile()); |
247 return service->IsExtensionEnabled(extension_->id()); | 249 return service->IsExtensionEnabled(extension_->id()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 CancelById(NotificationsApiDelegate::CreateScopedIdentifier( | 351 CancelById(NotificationsApiDelegate::CreateScopedIdentifier( |
350 extension_->id(), params_->notification_id)); | 352 extension_->id(), params_->notification_id)); |
351 | 353 |
352 SetResult(Value::CreateBooleanValue(cancel_result)); | 354 SetResult(Value::CreateBooleanValue(cancel_result)); |
353 SendResponse(true); | 355 SendResponse(true); |
354 | 356 |
355 return true; | 357 return true; |
356 } | 358 } |
357 | 359 |
358 } // namespace extensions | 360 } // namespace extensions |
OLD | NEW |