| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ | 5 #ifndef CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ |
| 6 #define CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ | 6 #define CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/accessibility/accessibility_events.h" | 13 #include "chrome/browser/accessibility/accessibility_events.h" |
| 14 #include "chrome/browser/extensions/extension_function.h" | 14 #include "chrome/browser/extensions/extension_function.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "ui/base/accessibility/accessibility_types.h" |
| 16 #include "content/public/browser/notification_registrar.h" | |
| 17 | 16 |
| 18 // Observes the profile and routes accessibility notifications as events | 17 // Observes the profile and routes accessibility notifications as events |
| 19 // to the extension system. | 18 // to the extension system. |
| 20 class ExtensionAccessibilityEventRouter : public content::NotificationObserver { | 19 class ExtensionAccessibilityEventRouter { |
| 21 public: | 20 public: |
| 21 typedef base::Callback<void(ui::AccessibilityTypes::Event, |
| 22 const AccessibilityControlInfo*)> |
| 23 ControlEventCallback; |
| 22 // Single instance of the event router. | 24 // Single instance of the event router. |
| 23 static ExtensionAccessibilityEventRouter* GetInstance(); | 25 static ExtensionAccessibilityEventRouter* GetInstance(); |
| 24 | 26 |
| 25 // Get the dict representing the last control that received an | 27 // Get the dict representing the last control that received an |
| 26 // OnControlFocus event. | 28 // OnControlFocus event. |
| 27 DictionaryValue* last_focused_control_dict() { | 29 DictionaryValue* last_focused_control_dict() { |
| 28 return &last_focused_control_dict_; | 30 return &last_focused_control_dict_; |
| 29 } | 31 } |
| 30 | 32 |
| 31 // Accessibility support is disabled until an extension expicitly enables | 33 // Accessibility support is disabled until an extension expicitly enables |
| 32 // it, so that this extension api has no impact on Chrome's performance | 34 // it, so that this extension api has no impact on Chrome's performance |
| 33 // otherwise. These methods handle enabling, disabling, and querying the | 35 // otherwise. These methods handle enabling, disabling, and querying the |
| 34 // status. | 36 // status. |
| 35 void SetAccessibilityEnabled(bool enabled); | 37 void SetAccessibilityEnabled(bool enabled); |
| 36 bool IsAccessibilityEnabled() const; | 38 bool IsAccessibilityEnabled() const; |
| 37 | 39 |
| 40 // Set and remove callbacks (used for testing, to confirm that events are |
| 41 // getting through). |
| 42 void SetControlEventCallbackForTesting(ControlEventCallback callback); |
| 43 void ClearControlEventCallback(); |
| 44 |
| 45 // Route a window-related accessibility event. |
| 46 void HandleWindowEvent(ui::AccessibilityTypes::Event event, |
| 47 const AccessibilityWindowInfo* info); |
| 48 |
| 49 // Route a menu-related accessibility event. |
| 50 void HandleMenuEvent(ui::AccessibilityTypes::Event event, |
| 51 const AccessibilityMenuInfo* info); |
| 52 |
| 53 // Route a control-related accessibility event. |
| 54 void HandleControlEvent(ui::AccessibilityTypes::Event event, |
| 55 const AccessibilityControlInfo* info); |
| 56 |
| 38 private: | 57 private: |
| 39 friend struct DefaultSingletonTraits<ExtensionAccessibilityEventRouter>; | 58 friend struct DefaultSingletonTraits<ExtensionAccessibilityEventRouter>; |
| 40 | 59 |
| 41 ExtensionAccessibilityEventRouter(); | 60 ExtensionAccessibilityEventRouter(); |
| 42 virtual ~ExtensionAccessibilityEventRouter(); | 61 virtual ~ExtensionAccessibilityEventRouter(); |
| 43 | 62 |
| 44 // content::NotificationObserver::Observe. | |
| 45 virtual void Observe(int type, | |
| 46 const content::NotificationSource& source, | |
| 47 const content::NotificationDetails& details) OVERRIDE; | |
| 48 | |
| 49 void OnWindowOpened(const AccessibilityWindowInfo* details); | 63 void OnWindowOpened(const AccessibilityWindowInfo* details); |
| 50 void OnWindowClosed(const AccessibilityWindowInfo* details); | |
| 51 void OnControlFocused(const AccessibilityControlInfo* details); | 64 void OnControlFocused(const AccessibilityControlInfo* details); |
| 52 void OnControlAction(const AccessibilityControlInfo* details); | 65 void OnControlAction(const AccessibilityControlInfo* details); |
| 53 void OnTextChanged(const AccessibilityControlInfo* details); | 66 void OnTextChanged(const AccessibilityControlInfo* details); |
| 54 void OnMenuOpened(const AccessibilityMenuInfo* details); | 67 void OnMenuOpened(const AccessibilityMenuInfo* details); |
| 55 void OnMenuClosed(const AccessibilityMenuInfo* details); | 68 void OnMenuClosed(const AccessibilityMenuInfo* details); |
| 56 | 69 |
| 57 void DispatchEvent(Profile* profile, | 70 void DispatchEvent(Profile* profile, |
| 58 const char* event_name, | 71 const char* event_name, |
| 59 scoped_ptr<base::ListValue> event_args); | 72 scoped_ptr<base::ListValue> event_args); |
| 60 | 73 |
| 61 // Used for tracking registrations to history service notifications. | |
| 62 content::NotificationRegistrar registrar_; | |
| 63 | |
| 64 DictionaryValue last_focused_control_dict_; | 74 DictionaryValue last_focused_control_dict_; |
| 65 | 75 |
| 66 bool enabled_; | 76 bool enabled_; |
| 67 | 77 |
| 78 // For testing. |
| 79 ControlEventCallback control_event_callback_; |
| 80 |
| 68 DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter); | 81 DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter); |
| 69 }; | 82 }; |
| 70 | 83 |
| 71 // API function that enables or disables accessibility support. Event | 84 // API function that enables or disables accessibility support. Event |
| 72 // listeners are only installed when accessibility support is enabled, to | 85 // listeners are only installed when accessibility support is enabled, to |
| 73 // minimize the impact. | 86 // minimize the impact. |
| 74 class AccessibilitySetAccessibilityEnabledFunction | 87 class AccessibilitySetAccessibilityEnabledFunction |
| 75 : public SyncExtensionFunction { | 88 : public SyncExtensionFunction { |
| 76 virtual ~AccessibilitySetAccessibilityEnabledFunction() {} | 89 virtual ~AccessibilitySetAccessibilityEnabledFunction() {} |
| 77 virtual bool RunImpl() OVERRIDE; | 90 virtual bool RunImpl() OVERRIDE; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 // API function that returns alerts being shown on the give tab. | 115 // API function that returns alerts being shown on the give tab. |
| 103 class AccessibilityGetAlertsForTabFunction : public SyncExtensionFunction { | 116 class AccessibilityGetAlertsForTabFunction : public SyncExtensionFunction { |
| 104 virtual ~AccessibilityGetAlertsForTabFunction() {} | 117 virtual ~AccessibilityGetAlertsForTabFunction() {} |
| 105 virtual bool RunImpl() OVERRIDE; | 118 virtual bool RunImpl() OVERRIDE; |
| 106 DECLARE_EXTENSION_FUNCTION( | 119 DECLARE_EXTENSION_FUNCTION( |
| 107 "experimental.accessibility.getAlertsForTab", | 120 "experimental.accessibility.getAlertsForTab", |
| 108 EXPERIMENTAL_ACCESSIBILITY_GETALERTSFORTAB) | 121 EXPERIMENTAL_ACCESSIBILITY_GETALERTSFORTAB) |
| 109 }; | 122 }; |
| 110 | 123 |
| 111 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ | 124 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ |
| OLD | NEW |