1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTER_H_
10 #include "base/memory/singleton.h"
11 #include "chrome/common/extensions/api/automation_internal.h"
12 #include "content/public/browser/ax_event_notification_details.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/common/extension.h"
19 } // namespace content
21 struct ExtensionMsg_AccessibilityEventParams
;
23 namespace extensions
{
25 struct AutomationListener
;
27 class AutomationEventRouter
: public content::NotificationObserver
{
29 static AutomationEventRouter
* GetInstance();
31 // Indicates that the listener at |listener_process_id|, |listener_routing_id|
32 // wants to receive automation events from the accessibility tree indicated
33 // by |source_ax_tree_id|. Automation events are forwarded from now on
34 // until the listener process dies.
35 void RegisterListenerForOneTree(int listener_process_id
,
36 int listener_routing_id
,
37 int source_ax_tree_id
);
39 // Indicates that the listener at |listener_process_id|, |listener_routing_id|
40 // wants to receive automation events from all accessibility trees because
41 // it has Desktop permission.
42 void RegisterListenerWithDesktopPermission(int listener_process_id
,
43 int listener_routing_id
);
45 void DispatchAccessibilityEvent(
46 const ExtensionMsg_AccessibilityEventParams
& params
);
48 // Notify all automation extensions that an accessibility tree was
49 // destroyed. If |browser_context| is null,
50 void DispatchTreeDestroyedEvent(
52 content::BrowserContext
* browser_context
);
55 struct AutomationListener
{
57 ~AutomationListener();
62 std::set
<int> tree_ids
;
65 AutomationEventRouter();
66 ~AutomationEventRouter() override
;
69 int listener_process_id
,
70 int listener_routing_id
,
71 int source_ax_tree_id
,
74 // content::NotificationObserver interface.
75 void Observe(int type
,
76 const content::NotificationSource
& source
,
77 const content::NotificationDetails
& details
) override
;
79 content::NotificationRegistrar registrar_
;
80 std::vector
<AutomationListener
> listeners_
;
82 friend struct DefaultSingletonTraits
<AutomationEventRouter
>;
84 DISALLOW_COPY_AND_ASSIGN(AutomationEventRouter
);
87 } // namespace extensions
89 #endif // CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTER_H_