Hook up AutomationEventRouterObserver bindings to Lacros
R=erikchen@chromium.org Bug: 1185764 Test: manual Change-Id: I71b1ee3a75d05ae0db794f2ea989178f11a8e276 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3116406 Reviewed-by: Erik Chen <erikchen@chromium.org> Commit-Queue: David Tseng <dtseng@chromium.org> Cr-Commit-Position: refs/heads/main@{#914985}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
d75f05f708
commit
8554c3a142
chrome/browser
ash
lacros
chromeos/crosapi/mojom
extensions/browser/api/automation_internal
@ -4,8 +4,6 @@
|
||||
|
||||
#include "chrome/browser/ash/crosapi/automation_ash.h"
|
||||
|
||||
#include "extensions/browser/api/automation_internal/automation_event_router.h"
|
||||
|
||||
namespace crosapi {
|
||||
|
||||
AutomationAsh::AutomationAsh() {
|
||||
@ -22,6 +20,11 @@ void AutomationAsh::BindReceiverDeprecated(
|
||||
void AutomationAsh::BindReceiver(
|
||||
mojo::PendingReceiver<mojom::AutomationFactory> pending_receiver) {
|
||||
automation_factory_receivers_.Add(this, std::move(pending_receiver));
|
||||
|
||||
if (!automation_event_router_observer_.IsObserving()) {
|
||||
automation_event_router_observer_.Observe(
|
||||
extensions::AutomationEventRouter::GetInstance());
|
||||
}
|
||||
}
|
||||
|
||||
void AutomationAsh::EnableDesktop() {
|
||||
@ -99,4 +102,14 @@ void AutomationAsh::BindAutomation(
|
||||
automation_receivers_.Add(this, std::move(automation));
|
||||
}
|
||||
|
||||
void AutomationAsh::AllAutomationExtensionsGone() {
|
||||
for (auto& client : automation_client_remotes_)
|
||||
client->NotifyAllAutomationExtensionsGone();
|
||||
}
|
||||
|
||||
void AutomationAsh::ExtensionListenerAdded() {
|
||||
for (auto& client : automation_client_remotes_)
|
||||
client->NotifyExtensionListenerAdded();
|
||||
}
|
||||
|
||||
} // namespace crosapi
|
||||
|
@ -6,8 +6,10 @@
|
||||
#define CHROME_BROWSER_ASH_CROSAPI_AUTOMATION_ASH_H_
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/scoped_observation.h"
|
||||
#include "base/unguessable_token.h"
|
||||
#include "chromeos/crosapi/mojom/automation.mojom.h"
|
||||
#include "extensions/browser/api/automation_internal/automation_event_router.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "mojo/public/cpp/bindings/receiver_set.h"
|
||||
@ -21,7 +23,8 @@ namespace crosapi {
|
||||
// the UI thread.
|
||||
class AutomationAsh : public mojom::Automation,
|
||||
public ui::AXActionHandlerObserver,
|
||||
public mojom::AutomationFactory {
|
||||
public mojom::AutomationFactory,
|
||||
public extensions::AutomationEventRouterObserver {
|
||||
public:
|
||||
AutomationAsh();
|
||||
AutomationAsh(const AutomationAsh&) = delete;
|
||||
@ -67,6 +70,10 @@ class AutomationAsh : public mojom::Automation,
|
||||
mojo::PendingRemote<crosapi::mojom::AutomationClient> automation_client,
|
||||
mojo::PendingReceiver<crosapi::mojom::Automation> automation) override;
|
||||
|
||||
// AutomationEventRouterObserver:
|
||||
void AllAutomationExtensionsGone() override;
|
||||
void ExtensionListenerAdded() override;
|
||||
|
||||
private:
|
||||
bool desktop_enabled_ = false;
|
||||
|
||||
@ -79,6 +86,10 @@ class AutomationAsh : public mojom::Automation,
|
||||
// This set maintains a list of all known automation clients.
|
||||
mojo::RemoteSet<mojom::AutomationClient> automation_client_remotes_;
|
||||
|
||||
base::ScopedObservation<extensions::AutomationEventRouter,
|
||||
extensions::AutomationEventRouterObserver>
|
||||
automation_event_router_observer_{this};
|
||||
|
||||
base::WeakPtrFactory<AutomationAsh> weak_factory_{this};
|
||||
};
|
||||
|
||||
|
@ -116,3 +116,13 @@ void AutomationManagerLacros::PerformAction(
|
||||
extensions::AutomationInternalPerformActionFunction::PerformAction(
|
||||
action_data, /*extension=*/nullptr, /*automation_info=*/nullptr);
|
||||
}
|
||||
|
||||
void AutomationManagerLacros::NotifyAllAutomationExtensionsGone() {
|
||||
extensions::AutomationEventRouter::GetInstance()
|
||||
->NotifyAllAutomationExtensionsGone();
|
||||
}
|
||||
|
||||
void AutomationManagerLacros::NotifyExtensionListenerAdded() {
|
||||
extensions::AutomationEventRouter::GetInstance()
|
||||
->NotifyExtensionListenerAdded();
|
||||
}
|
||||
|
@ -51,6 +51,8 @@ class AutomationManagerLacros
|
||||
int32_t request_id,
|
||||
base::Value optional_args) override;
|
||||
void PerformAction(const ui::AXActionData& action_data) override;
|
||||
void NotifyAllAutomationExtensionsGone() override;
|
||||
void NotifyExtensionListenerAdded() override;
|
||||
|
||||
// Bound on construction given an AutomationFactory remote is available.
|
||||
mojo::Remote<crosapi::mojom::Automation> automation_remote_;
|
||||
|
@ -14,8 +14,8 @@ import "ui/gfx/geometry/mojom/geometry.mojom";
|
||||
|
||||
// Interface for automation clients. Implemented by lacros-chrome. Used by
|
||||
// ash-chrome to enable automation and to perform actions.
|
||||
// Next version: 2
|
||||
// Next method id: 5
|
||||
// Next version: 3
|
||||
// Next method id: 7
|
||||
[Stable, Uuid="8dd5f2a7-c24b-47c3-a096-a5d28c4764bb"]
|
||||
interface AutomationClient {
|
||||
// Deprecated.
|
||||
@ -43,6 +43,12 @@ interface AutomationClient {
|
||||
// resolved by each client based on tree id, action type and other action data
|
||||
// fields.
|
||||
[MinVersion=1] PerformAction@4(ax.mojom.AXActionData action_data);
|
||||
|
||||
// Notifies Lacros when all Ash automation extensions have been unloaded.
|
||||
[MinVersion=2] NotifyAllAutomationExtensionsGone@5();
|
||||
|
||||
// Notifies Lacros when a new automation extension has added a listener.
|
||||
[MinVersion=2] NotifyExtensionListenerAdded@6();
|
||||
};
|
||||
|
||||
// Interface for automation. Implemented by ash-chrome.
|
||||
|
@ -177,6 +177,16 @@ void AutomationEventRouter::DispatchGetTextLocationDataResult(
|
||||
->DispatchEventToExtension(data.source_extension_id, std::move(event));
|
||||
}
|
||||
|
||||
void AutomationEventRouter::NotifyAllAutomationExtensionsGone() {
|
||||
for (AutomationEventRouterObserver& observer : observers_)
|
||||
observer.AllAutomationExtensionsGone();
|
||||
}
|
||||
|
||||
void AutomationEventRouter::NotifyExtensionListenerAdded() {
|
||||
for (AutomationEventRouterObserver& observer : observers_)
|
||||
observer.ExtensionListenerAdded();
|
||||
}
|
||||
|
||||
void AutomationEventRouter::AddObserver(
|
||||
AutomationEventRouterObserver* observer) {
|
||||
observers_.AddObserver(observer);
|
||||
|
@ -63,6 +63,10 @@ class AutomationEventRouter : public content::RenderProcessHostObserver,
|
||||
int listener_process_id,
|
||||
content::WebContents* web_contents);
|
||||
|
||||
// The following two methods should only be called by Lacros.
|
||||
void NotifyAllAutomationExtensionsGone();
|
||||
void NotifyExtensionListenerAdded();
|
||||
|
||||
void AddObserver(AutomationEventRouterObserver* observer);
|
||||
void RemoveObserver(AutomationEventRouterObserver* observer);
|
||||
|
||||
|
Reference in New Issue
Block a user