Chromium Code Reviews| 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/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 if (!NotificationBitmapToGfxImage(image_scale, | 281 if (!NotificationBitmapToGfxImage(image_scale, |
| 282 bitmap_sizes.icon_size, | 282 bitmap_sizes.icon_size, |
| 283 options->icon_bitmap.get(), | 283 options->icon_bitmap.get(), |
| 284 &icon)) { | 284 &icon)) { |
| 285 SetError(kUnableToDecodeIconError); | 285 SetError(kUnableToDecodeIconError); |
| 286 return false; | 286 return false; |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Then, handle any optional data that's been provided. | 289 // Then, handle any optional data that's been provided. |
| 290 message_center::RichNotificationData optional_fields; | 290 message_center::RichNotificationData optional_fields; |
| 291 if (options->small_icon_url.get()) { | |
| 292 NotificationBitmapToGfxImage(image_scale, | |
|
dewittj
2014/06/09 21:30:58
We should handle the case where this returns false
liyanhou
2014/06/16 16:56:59
Done.
| |
| 293 bitmap_sizes.small_icon_size, | |
| 294 options->small_icon_bitmap.get(), | |
| 295 &optional_fields.small_image); | |
| 296 } | |
| 297 | |
| 291 if (options->priority.get()) | 298 if (options->priority.get()) |
| 292 optional_fields.priority = *options->priority; | 299 optional_fields.priority = *options->priority; |
| 293 | 300 |
| 294 if (options->event_time.get()) | 301 if (options->event_time.get()) |
| 295 optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); | 302 optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); |
| 296 | 303 |
| 297 if (options->buttons.get()) { | 304 if (options->buttons.get()) { |
| 298 // Currently we allow up to 2 buttons. | 305 // Currently we allow up to 2 buttons. |
| 299 size_t number_of_buttons = options->buttons->size(); | 306 size_t number_of_buttons = options->buttons->size(); |
| 300 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; | 307 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 notification->set_message(base::UTF8ToUTF16(*options->message)); | 405 notification->set_message(base::UTF8ToUTF16(*options->message)); |
| 399 | 406 |
| 400 // TODO(dewittj): Return error if this fails. | 407 // TODO(dewittj): Return error if this fails. |
| 401 if (options->icon_bitmap) { | 408 if (options->icon_bitmap) { |
| 402 gfx::Image icon; | 409 gfx::Image icon; |
| 403 NotificationBitmapToGfxImage( | 410 NotificationBitmapToGfxImage( |
| 404 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); | 411 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); |
| 405 notification->set_icon(icon); | 412 notification->set_icon(icon); |
| 406 } | 413 } |
| 407 | 414 |
| 415 gfx::Image small_icon; | |
| 416 if (NotificationBitmapToGfxImage(image_scale, | |
| 417 bitmap_sizes.small_icon_size, | |
| 418 options->small_icon_bitmap.get(), | |
| 419 &small_icon)) { | |
| 420 notification->set_small_image(small_icon); | |
| 421 } | |
| 422 | |
| 408 if (options->priority) | 423 if (options->priority) |
| 409 notification->set_priority(*options->priority); | 424 notification->set_priority(*options->priority); |
| 410 | 425 |
| 411 if (options->event_time) | 426 if (options->event_time) |
| 412 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); | 427 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); |
| 413 | 428 |
| 414 if (options->buttons) { | 429 if (options->buttons) { |
| 415 // Currently we allow up to 2 buttons. | 430 // Currently we allow up to 2 buttons. |
| 416 size_t number_of_buttons = options->buttons->size(); | 431 size_t number_of_buttons = options->buttons->size(); |
| 417 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; | 432 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 ? api::notifications::PERMISSION_LEVEL_GRANTED | 684 ? api::notifications::PERMISSION_LEVEL_GRANTED |
| 670 : api::notifications::PERMISSION_LEVEL_DENIED; | 685 : api::notifications::PERMISSION_LEVEL_DENIED; |
| 671 | 686 |
| 672 SetResult(new base::StringValue(api::notifications::ToString(result))); | 687 SetResult(new base::StringValue(api::notifications::ToString(result))); |
| 673 SendResponse(true); | 688 SendResponse(true); |
| 674 | 689 |
| 675 return true; | 690 return true; |
| 676 } | 691 } |
| 677 | 692 |
| 678 } // namespace extensions | 693 } // namespace extensions |
| OLD | NEW |