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> |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // app_name passed implicitly via desktop-entry. | 400 // app_name passed implicitly via desktop-entry. |
401 writer.AppendString(""); | 401 writer.AppendString(""); |
402 | 402 |
403 writer.AppendUint32(data->dbus_id); | 403 writer.AppendUint32(data->dbus_id); |
404 | 404 |
405 // app_icon passed implicitly via desktop-entry. | 405 // app_icon passed implicitly via desktop-entry. |
406 writer.AppendString(""); | 406 writer.AppendString(""); |
407 | 407 |
408 writer.AppendString(base::UTF16ToUTF8(notification->title())); | 408 writer.AppendString(base::UTF16ToUTF8(notification->title())); |
409 | 409 |
410 writer.AppendString(base::UTF16ToUTF8(notification->message())); | 410 std::string body; |
| 411 if (base::ContainsKey(capabilities_, "body")) { |
| 412 body = base::UTF16ToUTF8(notification->message()); |
| 413 if (base::ContainsKey(capabilities_, "body-markup")) { |
| 414 base::ReplaceSubstringsAfterOffset(&body, 0, "&", "&"); |
| 415 base::ReplaceSubstringsAfterOffset(&body, 0, "<", "<"); |
| 416 base::ReplaceSubstringsAfterOffset(&body, 0, ">", ">"); |
| 417 } |
| 418 } |
| 419 writer.AppendString(body); |
411 | 420 |
412 // Even-indexed elements in this vector are action IDs passed back to | 421 // Even-indexed elements in this vector are action IDs passed back to |
413 // us in OnActionInvoked(). Odd-indexed ones contain the button text. | 422 // us in OnActionInvoked(). Odd-indexed ones contain the button text. |
414 std::vector<std::string> actions; | 423 std::vector<std::string> actions; |
415 data->action_start = data->action_end; | 424 if (base::ContainsKey(capabilities_, "actions")) { |
416 for (const auto& button_info : notification->buttons()) { | 425 data->action_start = data->action_end; |
417 // FDO notification buttons can contain either an icon or a label, | 426 for (const auto& button_info : notification->buttons()) { |
418 // but not both, and the type of all buttons must be the same (all | 427 // FDO notification buttons can contain either an icon or a label, |
419 // labels or all icons), so always use labels. | 428 // but not both, and the type of all buttons must be the same (all |
420 const std::string id = base::SizeTToString(data->action_end++); | 429 // labels or all icons), so always use labels. |
421 const std::string label = base::UTF16ToUTF8(button_info.title); | 430 const std::string id = base::SizeTToString(data->action_end++); |
422 actions.push_back(id); | 431 const std::string label = base::UTF16ToUTF8(button_info.title); |
423 actions.push_back(label); | 432 actions.push_back(id); |
| 433 actions.push_back(label); |
| 434 } |
| 435 if (notification->clickable()) { |
| 436 // Special case: the pair ("default", "") will not add a button, |
| 437 // but instead makes the entire notification clickable. |
| 438 actions.push_back(kDefaultButtonId); |
| 439 actions.push_back(""); |
| 440 } |
| 441 // Always add a settings button. |
| 442 actions.push_back(kSettingsButtonId); |
| 443 // TODO(thomasanderson): Localize this string. |
| 444 actions.push_back("Settings"); |
424 } | 445 } |
425 if (notification->clickable()) { | |
426 // Special case: the pair ("default", "") will not add a button, | |
427 // but instead makes the entire notification clickable. | |
428 actions.push_back(kDefaultButtonId); | |
429 actions.push_back(""); | |
430 } | |
431 // Always add a settings button. | |
432 actions.push_back(kSettingsButtonId); | |
433 actions.push_back("Settings"); | |
434 writer.AppendArrayOfStrings(actions); | 446 writer.AppendArrayOfStrings(actions); |
435 | 447 |
436 dbus::MessageWriter hints_writer(nullptr); | 448 dbus::MessageWriter hints_writer(nullptr); |
437 writer.OpenArray("{sv}", &hints_writer); | 449 writer.OpenArray("{sv}", &hints_writer); |
438 dbus::MessageWriter urgency_writer(nullptr); | 450 dbus::MessageWriter urgency_writer(nullptr); |
439 hints_writer.OpenDictEntry(&urgency_writer); | 451 hints_writer.OpenDictEntry(&urgency_writer); |
440 urgency_writer.AppendString("urgency"); | 452 urgency_writer.AppendString("urgency"); |
441 urgency_writer.AppendVariantOfUint32( | 453 urgency_writer.AppendVariantOfUint32( |
442 NotificationPriorityToFdoUrgency(notification->priority())); | 454 NotificationPriorityToFdoUrgency(notification->priority())); |
443 hints_writer.CloseContainer(&urgency_writer); | 455 hints_writer.CloseContainer(&urgency_writer); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 ConnectionInitializationStatusCode::COULD_NOT_CONNECT_TO_SIGNALS); | 650 ConnectionInitializationStatusCode::COULD_NOT_CONNECT_TO_SIGNALS); |
639 return; | 651 return; |
640 } | 652 } |
641 connected_signals_barrier_.Run(); | 653 connected_signals_barrier_.Run(); |
642 } | 654 } |
643 | 655 |
644 void RecordMetricsForCapabilities() { | 656 void RecordMetricsForCapabilities() { |
645 // Histogram macros must be called with the same name for each | 657 // Histogram macros must be called with the same name for each |
646 // callsite, so we can't roll the below into a nice loop. | 658 // callsite, so we can't roll the below into a nice loop. |
647 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.ActionIcons", | 659 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.ActionIcons", |
648 capabilities_.count("action-icons")); | 660 base::ContainsKey(capabilities_, "action-icons")); |
649 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Actions", | 661 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Actions", |
650 capabilities_.count("actions")); | 662 base::ContainsKey(capabilities_, "actions")); |
651 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Body", | 663 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Body", |
652 capabilities_.count("body")); | 664 base::ContainsKey(capabilities_, "body")); |
653 UMA_HISTOGRAM_BOOLEAN( | 665 UMA_HISTOGRAM_BOOLEAN( |
654 "Notifications.Freedesktop.Capabilities.BodyHyperlinks", | 666 "Notifications.Freedesktop.Capabilities.BodyHyperlinks", |
655 capabilities_.count("body-hyperlinks")); | 667 base::ContainsKey(capabilities_, "body-hyperlinks")); |
656 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.BodyImages", | 668 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.BodyImages", |
657 capabilities_.count("body-images")); | 669 base::ContainsKey(capabilities_, "body-images")); |
658 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.BodyMarkup", | 670 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.BodyMarkup", |
659 capabilities_.count("body-markup")); | 671 base::ContainsKey(capabilities_, "body-markup")); |
660 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.IconMulti", | 672 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.IconMulti", |
661 capabilities_.count("icon-multi")); | 673 base::ContainsKey(capabilities_, "icon-multi")); |
662 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.IconStatic", | 674 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.IconStatic", |
663 capabilities_.count("icon-static")); | 675 base::ContainsKey(capabilities_, "icon-static")); |
664 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Persistence", | 676 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Persistence", |
665 capabilities_.count("persistence")); | 677 base::ContainsKey(capabilities_, "persistence")); |
666 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Sound", | 678 UMA_HISTOGRAM_BOOLEAN("Notifications.Freedesktop.Capabilities.Sound", |
667 capabilities_.count("sound")); | 679 base::ContainsKey(capabilities_, "sound")); |
668 } | 680 } |
669 | 681 |
670 ////////////////////////////////////////////////////////////////////////////// | 682 ////////////////////////////////////////////////////////////////////////////// |
671 // Members used only on the UI thread. | 683 // Members used only on the UI thread. |
672 | 684 |
673 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 685 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
674 | 686 |
675 content::NotificationRegistrar registrar_; | 687 content::NotificationRegistrar registrar_; |
676 | 688 |
677 // State necessary for OnConnectionInitializationFinished() and | 689 // State necessary for OnConnectionInitializationFinished() and |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 } | 748 } |
737 | 749 |
738 void NotificationPlatformBridgeLinux::SetReadyCallback( | 750 void NotificationPlatformBridgeLinux::SetReadyCallback( |
739 NotificationBridgeReadyCallback callback) { | 751 NotificationBridgeReadyCallback callback) { |
740 impl_->SetReadyCallback(std::move(callback)); | 752 impl_->SetReadyCallback(std::move(callback)); |
741 } | 753 } |
742 | 754 |
743 void NotificationPlatformBridgeLinux::CleanUp() { | 755 void NotificationPlatformBridgeLinux::CleanUp() { |
744 impl_->CleanUp(); | 756 impl_->CleanUp(); |
745 } | 757 } |
OLD | NEW |