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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "ui/gfx/image/image_skia_rep.h" | 27 #include "ui/gfx/image/image_skia_rep.h" |
28 #include "ui/message_center/message_center_style.h" | 28 #include "ui/message_center/message_center_style.h" |
29 #include "ui/message_center/message_center_util.h" | 29 #include "ui/message_center/message_center_util.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kResultKey[] = "result"; | 36 const char kResultKey[] = "result"; |
| 37 const char kUnexpectedProgressValueForNonProgressType[] = |
| 38 "The progress value should not be specified for non-progress notification"; |
| 39 const char kInvalidProgressValue[] = |
| 40 "The progress value should range from 0 to 100"; |
37 | 41 |
38 // Converts an object with width, height, and data in RGBA format into an | 42 // Converts an object with width, height, and data in RGBA format into an |
39 // gfx::Image (in ARGB format). | 43 // gfx::Image (in ARGB format). |
40 bool NotificationBitmapToGfxImage( | 44 bool NotificationBitmapToGfxImage( |
41 api::notifications::NotificationBitmap* notification_bitmap, | 45 api::notifications::NotificationBitmap* notification_bitmap, |
42 gfx::Image* return_image) { | 46 gfx::Image* return_image) { |
43 if (!notification_bitmap) | 47 if (!notification_bitmap) |
44 return false; | 48 return false; |
45 | 49 |
46 // Ensure a sane set of dimensions. | 50 // Ensure a sane set of dimensions. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 &optional_fields.image); | 273 &optional_fields.image); |
270 // We should have an image if and only if the type is an image type. | 274 // We should have an image if and only if the type is an image type. |
271 if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) | 275 if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) |
272 return false; | 276 return false; |
273 | 277 |
274 // We should have list items if and only if the type is a multiple type. | 278 // We should have list items if and only if the type is a multiple type. |
275 bool has_list_items = options->items.get() && options->items->size() > 0; | 279 bool has_list_items = options->items.get() && options->items->size() > 0; |
276 if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE)) | 280 if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE)) |
277 return false; | 281 return false; |
278 | 282 |
| 283 if (options->progress.get() != NULL) { |
| 284 // We should have progress if and only if the type is a progress type. |
| 285 if (type != message_center::NOTIFICATION_TYPE_PROGRESS) { |
| 286 SetError(kUnexpectedProgressValueForNonProgressType); |
| 287 return false; |
| 288 } |
| 289 optional_fields.progress = *options->progress; |
| 290 // Progress value should range from 0 to 100. |
| 291 if (optional_fields.progress < 0 || optional_fields.progress > 100) { |
| 292 SetError(kInvalidProgressValue); |
| 293 return false; |
| 294 } |
| 295 } |
| 296 |
279 if (has_list_items) { | 297 if (has_list_items) { |
280 using api::notifications::NotificationItem; | 298 using api::notifications::NotificationItem; |
281 std::vector<linked_ptr<NotificationItem> >::iterator i; | 299 std::vector<linked_ptr<NotificationItem> >::iterator i; |
282 for (i = options->items->begin(); i != options->items->end(); ++i) { | 300 for (i = options->items->begin(); i != options->items->end(); ++i) { |
283 message_center::NotificationItem item(UTF8ToUTF16(i->get()->title), | 301 message_center::NotificationItem item(UTF8ToUTF16(i->get()->title), |
284 UTF8ToUTF16(i->get()->message)); | 302 UTF8ToUTF16(i->get()->message)); |
285 optional_fields.items.push_back(item); | 303 optional_fields.items.push_back(item); |
286 } | 304 } |
287 } | 305 } |
288 } | 306 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 NotificationsApiFunction::MapApiTemplateTypeToType( | 344 NotificationsApiFunction::MapApiTemplateTypeToType( |
327 api::notifications::TemplateType type) { | 345 api::notifications::TemplateType type) { |
328 switch (type) { | 346 switch (type) { |
329 case api::notifications::TEMPLATE_TYPE_NONE: | 347 case api::notifications::TEMPLATE_TYPE_NONE: |
330 case api::notifications::TEMPLATE_TYPE_BASIC: | 348 case api::notifications::TEMPLATE_TYPE_BASIC: |
331 return message_center::NOTIFICATION_TYPE_BASE_FORMAT; | 349 return message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
332 case api::notifications::TEMPLATE_TYPE_IMAGE: | 350 case api::notifications::TEMPLATE_TYPE_IMAGE: |
333 return message_center::NOTIFICATION_TYPE_IMAGE; | 351 return message_center::NOTIFICATION_TYPE_IMAGE; |
334 case api::notifications::TEMPLATE_TYPE_LIST: | 352 case api::notifications::TEMPLATE_TYPE_LIST: |
335 return message_center::NOTIFICATION_TYPE_MULTIPLE; | 353 return message_center::NOTIFICATION_TYPE_MULTIPLE; |
| 354 case api::notifications::TEMPLATE_TYPE_PROGRESS: |
| 355 return message_center::NOTIFICATION_TYPE_PROGRESS; |
336 default: | 356 default: |
337 // Gracefully handle newer application code that is running on an older | 357 // Gracefully handle newer application code that is running on an older |
338 // runtime that doesn't recognize the requested template. | 358 // runtime that doesn't recognize the requested template. |
339 return message_center::NOTIFICATION_TYPE_BASE_FORMAT; | 359 return message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
340 } | 360 } |
341 } | 361 } |
342 | 362 |
343 const char kNotificationPrefix[] = "extensions.api."; | 363 const char kNotificationPrefix[] = "extensions.api."; |
344 | 364 |
345 static uint64 next_id_ = 0; | 365 static uint64 next_id_ = 0; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 StripScopeFromIdentifier(extension_->id(), *iter), true); | 470 StripScopeFromIdentifier(extension_->id(), *iter), true); |
451 } | 471 } |
452 | 472 |
453 SetResult(result.release()); | 473 SetResult(result.release()); |
454 SendResponse(true); | 474 SendResponse(true); |
455 | 475 |
456 return true; | 476 return true; |
457 } | 477 } |
458 | 478 |
459 } // namespace extensions | 479 } // namespace extensions |
OLD | NEW |