| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/notification_platform_bridge_linux.h" | 5 #include "chrome/browser/notifications/notification_platform_bridge_linux.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/barrier_closure.h" | 15 #include "base/barrier_closure.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/i18n/number_formatting.h" |
| 17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/strings/nullable_string16.h" | 19 #include "base/strings/nullable_string16.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/task_scheduler/post_task.h" | 24 #include "base/task_scheduler/post_task.h" |
| 24 #include "base/version.h" | 25 #include "base/version.h" |
| 25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 50 // added at the end, before NUM_ITEMS. | 51 // added at the end, before NUM_ITEMS. |
| 51 enum class ConnectionInitializationStatusCode { | 52 enum class ConnectionInitializationStatusCode { |
| 52 SUCCESS = 0, | 53 SUCCESS = 0, |
| 53 NATIVE_NOTIFICATIONS_NOT_SUPPORTED = 1, | 54 NATIVE_NOTIFICATIONS_NOT_SUPPORTED = 1, |
| 54 MISSING_REQUIRED_CAPABILITIES = 2, | 55 MISSING_REQUIRED_CAPABILITIES = 2, |
| 55 COULD_NOT_CONNECT_TO_SIGNALS = 3, | 56 COULD_NOT_CONNECT_TO_SIGNALS = 3, |
| 56 INCOMPATIBLE_SPEC_VERSION = 4, | 57 INCOMPATIBLE_SPEC_VERSION = 4, |
| 57 NUM_ITEMS | 58 NUM_ITEMS |
| 58 }; | 59 }; |
| 59 | 60 |
| 61 base::string16 CreateNotificationTitle(const Notification& notification) { |
| 62 base::string16 title; |
| 63 if (notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) { |
| 64 title += base::FormatPercent(notification.progress()); |
| 65 title += base::UTF8ToUTF16(" - "); |
| 66 } |
| 67 title += notification.title(); |
| 68 return title; |
| 69 } |
| 70 |
| 60 gfx::Image DeepCopyImage(const gfx::Image& image) { | 71 gfx::Image DeepCopyImage(const gfx::Image& image) { |
| 61 if (image.IsEmpty()) | 72 if (image.IsEmpty()) |
| 62 return gfx::Image(); | 73 return gfx::Image(); |
| 63 std::unique_ptr<gfx::ImageSkia> image_skia(image.CopyImageSkia()); | 74 std::unique_ptr<gfx::ImageSkia> image_skia(image.CopyImageSkia()); |
| 64 return gfx::Image(*image_skia); | 75 return gfx::Image(*image_skia); |
| 65 } | 76 } |
| 66 | 77 |
| 67 int NotificationPriorityToFdoUrgency(int priority) { | 78 int NotificationPriorityToFdoUrgency(int priority) { |
| 68 enum FdoUrgency { | 79 enum FdoUrgency { |
| 69 LOW = 0, | 80 LOW = 0, |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 dbus::MessageWriter writer(&method_call); | 436 dbus::MessageWriter writer(&method_call); |
| 426 | 437 |
| 427 // app_name passed implicitly via desktop-entry. | 438 // app_name passed implicitly via desktop-entry. |
| 428 writer.AppendString(""); | 439 writer.AppendString(""); |
| 429 | 440 |
| 430 writer.AppendUint32(data->dbus_id); | 441 writer.AppendUint32(data->dbus_id); |
| 431 | 442 |
| 432 // app_icon passed implicitly via desktop-entry. | 443 // app_icon passed implicitly via desktop-entry. |
| 433 writer.AppendString(""); | 444 writer.AppendString(""); |
| 434 | 445 |
| 435 writer.AppendString(base::UTF16ToUTF8(notification->title())); | 446 writer.AppendString( |
| 447 base::UTF16ToUTF8(CreateNotificationTitle(*notification))); |
| 436 | 448 |
| 437 std::string body; | 449 std::string body; |
| 438 if (base::ContainsKey(capabilities_, "body")) { | 450 if (base::ContainsKey(capabilities_, "body")) { |
| 439 body = base::UTF16ToUTF8(notification->message()); | 451 body = base::UTF16ToUTF8(notification->message()); |
| 440 if (base::ContainsKey(capabilities_, "body-markup")) { | 452 if (base::ContainsKey(capabilities_, "body-markup")) { |
| 441 base::ReplaceSubstringsAfterOffset(&body, 0, "&", "&"); | 453 base::ReplaceSubstringsAfterOffset(&body, 0, "&", "&"); |
| 442 base::ReplaceSubstringsAfterOffset(&body, 0, "<", "<"); | 454 base::ReplaceSubstringsAfterOffset(&body, 0, "<", "<"); |
| 443 base::ReplaceSubstringsAfterOffset(&body, 0, ">", ">"); | 455 base::ReplaceSubstringsAfterOffset(&body, 0, ">", ">"); |
| 444 } | 456 } |
| 445 } | 457 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 } | 792 } |
| 781 | 793 |
| 782 void NotificationPlatformBridgeLinux::SetReadyCallback( | 794 void NotificationPlatformBridgeLinux::SetReadyCallback( |
| 783 NotificationBridgeReadyCallback callback) { | 795 NotificationBridgeReadyCallback callback) { |
| 784 impl_->SetReadyCallback(std::move(callback)); | 796 impl_->SetReadyCallback(std::move(callback)); |
| 785 } | 797 } |
| 786 | 798 |
| 787 void NotificationPlatformBridgeLinux::CleanUp() { | 799 void NotificationPlatformBridgeLinux::CleanUp() { |
| 788 impl_->CleanUp(); | 800 impl_->CleanUp(); |
| 789 } | 801 } |
| OLD | NEW |