Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / automation_internal / automation_event_router.h
blobff3ac1f332c2acdd7b9c7f5288bcf83b3f71f70e
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_
8 #include <vector>
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"
17 class Profile;
19 namespace content {
20 class BrowserContext;
21 } // namespace content
23 struct ExtensionMsg_AccessibilityEventParams;
25 namespace extensions {
27 struct AutomationListener;
29 class AutomationEventRouter : public content::NotificationObserver {
30 public:
31 static AutomationEventRouter* GetInstance();
33 // Indicates that the listener at |listener_process_id|, |listener_routing_id|
34 // wants to receive automation events from the accessibility tree indicated
35 // by |source_ax_tree_id|. Automation events are forwarded from now on
36 // until the listener process dies.
37 void RegisterListenerForOneTree(const ExtensionId& extension_id,
38 int listener_process_id,
39 int listener_routing_id,
40 int source_ax_tree_id);
42 // Indicates that the listener at |listener_process_id|, |listener_routing_id|
43 // wants to receive automation events from all accessibility trees because
44 // it has Desktop permission.
45 void RegisterListenerWithDesktopPermission(const ExtensionId& extension_id,
46 int listener_process_id,
47 int listener_routing_id);
49 void DispatchAccessibilityEvent(
50 const ExtensionMsg_AccessibilityEventParams& params);
52 // Notify all automation extensions that an accessibility tree was
53 // destroyed. If |browser_context| is null,
54 void DispatchTreeDestroyedEvent(
55 int tree_id,
56 content::BrowserContext* browser_context);
58 private:
59 struct AutomationListener {
60 AutomationListener();
61 ~AutomationListener();
63 ExtensionId extension_id;
64 int routing_id;
65 int process_id;
66 bool desktop;
67 std::set<int> tree_ids;
68 bool is_active_profile;
71 AutomationEventRouter();
72 ~AutomationEventRouter() override;
74 void Register(
75 const ExtensionId& extension_id,
76 int listener_process_id,
77 int listener_routing_id,
78 int source_ax_tree_id,
79 bool desktop);
81 // content::NotificationObserver interface.
82 void Observe(int type,
83 const content::NotificationSource& source,
84 const content::NotificationDetails& details) override;
86 // Called when the user switches profiles or when a listener is added
87 // or removed. The purpose is to ensure that multiple instances of the
88 // same extension running in different profiles don't interfere with one
89 // another, so in that case only the one associated with the active profile
90 // is marked as active.
92 // This is needed on Chrome OS because ChromeVox loads into the login profile
93 // in addition to the active profile. If a similar fix is needed on other
94 // platforms, we'd need an equivalent of SessionStateObserver that works
95 // everywhere.
96 void UpdateActiveProfile();
98 content::NotificationRegistrar registrar_;
99 std::vector<AutomationListener> listeners_;
101 Profile* active_profile_;
103 friend struct base::DefaultSingletonTraits<AutomationEventRouter>;
105 DISALLOW_COPY_AND_ASSIGN(AutomationEventRouter);
108 } // namespace extensions
110 #endif // CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTER_H_