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 if (!NotificationBitmapToGfxImage(image_scale, |
| 293 bitmap_sizes.small_icon_size, |
| 294 options->small_icon_bitmap.get(), |
| 295 &optional_fields.small_image)) { |
| 296 SetError(kUnableToDecodeIconError); |
| 297 return false; |
| 298 } |
| 299 } |
| 300 |
291 if (options->priority.get()) | 301 if (options->priority.get()) |
292 optional_fields.priority = *options->priority; | 302 optional_fields.priority = *options->priority; |
293 | 303 |
294 if (options->event_time.get()) | 304 if (options->event_time.get()) |
295 optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); | 305 optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); |
296 | 306 |
297 if (options->buttons.get()) { | 307 if (options->buttons.get()) { |
298 // Currently we allow up to 2 buttons. | 308 // Currently we allow up to 2 buttons. |
299 size_t number_of_buttons = options->buttons->size(); | 309 size_t number_of_buttons = options->buttons->size(); |
300 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; | 310 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)); | 408 notification->set_message(base::UTF8ToUTF16(*options->message)); |
399 | 409 |
400 // TODO(dewittj): Return error if this fails. | 410 // TODO(dewittj): Return error if this fails. |
401 if (options->icon_bitmap) { | 411 if (options->icon_bitmap) { |
402 gfx::Image icon; | 412 gfx::Image icon; |
403 NotificationBitmapToGfxImage( | 413 NotificationBitmapToGfxImage( |
404 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); | 414 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); |
405 notification->set_icon(icon); | 415 notification->set_icon(icon); |
406 } | 416 } |
407 | 417 |
| 418 gfx::Image small_icon; |
| 419 if (NotificationBitmapToGfxImage(image_scale, |
| 420 bitmap_sizes.small_icon_size, |
| 421 options->small_icon_bitmap.get(), |
| 422 &small_icon)) { |
| 423 notification->set_small_image(small_icon); |
| 424 } |
| 425 |
408 if (options->priority) | 426 if (options->priority) |
409 notification->set_priority(*options->priority); | 427 notification->set_priority(*options->priority); |
410 | 428 |
411 if (options->event_time) | 429 if (options->event_time) |
412 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); | 430 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); |
413 | 431 |
414 if (options->buttons) { | 432 if (options->buttons) { |
415 // Currently we allow up to 2 buttons. | 433 // Currently we allow up to 2 buttons. |
416 size_t number_of_buttons = options->buttons->size(); | 434 size_t number_of_buttons = options->buttons->size(); |
417 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; | 435 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 | 687 ? api::notifications::PERMISSION_LEVEL_GRANTED |
670 : api::notifications::PERMISSION_LEVEL_DENIED; | 688 : api::notifications::PERMISSION_LEVEL_DENIED; |
671 | 689 |
672 SetResult(new base::StringValue(api::notifications::ToString(result))); | 690 SetResult(new base::StringValue(api::notifications::ToString(result))); |
673 SendResponse(true); | 691 SendResponse(true); |
674 | 692 |
675 return true; | 693 return true; |
676 } | 694 } |
677 | 695 |
678 } // namespace extensions | 696 } // namespace extensions |
OLD | NEW |