Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_linux.cc

Issue 2876603004: Linux native notifications: Add attribution (Closed)
Patch Set: Address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <sstream> 10 #include <sstream>
(...skipping 14 matching lines...) Expand all
25 #include "base/task_scheduler/post_task.h" 25 #include "base/task_scheduler/post_task.h"
26 #include "base/version.h" 26 #include "base/version.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chrome_notification_types.h" 28 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/notifications/native_notification_display_service.h" 29 #include "chrome/browser/notifications/native_notification_display_service.h"
30 #include "chrome/browser/notifications/notification.h" 30 #include "chrome/browser/notifications/notification.h"
31 #include "chrome/browser/notifications/notification_display_service_factory.h" 31 #include "chrome/browser/notifications/notification_display_service_factory.h"
32 #include "chrome/browser/profiles/profile_manager.h" 32 #include "chrome/browser/profiles/profile_manager.h"
33 #include "chrome/browser/shell_integration_linux.h" 33 #include "chrome/browser/shell_integration_linux.h"
34 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
35 #include "components/url_formatter/elide_url.h"
35 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "dbus/bus.h" 38 #include "dbus/bus.h"
38 #include "dbus/message.h" 39 #include "dbus/message.h"
39 #include "dbus/object_proxy.h" 40 #include "dbus/object_proxy.h"
40 #include "net/base/escape.h" 41 #include "net/base/escape.h"
41 #include "skia/ext/image_operations.h" 42 #include "skia/ext/image_operations.h"
42 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
43 #include "ui/gfx/image/image_skia.h" 44 #include "ui/gfx/image/image_skia.h"
44 45
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 NOTREACHED(); 130 NOTREACHED();
130 case message_center::DEFAULT_PRIORITY: 131 case message_center::DEFAULT_PRIORITY:
131 return NORMAL; 132 return NORMAL;
132 } 133 }
133 } 134 }
134 135
135 // Constrain |image|'s size to |kMaxImageWidth|x|kMaxImageHeight|. If 136 // Constrain |image|'s size to |kMaxImageWidth|x|kMaxImageHeight|. If
136 // the image does not need to be resized, or the image is empty, 137 // the image does not need to be resized, or the image is empty,
137 // returns |image| directly. 138 // returns |image| directly.
138 gfx::Image ResizeImageToFdoMaxSize(const gfx::Image& image) { 139 gfx::Image ResizeImageToFdoMaxSize(const gfx::Image& image) {
140 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
139 if (image.IsEmpty()) 141 if (image.IsEmpty())
140 return image; 142 return image;
141 int width = image.Width(); 143 int width = image.Width();
142 int height = image.Height(); 144 int height = image.Height();
143 if (width <= kMaxImageWidth && height <= kMaxImageHeight) { 145 if (width <= kMaxImageWidth && height <= kMaxImageHeight) {
144 return image; 146 return image;
145 } 147 }
146 const SkBitmap* image_bitmap = image.ToSkBitmap(); 148 const SkBitmap* image_bitmap = image.ToSkBitmap();
147 double scale = std::min(static_cast<double>(kMaxImageWidth) / width, 149 double scale = std::min(static_cast<double>(kMaxImageWidth) / width,
148 static_cast<double>(kMaxImageHeight) / height); 150 static_cast<double>(kMaxImageHeight) / height);
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // app_icon passed implicitly via desktop-entry. 514 // app_icon passed implicitly via desktop-entry.
513 writer.AppendString(""); 515 writer.AppendString("");
514 516
515 writer.AppendString( 517 writer.AppendString(
516 base::UTF16ToUTF8(CreateNotificationTitle(*notification))); 518 base::UTF16ToUTF8(CreateNotificationTitle(*notification)));
517 519
518 std::ostringstream body; 520 std::ostringstream body;
519 if (base::ContainsKey(capabilities_, kCapabilityBody)) { 521 if (base::ContainsKey(capabilities_, kCapabilityBody)) {
520 const bool body_markup = 522 const bool body_markup =
521 base::ContainsKey(capabilities_, kCapabilityBodyMarkup); 523 base::ContainsKey(capabilities_, kCapabilityBodyMarkup);
524
525 if (notification->UseOriginAsContextMessage()) {
526 std::string url_display_text = net::EscapeForHTML(
527 base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay(
528 notification->origin_url(),
529 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS)));
530 if (base::ContainsKey(capabilities_, kCapabilityBodyHyperlinks)) {
531 body << "<a href=\""
532 << net::EscapePath(notification->origin_url().spec()) << "\">"
533 << url_display_text << "</a>";
534 } else {
535 body << url_display_text;
536 }
537 } else if (!notification->context_message().empty()) {
538 std::string context =
539 base::UTF16ToUTF8(notification->context_message());
540 if (body_markup)
541 context = net::EscapeForHTML(context);
542 body << context;
543 }
544
522 std::string message = base::UTF16ToUTF8(notification->message()); 545 std::string message = base::UTF16ToUTF8(notification->message());
523 if (body_markup) { 546 if (body_markup)
524 base::ReplaceSubstringsAfterOffset(&message, 0, "&", "&amp;"); 547 message = net::EscapeForHTML(message);
525 base::ReplaceSubstringsAfterOffset(&message, 0, "<", "&lt;"); 548 if (body.tellp())
526 base::ReplaceSubstringsAfterOffset(&message, 0, ">", "&gt;"); 549 body << "\n";
527 }
528 body << message; 550 body << message;
529 551
530 if (notification->type() == message_center::NOTIFICATION_TYPE_MULTIPLE) { 552 if (notification->type() == message_center::NOTIFICATION_TYPE_MULTIPLE) {
531 for (const auto& item : notification->items()) { 553 for (const auto& item : notification->items()) {
532 if (body.tellp()) 554 if (body.tellp())
533 body << "\n"; 555 body << "\n";
534 const std::string title = base::UTF16ToUTF8(item.title); 556 const std::string title = base::UTF16ToUTF8(item.title);
535 const std::string message = base::UTF16ToUTF8(item.message); 557 const std::string message = base::UTF16ToUTF8(item.message);
536 // TODO(peter): Figure out the right way to internationalize 558 // TODO(peter): Figure out the right way to internationalize
537 // this for RTL languages. 559 // this for RTL languages.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 } 926 }
905 927
906 void NotificationPlatformBridgeLinux::SetReadyCallback( 928 void NotificationPlatformBridgeLinux::SetReadyCallback(
907 NotificationBridgeReadyCallback callback) { 929 NotificationBridgeReadyCallback callback) {
908 impl_->SetReadyCallback(std::move(callback)); 930 impl_->SetReadyCallback(std::move(callback));
909 } 931 }
910 932
911 void NotificationPlatformBridgeLinux::CleanUp() { 933 void NotificationPlatformBridgeLinux::CleanUp() {
912 impl_->CleanUp(); 934 impl_->CleanUp();
913 } 935 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698