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 (capabilities_.count("body")) { | |
Lei Zhang
2017/05/06 00:29:34
base::ContainsKey(capabilities_, key) here and bel
Tom (Use chromium acct)
2017/05/08 21:12:39
Done.
| |
412 body = base::UTF16ToUTF8(notification->message()); | |
413 if (capabilities_.count("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 (capabilities_.count("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 actions.push_back("Settings"); | |
Lei Zhang
2017/05/06 00:29:34
Was this the one where I was asking about localiza
Tom (Use chromium acct)
2017/05/08 21:12:39
Done.
| |
424 } | 444 } |
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); | 445 writer.AppendArrayOfStrings(actions); |
435 | 446 |
436 dbus::MessageWriter hints_writer(nullptr); | 447 dbus::MessageWriter hints_writer(nullptr); |
437 writer.OpenArray("{sv}", &hints_writer); | 448 writer.OpenArray("{sv}", &hints_writer); |
438 dbus::MessageWriter urgency_writer(nullptr); | 449 dbus::MessageWriter urgency_writer(nullptr); |
439 hints_writer.OpenDictEntry(&urgency_writer); | 450 hints_writer.OpenDictEntry(&urgency_writer); |
440 urgency_writer.AppendString("urgency"); | 451 urgency_writer.AppendString("urgency"); |
441 urgency_writer.AppendVariantOfUint32( | 452 urgency_writer.AppendVariantOfUint32( |
442 NotificationPriorityToFdoUrgency(notification->priority())); | 453 NotificationPriorityToFdoUrgency(notification->priority())); |
443 hints_writer.CloseContainer(&urgency_writer); | 454 hints_writer.CloseContainer(&urgency_writer); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 } | 747 } |
737 | 748 |
738 void NotificationPlatformBridgeLinux::SetReadyCallback( | 749 void NotificationPlatformBridgeLinux::SetReadyCallback( |
739 NotificationBridgeReadyCallback callback) { | 750 NotificationBridgeReadyCallback callback) { |
740 impl_->SetReadyCallback(std::move(callback)); | 751 impl_->SetReadyCallback(std::move(callback)); |
741 } | 752 } |
742 | 753 |
743 void NotificationPlatformBridgeLinux::CleanUp() { | 754 void NotificationPlatformBridgeLinux::CleanUp() { |
744 impl_->CleanUp(); | 755 impl_->CleanUp(); |
745 } | 756 } |
OLD | NEW |