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

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

Issue 2876603004: Linux native notifications: Add attribution (Closed)
Patch Set: Rebase 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
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 <unordered_map> 10 #include <unordered_map>
(...skipping 12 matching lines...) Expand all
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/task_scheduler/post_task.h" 24 #include "base/task_scheduler/post_task.h"
25 #include "base/version.h" 25 #include "base/version.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/notifications/native_notification_display_service.h" 28 #include "chrome/browser/notifications/native_notification_display_service.h"
29 #include "chrome/browser/notifications/notification.h" 29 #include "chrome/browser/notifications/notification.h"
30 #include "chrome/browser/notifications/notification_display_service_factory.h" 30 #include "chrome/browser/notifications/notification_display_service_factory.h"
31 #include "chrome/browser/profiles/profile_manager.h" 31 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/browser/shell_integration_linux.h" 32 #include "chrome/browser/shell_integration_linux.h"
33 #include "components/url_formatter/elide_url.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
35 #include "dbus/bus.h" 36 #include "dbus/bus.h"
36 #include "dbus/message.h" 37 #include "dbus/message.h"
37 #include "dbus/object_proxy.h" 38 #include "dbus/object_proxy.h"
38 #include "skia/ext/image_operations.h" 39 #include "skia/ext/image_operations.h"
39 #include "ui/gfx/image/image_skia.h" 40 #include "ui/gfx/image/image_skia.h"
40 41
41 namespace { 42 namespace {
42 43
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 std::unique_ptr<ResourceFile> image_file = WriteDataToTmpFile( 516 std::unique_ptr<ResourceFile> image_file = WriteDataToTmpFile(
516 ResizeImageToFdoMaxSize(notification->image()).As1xPNGBytes()); 517 ResizeImageToFdoMaxSize(notification->image()).As1xPNGBytes());
517 if (image_file) { 518 if (image_file) {
518 if (!body.empty()) 519 if (!body.empty())
519 body += "\n"; 520 body += "\n";
520 body += 521 body +=
521 "<img src=\"" + image_file->file_path().value() + "\" alt=\"\"/>"; 522 "<img src=\"" + image_file->file_path().value() + "\" alt=\"\"/>";
522 data->resource_files.push_back(std::move(image_file)); 523 data->resource_files.push_back(std::move(image_file));
523 } 524 }
524 } 525 }
526
527 // Attribute this notification to the origin, if any.
528 if (!notification->origin_url().is_empty()) {
529 if (!body.empty())
530 body += "\n";
531 std::string url_display_text =
532 base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay(
533 notification->origin_url(),
534 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS));
535 std::string spec = notification->origin_url().spec();
536 if (base::ContainsKey(capabilities_, "body-hyperlinks")) {
537 body += "<a href=\"" + spec + "\">" + url_display_text + "</a>";
538 } else {
539 body += url_display_text;
540 }
541 }
525 } 542 }
526 writer.AppendString(body); 543 writer.AppendString(body);
527 544
528 // Even-indexed elements in this vector are action IDs passed back to 545 // Even-indexed elements in this vector are action IDs passed back to
529 // us in OnActionInvoked(). Odd-indexed ones contain the button text. 546 // us in OnActionInvoked(). Odd-indexed ones contain the button text.
530 std::vector<std::string> actions; 547 std::vector<std::string> actions;
531 if (base::ContainsKey(capabilities_, "actions")) { 548 if (base::ContainsKey(capabilities_, "actions")) {
532 data->action_start = data->action_end; 549 data->action_start = data->action_end;
533 for (const auto& button_info : notification->buttons()) { 550 for (const auto& button_info : notification->buttons()) {
534 // FDO notification buttons can contain either an icon or a label, 551 // FDO notification buttons can contain either an icon or a label,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 } 885 }
869 886
870 void NotificationPlatformBridgeLinux::SetReadyCallback( 887 void NotificationPlatformBridgeLinux::SetReadyCallback(
871 NotificationBridgeReadyCallback callback) { 888 NotificationBridgeReadyCallback callback) {
872 impl_->SetReadyCallback(std::move(callback)); 889 impl_->SetReadyCallback(std::move(callback));
873 } 890 }
874 891
875 void NotificationPlatformBridgeLinux::CleanUp() { 892 void NotificationPlatformBridgeLinux::CleanUp() {
876 impl_->CleanUp(); 893 impl_->CleanUp();
877 } 894 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698