diff options
author | mvanouwerkerk <mvanouwerkerk@chromium.org> | 2016-03-18 03:21:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 10:22:44 +0000 |
commit | 2dc0200c983a414b1ec462b5fe6fee0076e67231 (patch) | |
tree | 43ada4a72196aa026a0140a05632b707fe7d7cc4 /content/browser/notifications | |
parent | 13a22831538b2559f9951d213ece253352863804 (diff) | |
download | chromium_src-2dc0200c983a414b1ec462b5fe6fee0076e67231.zip chromium_src-2dc0200c983a414b1ec462b5fe6fee0076e67231.tar.gz chromium_src-2dc0200c983a414b1ec462b5fe6fee0076e67231.tar.bz2 |
Add badge to web notifications.
* This is guarded by the NotificationBadge runtime flag.
* On Android M+ the badge is displayed in the status bar,
otherwise Chrome falls back to the default Chrome icon.
* On all Android versions the badge is displayed in the notification.
* Not quite correct on desktop yet (it conflicts with the settings button).
* Screenshots: https://imgur.com/a/wewTP
* Spec discussion: https://github.com/whatwg/notifications/issues/65
* Spec PR: https://github.com/mvano/notifications/commit/d79fe317ccc00dc7e27dde88928dc33bcf38e5b4
* Intent to implement and ship: https://goo.gl/4KwzyR
BUG=591394
Review URL: https://codereview.chromium.org/1750083004
Cr-Commit-Position: refs/heads/master@{#381927}
Diffstat (limited to 'content/browser/notifications')
4 files changed, 11 insertions, 1 deletions
diff --git a/content/browser/notifications/notification_database_data.proto b/content/browser/notifications/notification_database_data.proto index d47f5d9..7044ed2 100644 --- a/content/browser/notifications/notification_database_data.proto +++ b/content/browser/notifications/notification_database_data.proto @@ -30,7 +30,7 @@ message NotificationDatabaseDataProto { // Actual data payload of the notification. This message is the protocol // buffer meant to serialize the content::PlatformNotificationData structure. // - // Next tag: 14 + // Next tag: 15 message NotificationData { enum Direction { LEFT_TO_RIGHT = 0; @@ -44,6 +44,7 @@ message NotificationDatabaseDataProto { optional string body = 4; optional string tag = 5; optional string icon = 6; + optional string badge = 14; repeated int32 vibration_pattern = 9 [packed=true]; optional int64 timestamp = 12; optional bool renotify = 13; diff --git a/content/browser/notifications/notification_database_data_conversions.cc b/content/browser/notifications/notification_database_data_conversions.cc index ce4c75c..5da5aae 100644 --- a/content/browser/notifications/notification_database_data_conversions.cc +++ b/content/browser/notifications/notification_database_data_conversions.cc @@ -51,6 +51,7 @@ bool DeserializeNotificationDatabaseData(const std::string& input, notification_data->body = base::UTF8ToUTF16(payload.body()); notification_data->tag = payload.tag(); notification_data->icon = GURL(payload.icon()); + notification_data->badge = GURL(payload.badge()); if (payload.vibration_pattern().size() > 0) { notification_data->vibration_pattern.assign( @@ -109,6 +110,7 @@ bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, payload->set_body(base::UTF16ToUTF8(notification_data.body)); payload->set_tag(notification_data.tag); payload->set_icon(notification_data.icon.spec()); + payload->set_badge(notification_data.badge.spec()); for (size_t i = 0; i < notification_data.vibration_pattern.size(); ++i) payload->add_vibration_pattern(notification_data.vibration_pattern[i]); diff --git a/content/browser/notifications/notification_database_data_unittest.cc b/content/browser/notifications/notification_database_data_unittest.cc index 94b94b8..a07a5f5 100644 --- a/content/browser/notifications/notification_database_data_unittest.cc +++ b/content/browser/notifications/notification_database_data_unittest.cc @@ -27,6 +27,7 @@ const char kNotificationLang[] = "nl"; const char kNotificationBody[] = "Hello, world!"; const char kNotificationTag[] = "my_tag"; const char kNotificationIconUrl[] = "https://example.com/icon.png"; +const char kNotificationBadgeUrl[] = "https://example.com/badge.png"; const char kNotificationActionIconUrl[] = "https://example.com/action_icon.png"; const int kNotificationVibrationPattern[] = {100, 200, 300}; const double kNotificationTimestamp = 621046800.; @@ -48,6 +49,7 @@ TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) { notification_data.body = base::ASCIIToUTF16(kNotificationBody); notification_data.tag = kNotificationTag; notification_data.icon = GURL(kNotificationIconUrl); + notification_data.badge = GURL(kNotificationBadgeUrl); notification_data.vibration_pattern = vibration_pattern; notification_data.timestamp = base::Time::FromJsTime(kNotificationTimestamp); notification_data.renotify = true; @@ -94,6 +96,7 @@ TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) { EXPECT_EQ(notification_data.body, copied_notification_data.body); EXPECT_EQ(notification_data.tag, copied_notification_data.tag); EXPECT_EQ(notification_data.icon, copied_notification_data.icon); + EXPECT_EQ(notification_data.badge, copied_notification_data.badge); EXPECT_THAT(copied_notification_data.vibration_pattern, testing::ElementsAreArray(kNotificationVibrationPattern)); diff --git a/content/browser/notifications/notification_message_filter.cc b/content/browser/notifications/notification_message_filter.cc index f0a64a7..0829750 100644 --- a/content/browser/notifications/notification_message_filter.cc +++ b/content/browser/notifications/notification_message_filter.cc @@ -53,6 +53,10 @@ bool ValidateNotificationResources(const NotificationResources& resources) { kPlatformNotificationMaxIconSizePx) { return false; } + if (resources.badge.width() > kPlatformNotificationMaxBadgeSizePx || + resources.badge.height() > kPlatformNotificationMaxBadgeSizePx) { + return false; + } for (const auto& action_icon : resources.action_icons) { if (action_icon.width() > kPlatformNotificationMaxActionIconSizePx || action_icon.height() > kPlatformNotificationMaxActionIconSizePx) { |