Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / accessibility / accessibility_extension_api.h
blob11fda2c359ba396dd7733e552dd52f5796178a2a
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_
6 #define CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/memory/singleton.h"
12 #include "base/values.h"
13 #include "chrome/browser/accessibility/accessibility_events.h"
14 #include "chrome/browser/extensions/chrome_extension_function.h"
15 #include "ui/base/accessibility/accessibility_types.h"
17 namespace extensions {
18 class ExtensionHost;
19 } // namespace extensions
21 // Observes the profile and routes accessibility notifications as events
22 // to the extension system.
23 class ExtensionAccessibilityEventRouter {
24 public:
25 typedef base::Callback<void(ui::AccessibilityTypes::Event,
26 const AccessibilityControlInfo*)>
27 ControlEventCallback;
28 // Single instance of the event router.
29 static ExtensionAccessibilityEventRouter* GetInstance();
31 // Get the dict representing the last control that received an
32 // OnControlFocus event.
33 base::DictionaryValue* last_focused_control_dict() {
34 return &last_focused_control_dict_;
37 // Accessibility support is disabled until an extension expicitly enables
38 // it, so that this extension api has no impact on Chrome's performance
39 // otherwise. These methods handle enabling, disabling, and querying the
40 // status.
41 void SetAccessibilityEnabled(bool enabled);
42 bool IsAccessibilityEnabled() const;
44 // Set and remove callbacks (used for testing, to confirm that events are
45 // getting through).
46 void SetControlEventCallbackForTesting(ControlEventCallback callback);
47 void ClearControlEventCallback();
49 // Route a window-related accessibility event.
50 void HandleWindowEvent(ui::AccessibilityTypes::Event event,
51 const AccessibilityWindowInfo* info);
53 // Route a menu-related accessibility event.
54 void HandleMenuEvent(ui::AccessibilityTypes::Event event,
55 const AccessibilityMenuInfo* info);
57 // Route a control-related accessibility event.
58 void HandleControlEvent(ui::AccessibilityTypes::Event event,
59 const AccessibilityControlInfo* info);
61 void OnChromeVoxLoadStateChanged(
62 Profile* profile,
63 bool loading,
64 bool make_announcements);
66 static void DispatchEventToChromeVox(
67 Profile* profile,
68 const char* event_name,
69 scoped_ptr<base::ListValue> event_args);
71 private:
72 friend struct DefaultSingletonTraits<ExtensionAccessibilityEventRouter>;
74 ExtensionAccessibilityEventRouter();
75 virtual ~ExtensionAccessibilityEventRouter();
77 void OnWindowOpened(const AccessibilityWindowInfo* details);
78 void OnControlFocused(const AccessibilityControlInfo* details);
79 void OnControlAction(const AccessibilityControlInfo* details);
80 void OnTextChanged(const AccessibilityControlInfo* details);
81 void OnMenuOpened(const AccessibilityMenuInfo* details);
82 void OnMenuClosed(const AccessibilityMenuInfo* details);
84 void DispatchEvent(Profile* profile,
85 const char* event_name,
86 scoped_ptr<base::ListValue> event_args);
88 base::DictionaryValue last_focused_control_dict_;
90 bool enabled_;
92 // For testing.
93 ControlEventCallback control_event_callback_;
95 DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter);
98 // API function that enables or disables accessibility support. Event
99 // listeners are only installed when accessibility support is enabled, to
100 // minimize the impact.
101 class AccessibilitySetAccessibilityEnabledFunction
102 : public ChromeSyncExtensionFunction {
103 virtual ~AccessibilitySetAccessibilityEnabledFunction() {}
104 virtual bool RunImpl() OVERRIDE;
105 DECLARE_EXTENSION_FUNCTION(
106 "experimental.accessibility.setAccessibilityEnabled",
107 EXPERIMENTAL_ACCESSIBILITY_SETACCESSIBILITYENABLED)
110 // API function that enables or disables web content accessibility support.
111 class AccessibilitySetNativeAccessibilityEnabledFunction
112 : public ChromeSyncExtensionFunction {
113 virtual ~AccessibilitySetNativeAccessibilityEnabledFunction() {}
114 virtual bool RunImpl() OVERRIDE;
115 DECLARE_EXTENSION_FUNCTION(
116 "experimental.accessibility.setNativeAccessibilityEnabled",
117 EXPERIMENTAL_ACCESSIBILITY_SETNATIVEACCESSIBILITYENABLED)
120 // API function that returns the most recent focused control.
121 class AccessibilityGetFocusedControlFunction
122 : public ChromeSyncExtensionFunction {
123 virtual ~AccessibilityGetFocusedControlFunction() {}
124 virtual bool RunImpl() OVERRIDE;
125 DECLARE_EXTENSION_FUNCTION(
126 "experimental.accessibility.getFocusedControl",
127 EXPERIMENTAL_ACCESSIBILITY_GETFOCUSEDCONTROL)
130 // API function that returns alerts being shown on the give tab.
131 class AccessibilityGetAlertsForTabFunction
132 : public ChromeSyncExtensionFunction {
133 virtual ~AccessibilityGetAlertsForTabFunction() {}
134 virtual bool RunImpl() OVERRIDE;
135 DECLARE_EXTENSION_FUNCTION(
136 "experimental.accessibility.getAlertsForTab",
137 EXPERIMENTAL_ACCESSIBILITY_GETALERTSFORTAB)
140 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_