Chromium Code Reviews| Index: chrome/browser/notifications/notification_platform_bridge_linux.cc |
| diff --git a/chrome/browser/notifications/notification_platform_bridge_linux.cc b/chrome/browser/notifications/notification_platform_bridge_linux.cc |
| index a5b8c3a971459e21c342758b7859a4c95fe71dc4..77f73a92b8cd647fe0f5e13482f05937d028e243 100644 |
| --- a/chrome/browser/notifications/notification_platform_bridge_linux.cc |
| +++ b/chrome/browser/notifications/notification_platform_bridge_linux.cc |
| @@ -31,6 +31,7 @@ |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/shell_integration_linux.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "components/url_formatter/elide_url.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_service.h" |
| #include "dbus/bus.h" |
| @@ -127,6 +128,12 @@ gfx::Image DeepCopyImage(const gfx::Image& image) { |
| return gfx::Image(*image_skia); |
| } |
| +void EscapeBodyText(std::string* text) { |
| + base::ReplaceSubstringsAfterOffset(text, 0, "&", "&"); |
| + base::ReplaceSubstringsAfterOffset(text, 0, "<", "<"); |
| + base::ReplaceSubstringsAfterOffset(text, 0, ">", ">"); |
| +} |
| + |
| int NotificationPriorityToFdoUrgency(int priority) { |
| enum FdoUrgency { |
| LOW = 0, |
| @@ -151,6 +158,7 @@ int NotificationPriorityToFdoUrgency(int priority) { |
| // the image does not need to be resized, or the image is empty, |
| // returns |image| directly. |
| gfx::Image ResizeImageToFdoMaxSize(const gfx::Image& image) { |
| + DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| if (image.IsEmpty()) |
| return image; |
| int width = image.Width(); |
| @@ -534,12 +542,31 @@ class NotificationPlatformBridgeLinuxImpl |
| if (base::ContainsKey(capabilities_, kCapabilityBody)) { |
| const bool body_markup = |
| base::ContainsKey(capabilities_, kCapabilityBodyMarkup); |
| + |
| + if (notification->UseOriginAsContextMessage()) { |
| + std::string url_display_text = |
| + base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( |
| + notification->origin_url(), |
| + url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS)); |
| + std::string spec = notification->origin_url().spec(); |
|
Lei Zhang
2017/05/15 22:19:59
Do we know if the origin URL is guaranteed to be v
Peter Beverloo
2017/05/15 22:43:26
Yes. UseOriginAsContextMessage() verifies this.
|
| + if (base::ContainsKey(capabilities_, kCapabilityBodyHyperlinks)) { |
| + body << "<a href=\"" << spec << "\">" << url_display_text << "</a>"; |
| + } else { |
| + body << url_display_text; |
| + } |
| + } else if (!notification->context_message().empty()) { |
| + std::string context = |
| + base::UTF16ToUTF8(notification->context_message()); |
| + if (body_markup) |
| + EscapeBodyText(&context); |
|
Peter Beverloo
2017/05/15 22:43:26
Is it possible for |body_markup| to be FALSE but k
Tom (Use chromium acct)
2017/05/16 04:43:34
no. body-hyperlinks => body-markup
|
| + body << context; |
| + } |
| + |
| std::string message = base::UTF16ToUTF8(notification->message()); |
| - if (body_markup) { |
| - base::ReplaceSubstringsAfterOffset(&message, 0, "&", "&"); |
| - base::ReplaceSubstringsAfterOffset(&message, 0, "<", "<"); |
| - base::ReplaceSubstringsAfterOffset(&message, 0, ">", ">"); |
| - } |
| + if (body_markup) |
| + EscapeBodyText(&message); |
| + if (body.size()) |
| + body << "\n"; |
| body << message; |
| if (notification->type() == message_center::NOTIFICATION_TYPE_MULTIPLE) { |