| 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/notifications/sync_notifier/synced_notification.h" | 5 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 15 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" | 16 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" |
| 16 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 17 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "skia/ext/image_operations.h" |
| 18 #include "sync/protocol/sync.pb.h" | 20 #include "sync/protocol/sync.pb.h" |
| 19 #include "sync/protocol/synced_notification_specifics.pb.h" | 21 #include "sync/protocol/synced_notification_specifics.pb.h" |
| 22 #include "third_party/skia/include/core/SkPaint.h" |
| 23 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/color_utils.h" |
| 20 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 26 #include "ui/gfx/size.h" |
| 27 #include "ui/gfx/skbitmap_operations.h" |
| 28 #include "ui/message_center/message_center_style.h" |
| 21 #include "ui/message_center/message_center_util.h" | 29 #include "ui/message_center/message_center_util.h" |
| 22 #include "ui/message_center/notification_types.h" | 30 #include "ui/message_center/notification_types.h" |
| 23 | 31 |
| 24 namespace { | 32 namespace { |
| 25 const char kExtensionScheme[] = "synced-notification://"; | 33 const char kExtensionScheme[] = "synced-notification://"; |
| 26 const char kDefaultSyncedNotificationScheme[] = "https:"; | 34 const char kDefaultSyncedNotificationScheme[] = "https:"; |
| 27 | 35 |
| 28 // Today rich notifications only supports two buttons, make sure we don't | 36 // Today rich notifications only supports two buttons, make sure we don't |
| 29 // try to supply them with more than this number of buttons. | 37 // try to supply them with more than this number of buttons. |
| 30 const unsigned int kMaxNotificationButtonIndex = 2; | 38 const unsigned int kMaxNotificationButtonIndex = 2; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 message_center::ButtonInfo button_info(base::UTF8ToUTF16(title)); | 305 message_center::ButtonInfo button_info(base::UTF8ToUTF16(title)); |
| 298 if (!button_bitmaps_[i].IsEmpty()) | 306 if (!button_bitmaps_[i].IsEmpty()) |
| 299 button_info.icon = button_bitmaps_[i]; | 307 button_info.icon = button_bitmaps_[i]; |
| 300 rich_notification_data.buttons.push_back(button_info); | 308 rich_notification_data.buttons.push_back(button_info); |
| 301 } | 309 } |
| 302 | 310 |
| 303 // Fill in the bitmap images. | 311 // Fill in the bitmap images. |
| 304 if (!image_bitmap_.IsEmpty()) | 312 if (!image_bitmap_.IsEmpty()) |
| 305 rich_notification_data.image = image_bitmap_; | 313 rich_notification_data.image = image_bitmap_; |
| 306 | 314 |
| 315 if (!app_icon_bitmap_.IsEmpty()) { |
| 316 // Since we can't control the size of images we download, resize using a |
| 317 // high quality filter down to the appropriate icon size. |
| 318 // TODO(dewittj): Remove this when correct resources are sent via the |
| 319 // protobuf. |
| 320 SkBitmap new_app_icon = |
| 321 skia::ImageOperations::Resize(app_icon_bitmap_.AsBitmap(), |
| 322 skia::ImageOperations::RESIZE_BEST, |
| 323 message_center::kSmallImageSize, |
| 324 message_center::kSmallImageSize); |
| 325 |
| 326 // The app icon should be in grayscale. |
| 327 // TODO(dewittj): Remove this when correct resources are sent via the |
| 328 // protobuf. |
| 329 color_utils::HSL shift = {-1, 0, 0.6}; |
| 330 SkBitmap grayscale = |
| 331 SkBitmapOperations::CreateHSLShiftedBitmap(new_app_icon, shift); |
| 332 gfx::Image small_image = |
| 333 gfx::Image(gfx::ImageSkia(gfx::ImageSkiaRep(grayscale, 1.0f))); |
| 334 rich_notification_data.small_image = small_image; |
| 335 } |
| 336 |
| 307 // Set the ContextMessage inside the rich notification data for the | 337 // Set the ContextMessage inside the rich notification data for the |
| 308 // annotation. | 338 // annotation. |
| 309 rich_notification_data.context_message = annotation; | 339 rich_notification_data.context_message = annotation; |
| 310 | 340 |
| 311 // If there is at least one person sending, use the first picture. | 341 // If there is at least one person sending, use the first picture. |
| 312 // TODO(petewil): Someday combine multiple profile photos here. | 342 // TODO(petewil): Someday combine multiple profile photos here. |
| 313 gfx::Image icon_bitmap = app_icon_bitmap_; | 343 gfx::Image icon_bitmap = app_icon_bitmap_; |
| 314 if (GetProfilePictureCount() >= 1) { | 344 if (GetProfilePictureCount() >= 1) { |
| 315 icon_bitmap = sender_bitmap_; | 345 icon_bitmap = sender_bitmap_; |
| 316 } | 346 } |
| 317 | 347 |
| 318 Notification ui_notification(notification_type, | 348 Notification ui_notification(notification_type, |
| 319 GetOriginUrl(), | 349 GetOriginUrl(), |
| 320 notification_heading, | 350 notification_heading, |
| 321 notification_text, | 351 notification_text, |
| 322 icon_bitmap, | 352 icon_bitmap, |
| 323 blink::WebTextDirectionDefault, | 353 blink::WebTextDirectionDefault, |
| 324 message_center::NotifierId(GetOriginUrl()), | 354 message_center::NotifierId(GetOriginUrl()), |
| 325 display_source, | 355 display_source, |
| 326 replace_key, | 356 replace_key, |
| 327 rich_notification_data, | 357 rich_notification_data, |
| 328 delegate.get()); | 358 delegate.get()); |
| 329 | |
| 330 // In case the notification is not supposed to be toasted, pretend that it | 359 // In case the notification is not supposed to be toasted, pretend that it |
| 331 // has already been shown. | 360 // has already been shown. |
| 332 ui_notification.set_shown_as_popup(!toast_state_); | 361 ui_notification.set_shown_as_popup(!toast_state_); |
| 333 | 362 |
| 334 notification_manager->Add(ui_notification, profile); | 363 notification_manager->Add(ui_notification, profile); |
| 335 } else { | 364 } else { |
| 336 // In this case we have a Webkit Notification, not a Rich Notification. | 365 // In this case we have a Webkit Notification, not a Rich Notification. |
| 337 Notification ui_notification(GetOriginUrl(), | 366 Notification ui_notification(GetOriginUrl(), |
| 338 GetAppIconUrl(), | 367 GetAppIconUrl(), |
| 339 notification_heading, | 368 notification_heading, |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 752 |
| 724 const gfx::Image& SyncedNotification::GetAppIcon() const { | 753 const gfx::Image& SyncedNotification::GetAppIcon() const { |
| 725 return app_icon_bitmap_; | 754 return app_icon_bitmap_; |
| 726 } | 755 } |
| 727 | 756 |
| 728 void SyncedNotification::SetToastState(bool toast_state) { | 757 void SyncedNotification::SetToastState(bool toast_state) { |
| 729 toast_state_ = toast_state; | 758 toast_state_ = toast_state; |
| 730 } | 759 } |
| 731 | 760 |
| 732 } // namespace notifier | 761 } // namespace notifier |
| OLD | NEW |