Chromium Code Reviews| 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); | |
|
dmazzoni
2013/08/14 21:00:17
Nit: indentation here too
Cait (Slow)
2013/08/15 20:01:16
Done.
| |
| 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 ControlEventCallback control_event_callback_; | |
|
dmazzoni
2013/08/14 21:00:17
Add a comment "for testing"
Cait (Slow)
2013/08/15 20:01:16
Done.
| |
| 79 | |
| 68 DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter); | 80 DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter); |
| 69 }; | 81 }; |
| 70 | 82 |
| 71 // API function that enables or disables accessibility support. Event | 83 // API function that enables or disables accessibility support. Event |
| 72 // listeners are only installed when accessibility support is enabled, to | 84 // listeners are only installed when accessibility support is enabled, to |
| 73 // minimize the impact. | 85 // minimize the impact. |
| 74 class AccessibilitySetAccessibilityEnabledFunction | 86 class AccessibilitySetAccessibilityEnabledFunction |
| 75 : public SyncExtensionFunction { | 87 : public SyncExtensionFunction { |
| 76 virtual ~AccessibilitySetAccessibilityEnabledFunction() {} | 88 virtual ~AccessibilitySetAccessibilityEnabledFunction() {} |
| 77 virtual bool RunImpl() OVERRIDE; | 89 virtual bool RunImpl() OVERRIDE; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 102 // API function that returns alerts being shown on the give tab. | 114 // API function that returns alerts being shown on the give tab. |
| 103 class AccessibilityGetAlertsForTabFunction : public SyncExtensionFunction { | 115 class AccessibilityGetAlertsForTabFunction : public SyncExtensionFunction { |
| 104 virtual ~AccessibilityGetAlertsForTabFunction() {} | 116 virtual ~AccessibilityGetAlertsForTabFunction() {} |
| 105 virtual bool RunImpl() OVERRIDE; | 117 virtual bool RunImpl() OVERRIDE; |
| 106 DECLARE_EXTENSION_FUNCTION( | 118 DECLARE_EXTENSION_FUNCTION( |
| 107 "experimental.accessibility.getAlertsForTab", | 119 "experimental.accessibility.getAlertsForTab", |
| 108 EXPERIMENTAL_ACCESSIBILITY_GETALERTSFORTAB) | 120 EXPERIMENTAL_ACCESSIBILITY_GETALERTSFORTAB) |
| 109 }; | 121 }; |
| 110 | 122 |
| 111 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ | 123 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_ |
| OLD | NEW |