#include "chrome/browser/notifications/notification_platform_bridge_linux.h"
#include <algorithm>
#include <memory>
#include <set>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/barrier_closure.h"
#include "base/callback_list.h"
#include "base/containers/contains.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_path_watcher.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_file.h"
#include "base/functional/bind.h"
#include "base/i18n/number_formatting.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/version.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/termination_notification.h"
#include "chrome/browser/notifications/notification_display_service_impl.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/notifications/notification_operation.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "chrome/grit/generated_resources.h"
#include "components/dbus/thread_linux/dbus_thread_linux.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "skia/ext/image_operations.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/message_center/public/cpp/notification.h"
#include "url/origin.h"
namespace {
const char kFreedesktopNotificationsName[] = …;
const char kFreedesktopNotificationsPath[] = …;
const char kMethodCloseNotification[] = …;
const char kMethodGetCapabilities[] = …;
const char kMethodListActivatableNames[] = …;
const char kMethodNameHasOwner[] = …;
const char kMethodNotify[] = …;
const char kMethodStartServiceByName[] = …;
const char kSignalActionInvoked[] = …;
const char kSignalNotificationClosed[] = …;
const char kSignalNotificationReplied[] = …;
const char kCapabilityActions[] = …;
const char kCapabilityBody[] = …;
const char kCapabilityBodyHyperlinks[] = …;
const char kCapabilityBodyImages[] = …;
const char kCapabilityBodyMarkup[] = …;
const char kCapabilityInlineReply[] = …;
const char kCapabilityPersistence[] = …;
const char kCapabilityXKdeOriginName[] = …;
const char kCapabilityXKdeReplyPlaceholderText[] = …;
const char kCloseButtonId[] = …;
const char kDefaultButtonId[] = …;
const char kInlineReplyButtonId[] = …;
const char kSettingsButtonId[] = …;
const int kMaxImageWidth = …;
const int kMaxImageHeight = …;
constexpr base::TimeDelta kStartServiceTimeout = …;
const int32_t kExpireTimeout = …;
const size_t kMaxAllowedOriginLength = …;
enum FdoUrgency { … };
enum class ConnectionInitializationStatusCode { … };
std::u16string CreateNotificationTitle(
const message_center::Notification& notification) { … }
void EscapeUnsafeCharacters(std::string* message) { … }
int NotificationPriorityToFdoUrgency(int priority) { … }
gfx::Image ResizeImageToFdoMaxSize(const gfx::Image& image) { … }
bool ShouldAddCloseButton(const std::string& server_name,
const base::Version& server_version) { … }
bool ShouldMarkPersistentNotificationsAsCritical(
const std::string& server_name) { … }
void ForwardNotificationOperationOnUiThread(
NotificationOperation operation,
NotificationHandler::Type notification_type,
const GURL& origin,
const std::string& notification_id,
const std::optional<int>& action_index,
const std::optional<bool>& by_user,
const std::optional<std::u16string>& reply,
const std::string& profile_id,
bool is_incognito) { … }
base::ScopedTempFile WriteDataToTmpFile(
const scoped_refptr<base::RefCountedMemory>& data) { … }
bool CheckNotificationsNameHasOwnerOrIsActivatable(dbus::Bus* bus) { … }
}
std::unique_ptr<NotificationPlatformBridge>
NotificationPlatformBridge::Create() { … }
bool NotificationPlatformBridge::CanHandleType(
NotificationHandler::Type notification_type) { … }
class NotificationPlatformBridgeLinuxImpl
: public NotificationPlatformBridge,
public base::RefCountedThreadSafe<NotificationPlatformBridgeLinuxImpl> { … };
NotificationPlatformBridgeLinux::NotificationPlatformBridgeLinux()
: … { … }
NotificationPlatformBridgeLinux::NotificationPlatformBridgeLinux(
scoped_refptr<dbus::Bus> bus)
: … { … }
NotificationPlatformBridgeLinux::~NotificationPlatformBridgeLinux() = default;
void NotificationPlatformBridgeLinux::Display(
NotificationHandler::Type notification_type,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) { … }
void NotificationPlatformBridgeLinux::Close(
Profile* profile,
const std::string& notification_id) { … }
void NotificationPlatformBridgeLinux::GetDisplayed(
Profile* profile,
GetDisplayedNotificationsCallback callback) const { … }
void NotificationPlatformBridgeLinux::GetDisplayedForOrigin(
Profile* profile,
const GURL& origin,
GetDisplayedNotificationsCallback callback) const { … }
void NotificationPlatformBridgeLinux::SetReadyCallback(
NotificationBridgeReadyCallback callback) { … }
void NotificationPlatformBridgeLinux::DisplayServiceShutDown(Profile* profile) { … }
void NotificationPlatformBridgeLinux::CleanUp() { … }