Commit 2cca330c authored by James Cook's avatar James Cook Committed by Commit Bot

lacros: Message center support for simple notifications

Add mojo interface for communication between ash and lacros. For now,
just add the fields needed for simple text notifications.

Notifications are handled in a new class MessageCenterAsh. It lives
in //chrome/browser/chromeos/crosapi instead of //c/b/notifications
for consistency with other crosapi implementations.

On mojo disconnect (e.g. lacros-chrome crash) all notifications
created by lacros are removed.

I'm working on tests now. They are not in this CL because this CL
is getting too large.

Test: Spawn basic notifications from test app Notifications Galore
      in chrome/test/data/extensions/api_test/notifications/galore/
Bug: 1113889

Change-Id: I6363b0e7568756b9087f089651a7fdc6d0901902
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343849Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Auto-Submit: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797969}
parent bed786cf
......@@ -4064,6 +4064,7 @@ static_library("browser") {
# TODO(crbug.com/1052397): Rename chromeos_is_browser_only to is_lacros.
if (chromeos_is_browser_only) {
assert(enable_native_notifications)
sources += [
"chrome_browser_main_extra_parts_lacros.cc",
"chrome_browser_main_extra_parts_lacros.h",
......@@ -4071,11 +4072,11 @@ static_library("browser") {
"lacros/lacros_chrome_service_delegate_impl.h",
"metrics/lacros_metrics_provider.cc",
"metrics/lacros_metrics_provider.h",
"notifications/message_center_client_lacros.cc",
"notifications/message_center_client_lacros.h",
"notifications/notification_platform_bridge_chromeos.cc",
"notifications/notification_platform_bridge_chromeos.h",
"notifications/notification_platform_bridge_delegate.h",
"notifications/notification_platform_bridge_lacros.cc",
"notifications/notification_platform_bridge_lacros.h",
]
deps += [
"//chromeos/crosapi/mojom",
......
......@@ -942,6 +942,8 @@ source_set("chromeos") {
"crosapi/browser_manager.h",
"crosapi/browser_util.cc",
"crosapi/browser_util.h",
"crosapi/message_center_ash.cc",
"crosapi/message_center_ash.h",
"crosapi/screen_manager_crosapi.cc",
"crosapi/screen_manager_crosapi.h",
"crosapi/select_file_ash.cc",
......
specific_include_rules = {
"message_center_ash\.cc": [
# Provides a mojo interface around the message center, but lives in this
# directory for consistency with other crosapi classes.
"-chrome",
"+chrome/browser/chromeos/crosapi",
"+ui/message_center/message_center.h",
],
"screen_manager_crosapi\.cc": [
# For window parenting.
"+ash/shell.h",
......
......@@ -10,9 +10,11 @@
#include "base/logging.h"
#include "chrome/browser/chromeos/crosapi/attestation_ash.h"
#include "chrome/browser/chromeos/crosapi/message_center_ash.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_crosapi.h"
#include "chrome/browser/chromeos/crosapi/select_file_ash.h"
#include "chromeos/crosapi/mojom/attestation.mojom.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
......@@ -35,6 +37,11 @@ void AshChromeServiceImpl::BindAttestation(
std::make_unique<crosapi::AttestationAsh>(std::move(receiver));
}
void AshChromeServiceImpl::BindMessageCenter(
mojo::PendingReceiver<mojom::MessageCenter> receiver) {
message_center_ash_ = std::make_unique<MessageCenterAsh>(std::move(receiver));
}
void AshChromeServiceImpl::BindSelectFile(
mojo::PendingReceiver<mojom::SelectFile> receiver) {
select_file_crosapi_ = std::make_unique<SelectFileAsh>(std::move(receiver));
......
......@@ -16,6 +16,7 @@ class ScreenManagerCrosapi;
namespace crosapi {
class AttestationAsh;
class MessageCenterAsh;
class SelectFileAsh;
// Implementation of AshChromeService. It provides a set of APIs that
......@@ -28,7 +29,9 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
// crosapi::mojom::AshChromeService:
void BindAttestation(
mojo::PendingReceiver<crosapi::mojom::Attestation> receiver) override;
mojo::PendingReceiver<mojom::Attestation> receiver) override;
void BindMessageCenter(
mojo::PendingReceiver<mojom::MessageCenter> receiver) override;
void BindScreenManager(
mojo::PendingReceiver<mojom::ScreenManager> receiver) override;
void BindSelectFile(
......@@ -37,7 +40,8 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
private:
mojo::Receiver<mojom::AshChromeService> receiver_;
std::unique_ptr<crosapi::AttestationAsh> attestation_ash_;
std::unique_ptr<AttestationAsh> attestation_ash_;
std::unique_ptr<MessageCenterAsh> message_center_ash_;
std::unique_ptr<ScreenManagerCrosapi> screen_manager_crosapi_;
std::unique_ptr<SelectFileAsh> select_file_crosapi_;
};
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/crosapi/message_center_ash.h"
#include <utility>
#include "base/bind.h"
#include "base/check.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/optional.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "chromeos/crosapi/mojom/notification.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h"
#include "url/gurl.h"
namespace mc = message_center;
namespace crosapi {
namespace {
mc::NotificationType FromMojo(mojom::NotificationType type) {
switch (type) {
case mojom::NotificationType::kSimple:
return mc::NOTIFICATION_TYPE_SIMPLE;
case mojom::NotificationType::kImage:
return mc::NOTIFICATION_TYPE_IMAGE;
case mojom::NotificationType::kList:
return mc::NOTIFICATION_TYPE_MULTIPLE;
case mojom::NotificationType::kProgress:
return mc::NOTIFICATION_TYPE_PROGRESS;
}
}
// Forwards NotificationDelegate methods to a remote delegate over mojo. If the
// remote delegate disconnects (e.g. lacros-chrome crashes) the corresponding
// notification will be removed.
class ForwardingDelegate : public message_center::NotificationDelegate {
public:
ForwardingDelegate(const std::string& notification_id,
mojo::PendingRemote<mojom::NotificationDelegate> delegate)
: notification_id_(notification_id),
remote_delegate_(std::move(delegate)) {
DCHECK(!notification_id_.empty());
DCHECK(remote_delegate_);
}
ForwardingDelegate(const ForwardingDelegate&) = delete;
ForwardingDelegate& operator=(const ForwardingDelegate&) = delete;
void Init() {
// Cannot be done in constructor because base::BindOnce() requires a
// non-zero reference count.
remote_delegate_.set_disconnect_handler(
base::BindOnce(&ForwardingDelegate::OnDisconnect, this));
}
private:
// Private due to ref-counting.
~ForwardingDelegate() override = default;
void OnDisconnect() {
// NOTE: Triggers a call to Close() if the notification is still showing.
mc::MessageCenter::Get()->RemoveNotification(notification_id_,
/*by_user=*/false);
}
// message_center::NotificationDelegate:
void Close(bool by_user) override {
// Can be called after |remote_delegate_| is disconnected.
if (remote_delegate_)
remote_delegate_->OnNotificationClosed(by_user);
}
void Click(const base::Optional<int>& button_index,
const base::Optional<base::string16>& reply) override {
if (button_index) {
// Chrome OS does not support inline reply. The button index comes out of
// trusted ash-side message center UI code and is guaranteed not to be
// negative.
remote_delegate_->OnNotificationButtonClicked(
base::checked_cast<uint32_t>(*button_index));
} else {
remote_delegate_->OnNotificationClicked();
}
}
void SettingsClick() override {
remote_delegate_->OnNotificationSettingsButtonClicked();
}
void DisableNotification() override {
remote_delegate_->OnNotificationDisabled();
}
const std::string notification_id_;
mojo::Remote<mojom::NotificationDelegate> remote_delegate_;
};
} // namespace
MessageCenterAsh::MessageCenterAsh(
mojo::PendingReceiver<mojom::MessageCenter> receiver)
: receiver_(this, std::move(receiver)) {}
MessageCenterAsh::~MessageCenterAsh() = default;
void MessageCenterAsh::DisplayNotification(
mojom::NotificationPtr notification,
mojo::PendingRemote<mojom::NotificationDelegate> delegate) {
auto forwarding_delegate = base::MakeRefCounted<ForwardingDelegate>(
notification->id, std::move(delegate));
forwarding_delegate->Init();
// TODO(crbug.com/1113889): Icon support.
// TODO(crbug.com/1113889): NotifierId support.
// TODO(crbug.com/1113889): RichNotificationData support.
mc::MessageCenter::Get()->AddNotification(std::make_unique<mc::Notification>(
FromMojo(notification->type), notification->id, notification->title,
notification->message, gfx::Image(), notification->display_source,
notification->origin_url.value_or(GURL()), mc::NotifierId(),
mc::RichNotificationData(), std::move(forwarding_delegate)));
}
void MessageCenterAsh::CloseNotification(const std::string& id) {
mc::MessageCenter::Get()->RemoveNotification(id, /*by_user=*/false);
}
} // namespace crosapi
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_MESSAGE_CENTER_ASH_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_MESSAGE_CENTER_ASH_H_
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace crosapi {
// Implements the crosapi message center interface. Lives in ash-chrome on the
// UI thread. Shows notifications in response to mojo IPCs from lacros-chrome.
// Sends reply IPCs when the user interacts with the notifications.
class MessageCenterAsh : public mojom::MessageCenter {
public:
explicit MessageCenterAsh(
mojo::PendingReceiver<mojom::MessageCenter> receiver);
MessageCenterAsh(const MessageCenterAsh&) = delete;
MessageCenterAsh& operator=(const MessageCenterAsh&) = delete;
~MessageCenterAsh() override;
// crosapi::mojom::MessageCenter:
void DisplayNotification(
mojom::NotificationPtr notification,
mojo::PendingRemote<mojom::NotificationDelegate> delegate) override;
void CloseNotification(const std::string& id) override;
private:
mojo::Receiver<mojom::MessageCenter> receiver_;
};
} // namespace crosapi
#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_MESSAGE_CENTER_ASH_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/notifications/message_center_client_lacros.h"
#include <utility>
#include "base/check.h"
#include "base/notreached.h"
MessageCenterClientLacros::MessageCenterClientLacros(
NotificationPlatformBridgeDelegate* delegate)
: delegate_(delegate) {
DCHECK(delegate_);
}
MessageCenterClientLacros::~MessageCenterClientLacros() = default;
void MessageCenterClientLacros::Display(
NotificationHandler::Type notification_type,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
NOTIMPLEMENTED();
}
void MessageCenterClientLacros::Close(Profile* profile,
const std::string& notification_id) {
NOTIMPLEMENTED();
}
void MessageCenterClientLacros::GetDisplayed(
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
NOTIMPLEMENTED();
std::move(callback).Run(/*notification_ids=*/{}, /*supports_sync=*/false);
}
void MessageCenterClientLacros::SetReadyCallback(
NotificationBridgeReadyCallback callback) {
NOTIMPLEMENTED();
std::move(callback).Run(true);
}
void MessageCenterClientLacros::DisplayServiceShutDown(Profile* profile) {
NOTIMPLEMENTED();
}
......@@ -18,7 +18,7 @@
#include "ui/gfx/image/image.h"
#if BUILDFLAG(IS_LACROS)
#include "chrome/browser/notifications/message_center_client_lacros.h"
#include "chrome/browser/notifications/notification_platform_bridge_lacros.h"
#else
#include "chrome/browser/notifications/chrome_ash_message_center_client.h"
#endif
......@@ -37,7 +37,7 @@ bool NotificationPlatformBridge::CanHandleType(
NotificationPlatformBridgeChromeOs::NotificationPlatformBridgeChromeOs() {
#if BUILDFLAG(IS_LACROS)
impl_ = std::make_unique<MessageCenterClientLacros>(this);
impl_ = std::make_unique<NotificationPlatformBridgeLacros>(this);
#else
impl_ = std::make_unique<ChromeAshMessageCenterClient>(this);
#endif
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/notifications/notification_platform_bridge_lacros.h"
#include <utility>
#include "base/check.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/optional.h"
#include "chrome/browser/notifications/notification_platform_bridge_delegate.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "chromeos/crosapi/mojom/notification.mojom.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_types.h"
namespace {
crosapi::mojom::NotificationType ToMojo(message_center::NotificationType type) {
switch (type) {
case message_center::NOTIFICATION_TYPE_SIMPLE:
case message_center::NOTIFICATION_TYPE_BASE_FORMAT:
// TYPE_BASE_FORMAT is displayed the same as TYPE_SIMPLE.
return crosapi::mojom::NotificationType::kSimple;
case message_center::NOTIFICATION_TYPE_IMAGE:
return crosapi::mojom::NotificationType::kImage;
case message_center::NOTIFICATION_TYPE_MULTIPLE:
return crosapi::mojom::NotificationType::kList;
case message_center::NOTIFICATION_TYPE_PROGRESS:
return crosapi::mojom::NotificationType::kProgress;
case message_center::NOTIFICATION_TYPE_CUSTOM:
// TYPE_CUSTOM exists only within ash.
NOTREACHED();
return crosapi::mojom::NotificationType::kSimple;
}
}
} // namespace
// Keeps track of notifications being displayed in the remote message center.
class NotificationPlatformBridgeLacros::RemoteNotificationDelegate
: public crosapi::mojom::NotificationDelegate {
public:
RemoteNotificationDelegate(
const std::string& notification_id,
NotificationPlatformBridgeDelegate* bridge_delegate,
base::WeakPtr<NotificationPlatformBridgeLacros> owner)
: notification_id_(notification_id),
bridge_delegate_(bridge_delegate),
owner_(owner) {
DCHECK(!notification_id_.empty());
DCHECK(bridge_delegate_);
DCHECK(owner_);
}
RemoteNotificationDelegate(const RemoteNotificationDelegate&) = delete;
RemoteNotificationDelegate& operator=(const RemoteNotificationDelegate&) =
delete;
~RemoteNotificationDelegate() override = default;
mojo::PendingRemote<crosapi::mojom::NotificationDelegate>
BindNotificationDelegate() {
return receiver_.BindNewPipeAndPassRemote();
}
// crosapi::mojom::NotificationDelegate:
void OnNotificationClosed(bool by_user) override {
bridge_delegate_->HandleNotificationClosed(notification_id_, by_user);
if (owner_)
owner_->OnRemoteNotificationClosed(notification_id_);
// NOTE: |this| is deleted.
}
void OnNotificationClicked() override {
bridge_delegate_->HandleNotificationClicked(notification_id_);
}
void OnNotificationButtonClicked(uint32_t button_index) override {
// Chrome OS does not support inline reply.
bridge_delegate_->HandleNotificationButtonClicked(
notification_id_, base::checked_cast<int>(button_index),
/*reply=*/base::nullopt);
}
void OnNotificationSettingsButtonClicked() override {
bridge_delegate_->HandleNotificationSettingsButtonClicked(notification_id_);
}
void OnNotificationDisabled() override {
bridge_delegate_->DisableNotification(notification_id_);
}
private:
const std::string notification_id_;
NotificationPlatformBridgeDelegate* const bridge_delegate_;
base::WeakPtr<NotificationPlatformBridgeLacros> owner_;
mojo::Receiver<crosapi::mojom::NotificationDelegate> receiver_{this};
};
NotificationPlatformBridgeLacros::NotificationPlatformBridgeLacros(
NotificationPlatformBridgeDelegate* delegate)
: bridge_delegate_(delegate) {
DCHECK(bridge_delegate_);
}
NotificationPlatformBridgeLacros::~NotificationPlatformBridgeLacros() = default;
void NotificationPlatformBridgeLacros::Display(
NotificationHandler::Type notification_type,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
// |profile| is ignored because Profile management is handled in
// NotificationPlatformBridgeChromeOs, which includes a profile ID as part of
// the notification ID. Lacros does not support Chrome OS multi-signin, so we
// don't need to handle inactive user notification blockers in ash.
auto note = crosapi::mojom::Notification::New();
note->type = ToMojo(notification.type());
note->id = notification.id();
note->title = notification.title();
note->message = notification.message();
note->display_source = notification.display_source();
note->origin_url = notification.origin_url();
// TODO(https://crbug.com/1113889): Icon.
// TODO(https://crbug.com/1113889): RichNotificationData fields.
// Clean up any old notification with the same ID before creating the new one.
remote_notifications_.erase(notification.id());
auto pending_notification = std::make_unique<RemoteNotificationDelegate>(
notification.id(), bridge_delegate_, weak_factory_.GetWeakPtr());
chromeos::LacrosChromeServiceImpl::Get()
->message_center_remote()
->DisplayNotification(std::move(note),
pending_notification->BindNotificationDelegate());
remote_notifications_[notification.id()] = std::move(pending_notification);
}
void NotificationPlatformBridgeLacros::Close(
Profile* profile,
const std::string& notification_id) {
chromeos::LacrosChromeServiceImpl::Get()
->message_center_remote()
->CloseNotification(notification_id);
// |remote_notifications_| is cleaned up after the remote notification closes
// and notifies us via the delegate.
}
void NotificationPlatformBridgeLacros::GetDisplayed(
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
NOTIMPLEMENTED();
std::move(callback).Run(/*notification_ids=*/{}, /*supports_sync=*/false);
}
void NotificationPlatformBridgeLacros::SetReadyCallback(
NotificationBridgeReadyCallback callback) {
// We don't handle the absence of Ash or a failure to open a Mojo connection,
// so just assume the client is ready.
std::move(callback).Run(true);
}
void NotificationPlatformBridgeLacros::DisplayServiceShutDown(
Profile* profile) {
remote_notifications_.clear();
}
void NotificationPlatformBridgeLacros::OnRemoteNotificationClosed(
const std::string& id) {
remote_notifications_.erase(id);
}
......@@ -2,10 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_CLIENT_LACROS_H_
#define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_CLIENT_LACROS_H_
#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LACROS_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LACROS_H_
#include <map>
#include <memory>
#include <string>
#include "base/memory/weak_ptr.h"
#include "chrome/browser/notifications/notification_platform_bridge.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
class NotificationPlatformBridgeDelegate;
......@@ -13,16 +19,15 @@ class NotificationPlatformBridgeDelegate;
// clicks on notifications received over mojo. Works together with
// NotificationPlatformBridgeChromeOs because that class contains support for
// transient notifications and multiple profiles.
// TODO(jamescook): Derive from crosapi::mojom::MessageCenterClient once that
// mojo interface is introduced.
class MessageCenterClientLacros : public NotificationPlatformBridge {
class NotificationPlatformBridgeLacros : public NotificationPlatformBridge {
public:
explicit MessageCenterClientLacros(
explicit NotificationPlatformBridgeLacros(
NotificationPlatformBridgeDelegate* delegate);
MessageCenterClientLacros(const MessageCenterClientLacros&) = delete;
MessageCenterClientLacros& operator=(const MessageCenterClientLacros&) =
NotificationPlatformBridgeLacros(const NotificationPlatformBridgeLacros&) =
delete;
~MessageCenterClientLacros() override;
NotificationPlatformBridgeLacros& operator=(
const NotificationPlatformBridgeLacros&) = delete;
~NotificationPlatformBridgeLacros() override;
// NotificationPlatformBridge:
void Display(NotificationHandler::Type notification_type,
......@@ -35,11 +40,19 @@ class MessageCenterClientLacros : public NotificationPlatformBridge {
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
void DisplayServiceShutDown(Profile* profile) override;
// TODO(jamescook): Add "client" methods like OnNotificationClicked,
// OnNotificationClosed, etc.
private:
NotificationPlatformBridgeDelegate* delegate_;
class RemoteNotificationDelegate;
// Cleans up after a remote notification is closed.
void OnRemoteNotificationClosed(const std::string& id);
NotificationPlatformBridgeDelegate* const bridge_delegate_;
// Map key is notification ID.
std::map<std::string, std::unique_ptr<RemoteNotificationDelegate>>
remote_notifications_;
base::WeakPtrFactory<NotificationPlatformBridgeLacros> weak_factory_{this};
};
#endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_CLIENT_LACROS_H_
#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LACROS_H_
......@@ -9,6 +9,8 @@ mojom("mojom") {
"attestation.mojom",
"bitmap.mojom",
"crosapi.mojom",
"message_center.mojom",
"notification.mojom",
"screen_manager.mojom",
"select_file.mojom",
]
......
......@@ -5,6 +5,7 @@
module crosapi.mojom;
import "chromeos/crosapi/mojom/attestation.mojom";
import "chromeos/crosapi/mojom/message_center.mojom";
import "chromeos/crosapi/mojom/screen_manager.mojom";
import "chromeos/crosapi/mojom/select_file.mojom";
......@@ -14,6 +15,9 @@ interface AshChromeService {
// Binds the Attestation interface for challenging keys.
BindAttestation@2(pending_receiver<Attestation> receiver);
// Binds the MessageCenter interface for showing notification messages.
BindMessageCenter@3(pending_receiver<MessageCenter> receiver);
// Binds the ScreenManager interface for interacting with windows, screens and
// displays.
BindScreenManager@1(pending_receiver<ScreenManager> receiver);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module crosapi.mojom;
import "chromeos/crosapi/mojom/notification.mojom";
import "mojo/public/mojom/base/string16.mojom";
// Handles notifications created via the Notifications web platform API and the
// chrome.notifications() extension API. Shows the notifications in the
// message center. Implemented in ash-chrome.
interface MessageCenter {
// Displays a notification. If the notification's ID is the same as an
// existing notification, that notification is replaced. The delegate will be
// called with user actions.
DisplayNotification(Notification notification,
pending_remote<NotificationDelegate> delegate);
// Closes a notification by the ID provided in |notification| above.
CloseNotification(string id);
};
// Handles responses to user actions on notifications. Multiple actions may
// occur on a single notification. For example, clicking a notification button
// may not close the notification. Implemented in lacros-chrome.
interface NotificationDelegate {
// Called when a notification previously displayed by the client is closed.
OnNotificationClosed(bool by_user);
// Called when the body of a notification is clicked.
OnNotificationClicked();
// Called when a notification that has buttons (e.g., "Learn more") receives a
// click on one of the buttons.
OnNotificationButtonClicked(uint32 button_index);
// Called when a notification's settings button has been pressed.
OnNotificationSettingsButtonClicked();
// Called when a notification has been disabled (via inline settings).
OnNotificationDisabled();
};
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module crosapi.mojom;
import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "url/mojom/url.mojom";
// Type of notification to show. See the chrome.notifications extension API:
// https://developer.chrome.com/extensions/notifications#type-TemplateType
[Extensible]
enum NotificationType {
// Icon, title and message.
kSimple = 0,
// Icon, title and message with a large image.
kImage = 1,
// List of items. Note: C++ calls this type "multiple".
kList = 2,
// Progress bar.
kProgress = 3,
};
// A notification to show in the system message center. Fields exist to support
// both the web platform notification API and the chrome.notifications extension
// API. See documentation at:
// https://developer.mozilla.org/en-US/docs/Web/API/notification
// https://developer.chrome.com/extensions/notifications#type-NotificationOptions
struct Notification {
// Type of notification to show.
NotificationType type;
// The client decides the format of the ID.
string id;
// The title, usually just a few words.
mojo_base.mojom.String16 title;
// The message body. If long, will wrap inside the notification.
mojo_base.mojom.String16 message;
// Human-readable description of the source of the notification. For example,
// "Google Calendar".
mojo_base.mojom.String16 display_source;
// For web notifications, the URL of the website responsible for showing the
// notification. Otherwise empty.
url.mojom.Url? origin_url;
// TODO(https://crbug.com/1113889): Support additional fields, such as images
// (icon, large image), priority, timestamp, buttons, item lists, etc.
};
......@@ -77,6 +77,12 @@ class LacrosChromeServiceNeverBlockingState
// These methods pass the receiver end of a mojo message pipe to ash-chrome.
// This effectively allows ash-chrome to receive messages sent on these
// message pipes.
void BindMessageCenterReceiver(
mojo::PendingReceiver<crosapi::mojom::MessageCenter> pending_receiver) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ash_chrome_service_->BindMessageCenter(std::move(pending_receiver));
}
void BindSelectFileReceiver(
mojo::PendingReceiver<crosapi::mojom::SelectFile> pending_receiver) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -153,6 +159,15 @@ LacrosChromeServiceImpl::LacrosChromeServiceImpl(
&LacrosChromeServiceNeverBlockingState::BindAshChromeServiceRemote,
weak_sequenced_state_));
// Bind the remote for SelectFile on the current thread, and then pass the
// receiver to the never_blocking_sequence_.
never_blocking_sequence_->PostTask(
FROM_HERE,
base::BindOnce(
&LacrosChromeServiceNeverBlockingState::BindMessageCenterReceiver,
weak_sequenced_state_,
message_center_remote_.BindNewPipeAndPassReceiver()));
// Bind the remote for SelectFile on the current thread, and then pass the
// receiver to the never_blocking_sequence_.
mojo::PendingReceiver<crosapi::mojom::SelectFile>
......
......@@ -14,6 +14,7 @@
#include "base/sequenced_task_runner.h"
#include "chromeos/crosapi/mojom/attestation.mojom.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
......@@ -64,6 +65,12 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
void BindReceiver(
mojo::PendingReceiver<crosapi::mojom::LacrosChromeService> receiver);
// This must be called on the affine sequence.
mojo::Remote<crosapi::mojom::MessageCenter>& message_center_remote() {
DCHECK_CALLED_ON_VALID_SEQUENCE(affine_sequence_checker_);
return message_center_remote_;
}
// This must be called on the affine sequence. It exposes a remote that can
// be used to show a select-file dialog.
mojo::Remote<crosapi::mojom::SelectFile>& select_file_remote() {
......@@ -97,6 +104,7 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
// This member allows lacros-chrome to use the SelectFile interface. This
// member is affine to the affine sequence. It is initialized in the
// constructor and it is immediately available for use.
mojo::Remote<crosapi::mojom::MessageCenter> message_center_remote_;
mojo::Remote<crosapi::mojom::SelectFile> select_file_remote_;
// This member allows lacros-chrome to use the Attestation interface. This
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment