| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTE
R_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTE
R_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTE
R_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTE
R_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "chrome/common/extensions/api/automation_internal.h" | 11 #include "chrome/common/extensions/api/automation_internal.h" |
| 12 #include "content/public/browser/ax_event_notification_details.h" | 12 #include "content/public/browser/ax_event_notification_details.h" |
| 13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 15 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 16 | 16 |
| 17 #if defined(OS_CHROMEOS) |
| 18 #include "ash/session/session_state_observer.h" |
| 19 #endif |
| 20 |
| 21 class Profile; |
| 22 |
| 17 namespace content { | 23 namespace content { |
| 18 class BrowserContext; | 24 class BrowserContext; |
| 19 } // namespace content | 25 } // namespace content |
| 20 | 26 |
| 21 struct ExtensionMsg_AccessibilityEventParams; | 27 struct ExtensionMsg_AccessibilityEventParams; |
| 22 | 28 |
| 23 namespace extensions { | 29 namespace extensions { |
| 24 | 30 |
| 25 struct AutomationListener; | 31 struct AutomationListener; |
| 26 | 32 |
| 27 class AutomationEventRouter : public content::NotificationObserver { | 33 class AutomationEventRouter |
| 34 : public content::NotificationObserver |
| 35 #if defined(OS_CHROMEOS) |
| 36 , public ash::SessionStateObserver |
| 37 #endif |
| 38 { |
| 28 public: | 39 public: |
| 29 static AutomationEventRouter* GetInstance(); | 40 static AutomationEventRouter* GetInstance(); |
| 30 | 41 |
| 31 // Indicates that the listener at |listener_process_id|, |listener_routing_id| | 42 // Indicates that the listener at |listener_process_id|, |listener_routing_id| |
| 32 // wants to receive automation events from the accessibility tree indicated | 43 // wants to receive automation events from the accessibility tree indicated |
| 33 // by |source_ax_tree_id|. Automation events are forwarded from now on | 44 // by |source_ax_tree_id|. Automation events are forwarded from now on |
| 34 // until the listener process dies. | 45 // until the listener process dies. |
| 35 void RegisterListenerForOneTree(int listener_process_id, | 46 void RegisterListenerForOneTree(const ExtensionId& extension_id, |
| 47 int listener_process_id, |
| 36 int listener_routing_id, | 48 int listener_routing_id, |
| 37 int source_ax_tree_id); | 49 int source_ax_tree_id); |
| 38 | 50 |
| 39 // Indicates that the listener at |listener_process_id|, |listener_routing_id| | 51 // Indicates that the listener at |listener_process_id|, |listener_routing_id| |
| 40 // wants to receive automation events from all accessibility trees because | 52 // wants to receive automation events from all accessibility trees because |
| 41 // it has Desktop permission. | 53 // it has Desktop permission. |
| 42 void RegisterListenerWithDesktopPermission(int listener_process_id, | 54 void RegisterListenerWithDesktopPermission(const ExtensionId& extension_id, |
| 55 int listener_process_id, |
| 43 int listener_routing_id); | 56 int listener_routing_id); |
| 44 | 57 |
| 45 void DispatchAccessibilityEvent( | 58 void DispatchAccessibilityEvent( |
| 46 const ExtensionMsg_AccessibilityEventParams& params); | 59 const ExtensionMsg_AccessibilityEventParams& params); |
| 47 | 60 |
| 48 // Notify all automation extensions that an accessibility tree was | 61 // Notify all automation extensions that an accessibility tree was |
| 49 // destroyed. If |browser_context| is null, | 62 // destroyed. If |browser_context| is null, |
| 50 void DispatchTreeDestroyedEvent( | 63 void DispatchTreeDestroyedEvent( |
| 51 int tree_id, | 64 int tree_id, |
| 52 content::BrowserContext* browser_context); | 65 content::BrowserContext* browser_context); |
| 53 | 66 |
| 54 private: | 67 private: |
| 55 struct AutomationListener { | 68 struct AutomationListener { |
| 56 AutomationListener(); | 69 AutomationListener(); |
| 57 ~AutomationListener(); | 70 ~AutomationListener(); |
| 58 | 71 |
| 72 ExtensionId extension_id; |
| 59 int routing_id; | 73 int routing_id; |
| 60 int process_id; | 74 int process_id; |
| 61 bool desktop; | 75 bool desktop; |
| 62 std::set<int> tree_ids; | 76 std::set<int> tree_ids; |
| 77 bool is_active_profile; |
| 63 }; | 78 }; |
| 64 | 79 |
| 65 AutomationEventRouter(); | 80 AutomationEventRouter(); |
| 66 ~AutomationEventRouter() override; | 81 ~AutomationEventRouter() override; |
| 67 | 82 |
| 68 void Register( | 83 void Register( |
| 84 const ExtensionId& extension_id, |
| 69 int listener_process_id, | 85 int listener_process_id, |
| 70 int listener_routing_id, | 86 int listener_routing_id, |
| 71 int source_ax_tree_id, | 87 int source_ax_tree_id, |
| 72 bool desktop); | 88 bool desktop); |
| 73 | 89 |
| 74 // content::NotificationObserver interface. | 90 // content::NotificationObserver interface. |
| 75 void Observe(int type, | 91 void Observe(int type, |
| 76 const content::NotificationSource& source, | 92 const content::NotificationSource& source, |
| 77 const content::NotificationDetails& details) override; | 93 const content::NotificationDetails& details) override; |
| 78 | 94 |
| 95 #if defined(OS_CHROMEOS) |
| 96 // SessionStateObserver overrides: |
| 97 void ActiveUserChanged(const std::string& user_id) override; |
| 98 #endif |
| 99 |
| 100 // Called when the user switches profiles or when a listener is added |
| 101 // or removed. The purpose is to ensure that multiple instances of the |
| 102 // same extension running in different profiles don't interfere with one |
| 103 // another, so in that case only the one associated with the active profile |
| 104 // is marked as active. |
| 105 // |
| 106 // This is needed on Chrome OS because ChromeVox loads into the login profile |
| 107 // in addition to the active profile. If a similar fix is needed on other |
| 108 // platforms, we'd need an equivalent of SessionStateObserver that works |
| 109 // everywhere. |
| 110 void UpdateActiveProfile(); |
| 111 |
| 79 content::NotificationRegistrar registrar_; | 112 content::NotificationRegistrar registrar_; |
| 80 std::vector<AutomationListener> listeners_; | 113 std::vector<AutomationListener> listeners_; |
| 81 | 114 |
| 115 Profile* active_profile_; |
| 116 |
| 117 #if defined(OS_CHROMEOS) |
| 118 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; |
| 119 #endif |
| 120 |
| 82 friend struct DefaultSingletonTraits<AutomationEventRouter>; | 121 friend struct DefaultSingletonTraits<AutomationEventRouter>; |
| 83 | 122 |
| 84 DISALLOW_COPY_AND_ASSIGN(AutomationEventRouter); | 123 DISALLOW_COPY_AND_ASSIGN(AutomationEventRouter); |
| 85 }; | 124 }; |
| 86 | 125 |
| 87 } // namespace extensions | 126 } // namespace extensions |
| 88 | 127 |
| 89 #endif // CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_RO
UTER_H_ | 128 #endif // CHROME_BROWSER_EXTENSIONS_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_RO
UTER_H_ |
| OLD | NEW |