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

Unified Diff: chrome/browser/notifications/notification_platform_bridge_linux.cc

Issue 2814973002: Linux native notifications: Add support for custom notification buttons (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ed8f4bc9406133dbead14d2e0b7e4e0c1bc58aaf..a24248586520851fdd8ba74eb10ca5dbddc51a91 100644
--- a/chrome/browser/notifications/notification_platform_bridge_linux.cc
+++ b/chrome/browser/notifications/notification_platform_bridge_linux.cc
@@ -10,6 +10,7 @@
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/nullable_string16.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_scheduler/post_task.h"
#include "chrome/browser/browser_process.h"
@@ -176,6 +177,11 @@ struct NotificationPlatformBridgeLinux::NotificationData {
// NativeNotificationDisplayService.
const GURL origin_url;
+ // Used to keep track of the IDs of the buttons currently displayed
+ // on this notification.
+ size_t action_start = 0;
+ size_t action_end = 0;
+
// Temporary resource files associated with the notification that
// should be cleaned up when the notification is closed.
std::vector<base::FilePath> resource_files;
@@ -331,6 +337,15 @@ void NotificationPlatformBridgeLinux::NotifyNow(
// Even-indexed elements in this array are action IDs passed back to
// us in GSignalReceiver. Odd-indexed ones contain the button text.
g_variant_builder_init(&actions_builder, G_VARIANT_TYPE("as"));
+ data->action_start = data->action_end;
+ for (const auto& button_info : notification.buttons()) {
+ // FDO notification buttons can contain either an icon or a label,
+ // but not both, and the type of all buttons must be the same (all
+ // labels or all icons), so always use labels.
+ std::string id = base::SizeTToString(data->action_end++);
+ const std::string label = base::UTF16ToUTF8(button_info.title);
+ AddActionToNotification(&actions_builder, id.c_str(), label.c_str());
Peter Beverloo 2017/04/12 00:44:22 Are we concerned about the OS passing us invalid b
Tom (Use chromium acct) 2017/04/13 02:23:34 No, but I wanted to handle this case: 1. Notificat
+ }
if (notification.clickable()) {
// Special case: the pair ("default", "") will not add a button,
// but instead makes the entire notification clickable.
@@ -438,11 +453,21 @@ void NotificationPlatformBridgeLinux::GSignalReceiver(GDBusProxy* proxy,
DCHECK(action);
if (strcmp(action, "default") == 0) {
- ForwardNotificationOperation(dbus_id, NotificationCommon::CLICK, 0);
+ ForwardNotificationOperation(dbus_id, NotificationCommon::CLICK, -1);
} else if (strcmp(action, "settings") == 0) {
ForwardNotificationOperation(dbus_id, NotificationCommon::SETTINGS, -1);
} else {
- NOTIMPLEMENTED() << "No custom buttons just yet!";
+ size_t id;
+ if (!base::StringToSizeT(action, &id))
+ return;
+ NotificationData* data = FindNotificationData(dbus_id);
+ if (!data)
+ return;
+ size_t n_buttons = data->action_end - data->action_start;
+ if (id >= n_buttons)
+ return;
+ ForwardNotificationOperation(dbus_id, NotificationCommon::CLICK,
+ id - data->action_start);
}
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698