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

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

Issue 2811183009: Linux native notifications: Add desktop-entry hint (Closed)
Patch Set: Rebase 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/nullable_string16.h" 12 #include "base/strings/nullable_string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/task_scheduler/post_task.h" 16 #include "base/task_scheduler/post_task.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/notifications/native_notification_display_service.h" 19 #include "chrome/browser/notifications/native_notification_display_service.h"
19 #include "chrome/browser/notifications/notification.h" 20 #include "chrome/browser/notifications/notification.h"
20 #include "chrome/browser/notifications/notification_display_service_factory.h" 21 #include "chrome/browser/notifications/notification_display_service_factory.h"
21 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/shell_integration_linux.h"
22 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
23 25
24 namespace { 26 namespace {
25 27
26 const char kFreedesktopNotificationsName[] = "org.freedesktop.Notifications"; 28 const char kFreedesktopNotificationsName[] = "org.freedesktop.Notifications";
27 const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications"; 29 const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications";
28 30
29 void AddActionToNotification(GVariantBuilder* actions_builder, 31 void AddActionToNotification(GVariantBuilder* actions_builder,
30 const char* action_id, 32 const char* action_id,
31 const char* button_label) { 33 const char* button_label) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if (notification.clickable()) { 370 if (notification.clickable()) {
369 // Special case: the pair ("default", "") will not add a button, 371 // Special case: the pair ("default", "") will not add a button,
370 // but instead makes the entire notification clickable. 372 // but instead makes the entire notification clickable.
371 AddActionToNotification(&actions_builder, "default", ""); 373 AddActionToNotification(&actions_builder, "default", "");
372 } 374 }
373 // Always add a settings button. 375 // Always add a settings button.
374 AddActionToNotification(&actions_builder, "settings", "Settings"); 376 AddActionToNotification(&actions_builder, "settings", "Settings");
375 377
376 GVariantBuilder hints_builder; 378 GVariantBuilder hints_builder;
377 g_variant_builder_init(&hints_builder, G_VARIANT_TYPE("a{sv}")); 379 g_variant_builder_init(&hints_builder, G_VARIANT_TYPE("a{sv}"));
380
378 g_variant_builder_add(&hints_builder, "{sv}", "urgency", 381 g_variant_builder_add(&hints_builder, "{sv}", "urgency",
379 g_variant_new_byte(NotificationPriorityToFdoUrgency( 382 g_variant_new_byte(NotificationPriorityToFdoUrgency(
380 notification.priority()))); 383 notification.priority())));
381 384
385 std::unique_ptr<base::Environment> env = base::Environment::Create();
386 std::string desktop_file = shell_integration_linux::GetDesktopName(env.get());
387 const char kDesktopFileSuffix[] = ".desktop";
388 DCHECK(base::EndsWith(desktop_file, kDesktopFileSuffix,
389 base::CompareCase::SENSITIVE));
390 desktop_file =
391 desktop_file.substr(0, desktop_file.size() - strlen(kDesktopFileSuffix));
Lei Zhang 2017/04/14 01:23:10 Alternatively, maybe make |desktop_file| a base::F
Tom (Use chromium acct) 2017/04/18 03:46:40 Done.
392 g_variant_builder_add(&hints_builder, "{sv}", "desktop-entry",
393 g_variant_new_string(desktop_file.c_str()));
394
382 if (!resource_files->icon_file.empty()) { 395 if (!resource_files->icon_file.empty()) {
383 g_variant_builder_add( 396 g_variant_builder_add(
384 &hints_builder, "{sv}", "image-path", 397 &hints_builder, "{sv}", "image-path",
385 g_variant_new_string(resource_files->icon_file.value().c_str())); 398 g_variant_new_string(resource_files->icon_file.value().c_str()));
386 data->resource_files.push_back(resource_files->icon_file); 399 data->resource_files.push_back(resource_files->icon_file);
387 resource_files->icon_file.clear(); 400 resource_files->icon_file.clear();
388 } 401 }
389 402
390 const std::string title = base::UTF16ToUTF8(notification.title()); 403 const std::string title = base::UTF16ToUTF8(notification.title());
391 const std::string message = base::UTF16ToUTF8(notification.message()); 404 const std::string message = base::UTF16ToUTF8(notification.message());
392 405
393 GVariant* parameters = 406 GVariant* parameters = g_variant_new(
394 g_variant_new("(susssasa{sv}i)", "", data->dbus_id, "", title.c_str(), 407 "(susssasa{sv}i)", "" /* app_name passed implicitly via desktop-entry */,
395 message.c_str(), &actions_builder, &hints_builder, -1); 408 data->dbus_id, "" /* app_icon passed implicitly via desktop-entry */,
409 title.c_str(), message.c_str(), &actions_builder, &hints_builder, -1);
396 g_dbus_proxy_call(notification_proxy_, "Notify", parameters, 410 g_dbus_proxy_call(notification_proxy_, "Notify", parameters,
397 G_DBUS_CALL_FLAGS_NONE, -1, data->cancellable, callback, 411 G_DBUS_CALL_FLAGS_NONE, -1, data->cancellable, callback,
398 user_data); 412 user_data);
399 } 413 }
400 414
401 void NotificationPlatformBridgeLinux::CloseNow(uint32_t dbus_id) { 415 void NotificationPlatformBridgeLinux::CloseNow(uint32_t dbus_id) {
402 g_dbus_proxy_call(notification_proxy_, "CloseNotification", 416 g_dbus_proxy_call(notification_proxy_, "CloseNotification",
403 g_variant_new("(u)", dbus_id), G_DBUS_CALL_FLAGS_NONE, -1, 417 g_variant_new("(u)", dbus_id), G_DBUS_CALL_FLAGS_NONE, -1,
404 nullptr, nullptr, nullptr); 418 nullptr, nullptr, nullptr);
405 } 419 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (!data) 497 if (!data)
484 return; 498 return;
485 size_t n_buttons = data->action_end - data->action_start; 499 size_t n_buttons = data->action_end - data->action_start;
486 if (id >= n_buttons) 500 if (id >= n_buttons)
487 return; 501 return;
488 ForwardNotificationOperation(dbus_id, NotificationCommon::CLICK, 502 ForwardNotificationOperation(dbus_id, NotificationCommon::CLICK,
489 id - data->action_start); 503 id - data->action_start);
490 } 504 }
491 } 505 }
492 } 506 }
OLDNEW
« 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