Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: chrome/browser/notifications/sync_notifier/synced_notification.cc

Issue 149433005: Adds a small icon to notifications, and connects it to synced notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add testing. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 GetOriginUrl(), 327 GetOriginUrl(),
320 notification_heading, 328 notification_heading,
321 notification_text, 329 notification_text,
322 icon_bitmap, 330 icon_bitmap,
323 blink::WebTextDirectionDefault, 331 blink::WebTextDirectionDefault,
324 message_center::NotifierId(GetOriginUrl()), 332 message_center::NotifierId(GetOriginUrl()),
325 display_source, 333 display_source,
326 replace_key, 334 replace_key,
327 rich_notification_data, 335 rich_notification_data,
328 delegate.get()); 336 delegate.get());
337 if (!app_icon_bitmap_.IsEmpty()) {
Pete Williamson 2014/01/30 00:00:21 Nit: It would be nice to move this change to line
dewittj 2014/01/30 00:41:56 Done.
338 // Since we can't control the size of images we download, resize using a
339 // high quality filter down to the appropriate icon size.
340 // TODO(dewittj): Remove this when correct resources are sent via the
341 // protobuf.
342 SkBitmap new_app_icon =
343 skia::ImageOperations::Resize(app_icon_bitmap_.AsBitmap(),
344 skia::ImageOperations::RESIZE_BEST,
345 message_center::kSmallImageSize,
346 message_center::kSmallImageSize);
347
348 // The app icon should be in grayscale.
349 // TODO(dewittj): Remove this when correct resources are sent via the
350 // protobuf.
351 color_utils::HSL shift = {-1, 0, 0.6};
352 SkBitmap grayscale =
353 SkBitmapOperations::CreateHSLShiftedBitmap(new_app_icon, shift);
354 gfx::Image small_image =
355 gfx::Image(gfx::ImageSkia(gfx::ImageSkiaRep(grayscale, 1.0f)));
356 ui_notification.set_small_image(small_image);
357 }
329 358
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(),
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698