OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACCESSIBILITY_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACCESSIBILITY_API_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/singleton.h" |
| 12 #include "chrome/browser/extensions/extension_function.h" |
| 13 #include "chrome/common/accessibility_events.h" |
| 14 #include "chrome/common/notification_service.h" |
| 15 #include "chrome/common/notification_registrar.h" |
| 16 |
| 17 // Observes the profile and routes accessibility notifications as events |
| 18 // to the extension system. |
| 19 class ExtensionAccessibilityEventRouter : public NotificationObserver { |
| 20 public: |
| 21 // Single instance of the event router. |
| 22 static ExtensionAccessibilityEventRouter* GetInstance(); |
| 23 |
| 24 // Safe to call multiple times. |
| 25 void ObserveProfile(Profile* profile); |
| 26 |
| 27 // Get the dict representing the last control that received an |
| 28 // OnControlFocus event. |
| 29 DictionaryValue* last_focused_control_dict() { |
| 30 return &last_focused_control_dict_; |
| 31 } |
| 32 |
| 33 // Accessibility support is disabled until an extension expicitly enables |
| 34 // it, so that this extension api has no impact on Chrome's performance |
| 35 // otherwise. These methods handle enabling, disabling, querying the |
| 36 // status, and installing callbacks to execute when accessibility support |
| 37 // is enabled or disabled. |
| 38 void SetAccessibilityEnabled(bool enabled); |
| 39 bool IsAccessibilityEnabled() const; |
| 40 typedef Callback0::Type Callback; |
| 41 void AddOnEnabledListener(Callback* callback); |
| 42 void AddOnDisabledListener(Callback* callback); |
| 43 |
| 44 private: |
| 45 friend struct DefaultSingletonTraits<ExtensionAccessibilityEventRouter>; |
| 46 |
| 47 ExtensionAccessibilityEventRouter() |
| 48 : enabled_(false) {} |
| 49 virtual ~ExtensionAccessibilityEventRouter() {} |
| 50 |
| 51 // NotificationObserver::Observe. |
| 52 virtual void Observe(NotificationType type, |
| 53 const NotificationSource& source, |
| 54 const NotificationDetails& details); |
| 55 |
| 56 void OnWindowOpened(const AccessibilityWindowInfo* details); |
| 57 void OnWindowClosed(const AccessibilityWindowInfo* details); |
| 58 void OnControlFocused(const AccessibilityControlInfo* details); |
| 59 void OnControlAction(const AccessibilityControlInfo* details); |
| 60 void OnTextChanged(const AccessibilityControlInfo* details); |
| 61 |
| 62 void DispatchEvent(Profile* profile, |
| 63 const char* event_name, |
| 64 const std::string& json_args); |
| 65 |
| 66 // Used for tracking registrations to history service notifications. |
| 67 NotificationRegistrar registrar_; |
| 68 |
| 69 DictionaryValue last_focused_control_dict_; |
| 70 |
| 71 bool enabled_; |
| 72 std::vector<Callback*> on_enabled_listeners_; |
| 73 std::vector<Callback*> on_disabled_listeners_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter); |
| 76 }; |
| 77 |
| 78 // API function that enables or disables accessibility support. Event |
| 79 // listeners are only installed when accessibility support is enabled, to |
| 80 // minimize the impact. |
| 81 class SetAccessibilityEnabledFunction : public SyncExtensionFunction { |
| 82 virtual ~SetAccessibilityEnabledFunction() {} |
| 83 virtual bool RunImpl(); |
| 84 DECLARE_EXTENSION_FUNCTION_NAME( |
| 85 "experimental.accessibility.setAccessibilityEnabled") |
| 86 }; |
| 87 |
| 88 // API function that returns the most recent focused control. |
| 89 class GetFocusedControlFunction : public SyncExtensionFunction { |
| 90 virtual ~GetFocusedControlFunction() {} |
| 91 virtual bool RunImpl(); |
| 92 DECLARE_EXTENSION_FUNCTION_NAME( |
| 93 "experimental.accessibility.getFocusedControl") |
| 94 }; |
| 95 |
| 96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACCESSIBILITY_API_H_ |
OLD | NEW |